minitest
is a great testing library and factory_girl
is a handy fixture replace library, especially when working with Rails.
It can get tedious to repeat FactoryGirl.
for every invocation of build
, create
, etcetera. Here is a handy shortcut to help reduce your Carpal Tunnel pain:
1 2 3 4 5 6 7 8 9 |
|
Place this in a file such as test/support/factory_girl.rb
.
This allows you to use the core set of syntax methods (build
, build_stubbed
, create
, attributes_for
, and their *_list
counterparts) without having to call them on FactoryGirl
directly:
1 2 3 4 5 6 7 |
|
This guide assumes the following:
Make sure MacPorts is up to date, then install the postgresql92-server
port:
$ sudo port -v selfupdate
$ sudo port -v install postgresql92-server
Once the server has been installed, you will need to create the initial database:
$ sudo mkdir -p /opt/local/var/db/postgresql92/defaultdb
$ sudo chown postgres:postgres /opt/local/var/db/postgresql92/defaultdb
$ sudo su postgres -c '/opt/local/lib/postgresql92/bin/initdb -D /opt/local/var/db/postgresql92/defaultdb'
Once the initial database has been created, you can start the server.
To run the server manually, execute the following command:
$ sudo su postgres -c '/opt/local/lib/postgresql92/bin/postgres -D /opt/local/var/db/postgresql92/defaultdb'
If you want the server to automatically start at boot time, execute the following command:
$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql92-server.plist
The executable files for PostgreSQL are in a non-standard location, so you you’ll want to update your PATH
to make things easier. Most likely, you’ll want to edit your ~/.bashrc
or ~/.zshrc
(or similar) profile, though you can set apply the changes for all users system-wide by editing /etc/profile
.
Make sure you set the new path before /usr/bin
to ensure that you are using the latest versions and not the default apple-supplied tools:
1
|
|
You can verify this works by running which psql
and you should see /opt/local/lib/postgresql92/bin/psql
as the output.
You will be setup with a postgres
user by default, but it is good practice to create a different user account.
To make things easy, create a new database user to match your OS X username:
$ createuser --superuser <my username> -U postgres
You should now be able to create a new database:
$ createdb my_app
Do please consider setting a password for your newly-created user ;)
To setup your Rails application with PostgreSQL, you will need to do the following:
pg
gem to your Gemfile
and run the bundle
command1 2 3 4 5 |
|
database.yml
to use PostgreSQL:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
Even if you have set the min_messages
option, you may still see console output like the following:
WARNING: there is already a transaction in progress
Edit the file /opt/local/var/db/postgresql92/defaultdb/postgresql.conf
and set the following:
client_min_messages = error
Everything should now be running smoothly.
]]>Of course, since it is zero-day, there was an issue fetching the Command Line Tools from the server and I had to install manually from a .pkg
file retrieved from the Apple Developer Portal. If you install the CLI tools package manually, you may need to run the following:
sudo xcodebuild -license
That is required to accept the license terms system-wide.
First, you’ll need to update the base MacPorts installation:
sudo port -v selfupdate
If you run in to a compilation error, you may need to edit the file /opt/local/etc/macports/macports.conf
and set the developer_dir
option to be empty:
sudo vim /opt/local/etc/macports/macports.conf
1 2 3 |
|
You should now be able to update any outdated ports (grab a beverage while you wait):
sudo port -vu upgrade outdated
Now install the apple-gcc42
port to replace the missing GCC 4.2 in Mountain Lion:
sudo port install -vu apple-gcc42
Once that has been installed, you will need to link it to the expected system location:
sudo ln -s /opt/local/bin/gcc-apple-4.2 /usr/bin/gcc-4.2
Make sure you have the latest RVM version installed:
curl -L https://get.rvm.io | bash -s stable
You should now ensure that you can rebuild your installed Ruby versions:
rvm reinstall 1.9.3
rvm reinstall rbx
...
You may need to reference my earlier tip: Fix Ruby 1.9.x OpenSSL Segfault on OS X
]]>The Internet Defense League takes the tactic that killed SOPA & PIPA and turns it into a permanent force for defending the internet, and making it better. Think of it like the internet’s Emergency Broadcast System, or its bat signal!
The Internet Blackout was just the beginning. Together, our websites and personal networks can mobilize the planet to defend the internet from bad laws & monopolies. Are you in?
]]>1 2 3 4 5 6 7 |
|
As written, that could be added to a ~/.bash_profile
or similar location allowing you to run something like:
$ cd myproject
$ git-sync-master mybranch
Taking this one step further, you can “integrate” this command in to git with the following minor modifications:
$ cat > ~/bin/git-sync-master
git checkout master &&
git fetch origin &&
git pull origin master &&
git checkout $1 &&
git rebase master
^D
$ chmod +x ~/bin/git-sync-master
$ cd myproject
$ git sync-master mybranch
]]>$ port installed | grep mongodb
mongodb @2.0.6_0 (active)
$ port installed | grep boost
boost @1.50.0_0 (active)
$ mongo
dyld: Symbol not found: __ZNK5boost15program_options16validation_error4whatEv
Referenced from: /opt/local/bin/mongo
Expected in: /opt/local/lib/libboost_program_options-mt.dylib
in /opt/local/bin/mongo
There are numerous reports on the MacPorts Trac with various ports that are affected. Here is the solution that worked for me:
$ cd /tmp
$ svn co -r 93341 'http://svn.macports.org/repository/macports/trunk/dports/devel/boost/'
A boost/files
A boost/files/patch-boost-foreach.diff
A boost/files/patch-thread_visibility.diff
A boost/files/patch-libs-mpi-build-Jamfile.v2.diff
A boost/files/patch-tools-build-v2-tools-python-2.jam.diff
A boost/files/patch-tools-build-v2-tools-python.jam.diff
A boost/files/patch-bootstrap.sh.diff
A boost/files/patch-tools_build_v2_engine_src_build.jam.diff
A boost/files/patch-libs-python-src-converter-builtin_converters.cpp
A boost/files/patch-tools_build_v2_engine_src_build.sh.diff
A boost/Portfile
Checked out revision 93341.
$ cd boost
$ sudo port install
---> Computing dependencies for boost
---> Fetching archive for boost
---> Attempting to fetch boost-1.49.0_0.darwin_10.x86_64.tbz2 from http://packages.macports.org/boost
---> Attempting to fetch boost-1.49.0_0.darwin_10.x86_64.tbz2.rmd160 from http://packages.macports.org/boost
---> Installing boost @1.49.0_0
---> Deactivating boost @1.50.0_0
---> Cleaning boost
---> Activating boost @1.49.0_0
---> Cleaning boost
$ sudo port activate boost @1.49.0_0
---> Computing dependencies for boost
---> Cleaning boost
]]>mysql
gem version 2.7 in to following environment:
I needed to look up this incantation for the Nth time so I am recording it here:
1
|
|
~/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
The version of OpenSSL that ships with OS X 10.6 and 10.7 is older and causes this issue.
There are a number of options solve this. Here a few:
MacPorts
$ port selfupdate
$ port install openssl
$ port install libyaml
# RVM
$ rvm install 1.9.3 --with-openssl-dir=/opt/local --with-opt-dir=/opt/local
# rbenv
$ CONFIGURE_OPTS='--with-openssl-dir=/opt/local --with-opt-dir=/opt/local' rbenv install 1.9.3-p194
Homebrew
$ brew update
$ brew install openssl
# RVM
$ rvm install 1.9.3 --with-openssl-dir=`brew --prefix openssl`
# rbenv
$ CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl`" rbenv install 1.9.3-p194
RVM
$ rvm pkg install openssl
$ rvm reinstall 1.9.3 --with-openssl-dir=$rvm_path/usr
]]>Some good choices include Thin (evented I/O), Unicorn (multi-process) and Puma (multi-threaded).
The exact configuration settings will vary by application and how much memory each app takes. A default Rails app with a basic scaffold can easily support 4 unicorn workers or 4 puma threads. A small Sinatra app can support several times that number.
Here are the Procfile
settings you can use for each:
1 2 3 4 5 6 7 8 |
|
Use the New Relic RPM Add-on to monitor your application resources.
]]>