System notice: In light of the Debian OpenSSL security issue we've regenerated the server keys. See this thread for instructions and the new key fingerprints.

Commit 883d2f28845a65fce7bd05931f988079a09fb4de

minor refactoring

Commit diff

rspec_on_rails/lib/spec/rails/example/rails_example_group.rb

 
2020
2121 include Spec::Rails::Matchers
2222
23 @@model_id = 1000
2423 # Creates a mock object instance for a +model_class+ with common
25 # methods stubbed out.
26 # Additional methods may be easily stubbed (via add_stubs) if +stubs+ is passed.
24 # methods stubbed out. Additional methods may be easily stubbed (via
25 # add_stubs) if +stubs+ is passed.
2726 def mock_model(model_class, options_and_stubs = {})
28 id = @@model_id
29 @@model_id += 1
27 id = next_id
3028 options_and_stubs = {
3129 :id => id,
3230 :to_param => id.to_s,
8282 # model.first_name = "David"
8383 # end
8484 def stub_model(model_class, stubs = {})
85 id = @@model_id
86 @@model_id += 1
87 stubs = {
88 :id => id
89 }.merge(stubs)
85 stubs = {:id => next_id}.merge(stubs)
9086 returning model_class.new do |model|
9187 model.id = stubs.delete(:id)
9288 (class << model; self; end).class_eval do
118118 m
119119 end
120120 Spec::Example::ExampleGroupFactory.default(self)
121
122 private
123 @@model_id = 1000
124 def next_id
125 @@model_id += 1
126 end
121127 end
122128 end
123129 end
toggle raw diff