Sending household appliances twirling through the 4th dimension since twenty aught five
I recently setup a Jenkins CI server for a client and put their Rails app in it. When someone committed a change, it ran a CI build. However, when someone committed a migration, rake would abort with the dreaded "pending migrations" error. So I just added a db:migrate step to the ci:build task, and all was well…
…or so I thought. In this particular case, the CI server builds anytime someone pushes code to either the "develop" or "master" branch (using git). Pushes to develop happen much more often than master, because master is the "stable production release branch" and develop is the "push everything here when it's ready to be shared with the rest of the team and integrated into the bleeding edge version of the app" branch. One consequence of this is that master builds will often assume an older database schema than develop builds because those migrations haven't been merged with the master branch yet. So running "rake db:migrate" in the ci:build task broke. The migrate task doesn't understand moving the schema backwards and forwards unless you explicitly tell it what to do. However, there's a much better way to do this. The file db/schema.rb is a current snapshot of your database and it should be checked into your code repo. So if you just load that into the test DB before each CI build (via the handy "rake db:schema:load" task), then you're golden. Master has its snapshot, and develop has its snapshot. Everything's fixed! Er... Here's the wrinkle: When you run rake spec after doing that (within the same rake ci:build über-task), it executes the following tasks: ** Invoke spec (first_time)"Be the Change you wish to see in the world" is a common quote attributed to Mahatma Gandhi. But he never said it, and in fact didn't believe the smug, apolitical sentiment it communicates. That and other awesome gems in this NYT article.
My favorite excerpt on the fake Gandhi quote:Here, Gandhi is telling us that personal and social transformation go hand in hand, but there is no suggestion in his words that personal transformation is enough. In fact, for Gandhi, the struggle to bring about a better world involved not only stringent self-denial and rigorous adherence to the philosophy of nonviolence; it also involved a steady awareness that one person, alone, can’t change anything, an awareness that unjust authority can be overturned only by great numbers of people working together with discipline and persistence.
Hmm, great numbers of people working together with discipline and persistence. Why, that almost sounds like organizing!
def do_something(first_arg, second_arg)
puts "First: #{first_arg}"
puts "Second: #{second_arg}"
enddo_something(:second_arg => 'blah', :first_arg => 'yeah') => First: yeah Second: blah
do_something('yeah', 'blah') =>
First: yeah
Second: blahdef do_something(params)
puts "First: #{params[:first_arg]}"
puts "Second: #{params[:second_arg]}"
endfind(:id => id).tap { |foo|
foo.do_things
something_else(foo)
if foo.has_bar?
this_thing(foo)
else
that_other
end
}foo = find(:id => id) foo.do_things something_else(foo) if foo.has_bar? this_thing(foo) else that_other end foo
Then /^it should raise (.+?) when (.+)$/ do |exception,when_step|
lambda {
When when_step
}.should raise_error(eval(exception))
endYou get what you vote for, America.