-
-
Save dchelimsky/2438 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Migration | |
| class << self | |
| attr_accessor :model | |
| def set_model(model) | |
| @model = eval(model) | |
| end | |
| end | |
| def run | |
| self.class.model.count | |
| records = self.class.model.find | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper.rb' | |
| describe "Migration" do | |
| before(:all) do | |
| MyModel = Object.new | |
| require 'my_migration' | |
| end | |
| before(:each) do | |
| @record = mock('record', :name => 'Pete') | |
| MyModel.stub!(:find).and_return([@record]) | |
| MyModel.stub!(:count) | |
| end | |
| it "should get a count of the records" do | |
| MyModel.should_receive(:count) | |
| MyMigration.new.run | |
| end | |
| it "should find the records" do | |
| MyModel.should_receive(:find) | |
| MyMigration.new.run | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'migration' | |
| class MyMigration < Migration | |
| set_model 'MyModel' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| begin | |
| require 'spec' | |
| rescue LoadError | |
| require 'rubygems' | |
| gem 'rspec' | |
| require 'spec' | |
| end | |
| # Spec::Runner.configure do |config| | |
| # config.mock_with :flexmock | |
| # end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment