gist: 2438 Download_button fork
public
Public Clone URL: git://gist.github.com/2438.git
migration.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
migration_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
my_migration.rb
1
2
3
4
5
6
7
require 'migration'
 
class MyMigration < Migration
  
  set_model 'MyModel'
  
end
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
begin
  require 'spec'
rescue LoadError
  require 'rubygems'
  gem 'rspec'
  require 'spec'
end
 
# Spec::Runner.configure do |config|
# config.mock_with :flexmock
# end

Owner

dchelimsky

Fork Of

Revisions