Take the 2008 Git User's Survey and help out! [ hide ]

public
Description: Replacement for ActiveRecord fixtures using an extremely flexible ruby-based approach.
Clone URL: git://github.com/technoweenie/model_stubbing.git
Search Repo:
update specs for :validate, so its checked from the model, not the 
definition.  make :validate => false by default
technoweenie (author)
Sun Jul 06 11:57:07 -0700 2008
commit  847b4ec59346d54c1e8a172da0e36c2ddac9f694
tree    0fa54f4fffcb72de1f8fbc56ceb2d2bdba70b52e
parent  08cbfe4f1fe0e2d868aaa3e38d0ad81da3e02f4a
...
38
39
40
 
41
42
43
...
38
39
40
41
42
43
44
0
@@ -38,6 +38,7 @@ module ModelStubbing
0
     base_name = options[:copy] || :default
0
     base = name == base_name ? nil : ModelStubbing.definitions[base_name]
0
     defn = ModelStubbing.definitions[name] ||= (base && options[:copy] != false) ? base.dup : ModelStubbing::Definition.new
0
+ options = base.options.merge(options) if base
0
     defn.setup_on self, options, &block
0
   end
0
 
...
73
74
75
76
77
 
 
78
79
80
81
82
...
73
74
75
 
 
76
77
78
 
79
80
81
0
@@ -73,10 +73,9 @@ module ModelStubbing
0
     # Shortcut methods for each model are generated as well. users(:default) accesses
0
     # the default user stub, and users(:admin) accesses the 'admin' user stub.
0
     def setup_on(base, options = {}, &block)
0
- options = {:validate => true, :insert => true}.update(options)
0
- self.insert = false if options[:insert] == false
0
+ @options = {:validate => false, :insert => true}.update(options)
0
+ self.insert = false if @options[:insert] == false
0
       self.instance_eval(&block) if block
0
- @options = options
0
       if base.ancestors.any? { |a| a.to_s == "Test::Unit::TestCase" || a.to_s == "Spec::Example::ExampleGroup" }
0
         unless base.ancestors.include?(ModelStubbing::Extension)
0
           base.send :include, ModelStubbing::Extension
...
22
23
24
25
 
26
27
28
...
97
98
99
100
 
101
102
103
...
22
23
24
 
25
26
27
28
...
97
98
99
 
100
101
102
103
0
@@ -22,7 +22,7 @@ module ModelStubbing
0
       @name = options.delete(:name) || default_name.to_sym
0
       @plural = options.delete(:plural) || name
0
       @singular = options.delete(:singular) || name.to_s.singularize
0
- @options = {}
0
+ @options = options
0
       @stubs = {}
0
       unless @model_class.respond_to?(:mock_id)
0
         class << @model_class
0
@@ -97,7 +97,7 @@ module ModelStubbing
0
     
0
     def purge
0
       if connection
0
- connection.delete "DELETE FROM #{connection.quote_table_name(@model_class.table_name)}", 'Model Stubs Delete'
0
+ connection.delete "DELETE FROM #{connection.quote_table_name(@model_class.table_name)}"
0
       end
0
     end
0
     
...
49
50
51
 
52
53
54
55
56
...
119
120
121
122
123
124
125
...
49
50
51
52
53
 
54
55
56
...
119
120
121
 
122
123
124
0
@@ -49,8 +49,8 @@ module ModelStubbing
0
     def insert(attributes = {})
0
       @inserting = true
0
       object = record(attributes)
0
+ object.new_record = true
0
       if model.options[:callbacks]
0
- object.new_record = true # record could have returned one from the cache
0
         object.save!
0
       elsif !model.options[:validate] || object.valid?
0
         connection.insert_fixture(object.stubbed_attributes, model.model_class.table_name)
0
@@ -119,7 +119,6 @@ module ModelStubbing
0
         record.new_record = false
0
         record.id = ModelStubbing.record_ids[this_record_key] ||= attributes[:id] || @model.model_class.base_class.mock_id
0
       end
0
- record.new_record = true if @inserting
0
       record.stubbed_attributes = stubbed_attributes.merge(:id => record.id)
0
       stubbed_attributes.each do |key, value|
0
         meta.send :attr_accessor, key unless record.respond_to?("#{key}=")
...
158
159
160
161
 
162
163
164
165
166
167
 
168
169
170
...
173
174
175
176
 
177
178
179
180
181
182
183
 
184
185
186
187
188
189
190
 
191
192
193
194
195
196
197
 
198
199
200
201
202
203
204
 
205
206
207
...
158
159
160
 
161
162
163
164
165
166
 
167
168
169
170
...
173
174
175
 
176
177
178
179
180
181
182
 
183
184
185
186
187
188
189
 
190
191
192
193
194
195
196
 
197
198
199
200
201
202
203
 
204
205
206
207
0
@@ -158,13 +158,13 @@ module ModelStubbing
0
       @defn = ModelStubbing.definitions[:default]
0
       @model = @defn.models[:model_stubbing_users]
0
       @stub = @model.default
0
- @opts = @defn.options.dup
0
+ @opts = @model.options.dup
0
     end
0
   
0
     before do
0
       ModelStubbing.records.clear
0
       ModelStubbing.record_ids.clear
0
- @defn.options.update(@opts)
0
+ @model.options.update(@opts)
0
       @conn = mock("Connection")
0
       @record = @stub.record
0
       @stub.stub!(:record).and_return(@record)
0
@@ -173,35 +173,35 @@ module ModelStubbing
0
     end
0
 
0
     it "inserts an invalid record without validating" do
0
- @defn.options.update(:validate => false, :callbacks => false)
0
+ @model.options.update(:validate => false, :callbacks => false)
0
       @record.valid = false
0
       @conn.should_receive(:insert_fixture)
0
       @inserting_record.call
0
     end
0
 
0
     it "raises error an invalid record with validation" do
0
- @defn.options.update(:validate => true, :callbacks => false)
0
+ @model.options.update(:validate => true, :callbacks => false)
0
       @record.valid = false
0
       @conn.should_not_receive(:insert_fixture)
0
       @inserting_record.should raise_error
0
     end
0
 
0
     it "inserts valid record with validation" do
0
- @defn.options.update(:validate => true, :callbacks => false)
0
+ @model.options.update(:validate => true, :callbacks => false)
0
       @record.valid = true
0
       @conn.should_receive(:insert_fixture)
0
       @inserting_record.call
0
     end
0
 
0
     it "raises error an invalid record with validation and callbacks" do
0
- @defn.options.update(:validate => true, :callbacks => true)
0
+ @model.options.update(:validate => true, :callbacks => true)
0
       @record.valid = false
0
       @conn.should_not_receive(:insert_fixture)
0
       @inserting_record.should raise_error
0
     end
0
 
0
     it "inserts valid record with validation and callbacks" do
0
- @defn.options.update(:validate => true, :callbacks => true)
0
+ @model.options.update(:validate => true, :callbacks => true)
0
       @record.valid = true
0
       @conn.should_not_receive(:insert_fixture)
0
       @inserting_record.call

Comments

    No one has commented yet.