fixture_replacement 3.0.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.rdoc +5 -0
  3. data/README.rdoc +2 -14
  4. data/VERSION +1 -1
  5. data/lib/fixture_replacement/attribute_builder.rb +5 -3
  6. data/lib/fixture_replacement/class_methods.rb +10 -2
  7. data/lib/fixture_replacement/version.rb +2 -2
  8. data/lib/fixture_replacement.rb +0 -1
  9. metadata +26 -109
  10. data/.gitignore +0 -2
  11. data/Rakefile +0 -8
  12. data/etc/bug_reports/2007_09_28_linoj.txt +0 -51
  13. data/etc/google_analytics +0 -6
  14. data/etc/patches/2007_09_14_default_model_name_with_arguments.diff +0 -26
  15. data/etc/patches/2007_10_14_active_record_specs.diff +0 -396
  16. data/etc/patches/2007_10_14_protected_attributes.diff +0 -26
  17. data/etc/patches/2007_10_14_send_patch.diff +0 -79
  18. data/etc/patches/2007_10_14_spelling_error_in_comments.diff +0 -13
  19. data/etc/patches/2007_10_17_protected_attributes_second_go.diff +0 -212
  20. data/etc/patches/2007_10_18_README.diff +0 -137
  21. data/etc/patches/2007_10_19_readme_tweak.diff +0 -12
  22. data/etc/patches/2007_10_19_silence_migration.diff +0 -12
  23. data/etc/patches/2007_10_25_changed_classify_to_camelize.diff +0 -38
  24. data/etc/patches/2007_11_20_fixture_replacement_generator_should_not_reload_environment_or_boot.patch +0 -13
  25. data/etc/patches/2007_11_20_string_random_refactor_and_extension.patch +0 -104
  26. data/etc/patches/2007_11_20_string_random_refactor_and_extension_v2.patch +0 -108
  27. data/fixture_replacement.gemspec +0 -126
  28. data/rake_tasks/code_quality.rb +0 -37
  29. data/rake_tasks/docs.rb +0 -59
  30. data/rake_tasks/gem.rb +0 -27
  31. data/rake_tasks/specs.rb +0 -7
  32. data/rake_tasks/tests.rb +0 -7
  33. data/rake_tasks/website.rb +0 -11
  34. data/spec/fixture_replacement/attribute_builder_spec.rb +0 -162
  35. data/spec/fixture_replacement/fixture_replacement_spec.rb +0 -96
  36. data/spec/fixture_replacement/fixtures/classes.rb +0 -78
  37. data/spec/fixture_replacement/fr_spec.rb +0 -7
  38. data/spec/fixture_replacement/integration/attr_protected_attributes_spec.rb +0 -71
  39. data/spec/fixture_replacement/integration/attributes_for_with_invalid_keys_spec.rb +0 -14
  40. data/spec/fixture_replacement/integration/attributes_from_spec_without_block.rb +0 -52
  41. data/spec/fixture_replacement/integration/create_method_spec.rb +0 -61
  42. data/spec/fixture_replacement/integration/cyclic_dependency_spec.rb +0 -32
  43. data/spec/fixture_replacement/integration/default_warnings_spec.rb +0 -29
  44. data/spec/fixture_replacement/integration/extend_spec.rb +0 -37
  45. data/spec/fixture_replacement/integration/has_and_belongs_to_many_spec.rb +0 -64
  46. data/spec/fixture_replacement/integration/new_method_spec.rb +0 -96
  47. data/spec/fixture_replacement/integration/private_methods_spec.rb +0 -43
  48. data/spec/fixture_replacement/integration/public_methods_spec.rb +0 -21
  49. data/spec/fixture_replacement/integration/valid_attributes_spec.rb +0 -41
  50. data/spec/fixture_replacement/integration/validation_spec.rb +0 -54
  51. data/spec/fixture_replacement/regressions/2008_01_21_random_string_with_sti_spec.rb +0 -71
  52. data/spec/fixture_replacement/version_spec.rb +0 -7
  53. data/spec/spec.opts +0 -1
  54. data/spec/spec_helper.rb +0 -16
  55. data/spec/spec_helpers.rb +0 -117
  56. data/test/test_helper.rb +0 -21
  57. data/test/unit/user_test.rb +0 -57
@@ -1,396 +0,0 @@
1
- Index: spec/fixture_replacement/fixture_replacement_spec.rb
2
- ===================================================================
3
- --- spec/fixture_replacement/fixture_replacement_spec.rb (revision 31)
4
- +++ spec/fixture_replacement/fixture_replacement_spec.rb (working copy)
5
- @@ -1,53 +1,52 @@
6
- -
7
- require File.dirname(__FILE__) + "/../spec_helper"
8
- +require 'activesupport'
9
- +require 'activerecord'
10
-
11
- -# It would be better if these things were actual mocks/stubs
12
- -# of ActiveRecord Classes.
13
- -class ARBase
14
- - class << self
15
- - def create!(h={})
16
- - obj = new(h)
17
- - obj.save!
18
- - obj
19
- - end
20
- +ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
21
- +class User < ActiveRecord::Base
22
- + belongs_to :gender
23
- + attr_accessor :saved
24
- + def save!
25
- + @saved = true
26
- end
27
- +end
28
- +class Gender < ActiveRecord::Base
29
- + attr_accessor :saved
30
- + def save!
31
- + @saved = true
32
- + end
33
- +end
34
- +class Alien < ActiveRecord::Base
35
- + belongs_to :gender
36
- +end
37
-
38
- - def initialize(hash={})
39
- - @hash = hash
40
- +ActiveRecord::Schema.define do
41
- + create_table :users do |t|
42
- + t.string :key
43
- + t.string :other_key
44
- + t.integer :gender_id
45
- end
46
- -
47
- - attr_reader :hash
48
- -
49
- - def gender # this would be a has_many call in rails
50
- - 17
51
- + create_table :genders do |t|
52
- + t.string :sex
53
- end
54
- -
55
- - def save!
56
- - @saved = true
57
- + create_table :aliens do |t|
58
- + t.integer :gender_id
59
- end
60
- -
61
- - def saved?
62
- - @saved || false
63
- - end
64
- -
65
- end
66
-
67
- -class User < ARBase; end
68
- -class Gender < ARBase; end
69
- -class Alien < ARBase; end
70
- +include FixtureReplacement
71
-
72
- -
73
- module FixtureReplacement
74
- describe Generator, "creation" do
75
- before :each do
76
- @generator = Generator.new("user")
77
- end
78
-
79
- - it "should take a lowecase-model name as it's paramaters" do
80
- + it "should take a lowercase-model name as its paramaters" do
81
- @generator.model_name.should == "user"
82
- end
83
-
84
- - it "should be able to take tell the name of model in string" do
85
- + it "should be able to take tell the name of model in string" do
86
- @generator.model_name.to_s.should == "user"
87
- end
88
-
89
- @@ -84,16 +83,11 @@
90
- FixtureReplacement.module_eval do
91
- def user_attributes
92
- {
93
- - :key => :val
94
- + :key => "val"
95
- }
96
- end
97
- end
98
- @generator = Generator.new("user")
99
- -
100
- - @class = Class.new do
101
- - include FixtureReplacement
102
- - end
103
- - @instance = @class.new
104
- end
105
-
106
- it "should generate the method default_user in the module" do
107
- @@ -103,45 +97,34 @@
108
-
109
- it "should return a ::FixtureReplacement::DelayedEvaluationProc" do
110
- @generator.generate_default_method
111
- - @instance.default_user.class.should == ::FixtureReplacement::DelayedEvaluationProc
112
- + default_user.class.should == ::FixtureReplacement::DelayedEvaluationProc
113
- end
114
-
115
- it %(should return the special proc, which in turn should return an array
116
- of the name of the model ('user') if no params were given) do
117
- @generator.generate_default_method
118
- - @instance.default_user.call.should == ["user"]
119
- + default_user.call.should == ["user"]
120
- end
121
-
122
- it %(should return the special proc, which in turn should return an array
123
- of the name of the model ('user') and the params given) do
124
- @generator.generate_default_method
125
- - @instance.default_user({:some => :hash}).call.should == ["user", {:some => :hash}]
126
- + default_user({:key => "hash"}).call.should == ["user", {:key => "hash"}]
127
- end
128
- end
129
-
130
- describe Generator, "generate_create_method for User when user_attributes is defined (and valid)" do
131
- - before :each do
132
- - User.class_eval do
133
- - def save!
134
- - @saved = true
135
- - end
136
- - end
137
- -
138
- + before :each do
139
- FixtureReplacement.module_eval do
140
- def user_attributes
141
- {
142
- - :key => :val
143
- + :key => "val"
144
- }
145
- end
146
- end
147
- @generator = Generator.new("user")
148
- @generator.generate_new_method
149
- @generator.generate_create_method
150
- -
151
- - @class = Class.new do
152
- - include FixtureReplacement
153
- - end
154
- - @instance = @class.new
155
- end
156
-
157
- it "should generate the method create_user in the module" do
158
- @@ -150,38 +133,32 @@
159
-
160
- it "should generate the method create_user which takes one parameter - a hash" do
161
- @generator.generate_create_method
162
- - @instance.create_user({:key => :value})
163
- + create_user({:key => "value"})
164
- end
165
-
166
- it "should return a user" do
167
- @generator.generate_create_method
168
- - @instance.create_user.should be_a_kind_of(User)
169
- + create_user.should be_a_kind_of(User)
170
- end
171
-
172
- - it "should return a user which has been saved (with create!)" do
173
- + it "should return a user which has been saved (with save!)" do
174
- @generator.generate_create_method
175
- - @instance.create_user.should be_saved
176
- + create_user.saved.should == true
177
- end
178
-
179
- it "should overwrite the hash parameters given" do
180
- @generator.generate_create_method
181
- - @instance.create_user(:key => :value).hash.should == {:key => :value}
182
- + create_user(:key => "value").key.should == "value"
183
- end
184
-
185
- it "should not overwrite the default hash parameters, if none are given" do
186
- @generator.generate_create_method
187
- - @instance.create_user.hash.should == {:key => :val}
188
- + create_user.key.should == "val"
189
- end
190
- end
191
-
192
- describe Generator, "generate_create_method for User when user_attributes is defined (and valid)" do
193
- before :each do
194
- - User.class_eval do
195
- - def save!
196
- - @saved = true
197
- - end
198
- - end
199
- -
200
- FixtureReplacement.module_eval do
201
- def user_attributes
202
- {
203
- @@ -203,60 +180,40 @@
204
- @generator = Generator.new("user")
205
- @generator.generate_new_method
206
- @generator.generate_create_method
207
- -
208
- - @class = Class.new do
209
- - include FixtureReplacement
210
- - end
211
- - @instance = @class.new
212
- end
213
-
214
- it "should save the associated join models which have a default_* method (if it is not overwritten)" do
215
- - created_user = @instance.create_user
216
- - created_gender = created_user.hash[:gender]
217
- - created_gender.hash.should == {:sex => "Male"}
218
- + created_gender = create_user.gender
219
- + created_gender.sex.should == "Male"
220
- end
221
-
222
- it "should not save the associated join model, but not as the default_* method (in the case that it is overwritten)" do
223
- - created_user = @instance.create_user(:gender => Gender.create!(:sex => "Female"))
224
- - created_gender = created_user.hash[:gender]
225
- - created_gender.hash.should == {:sex => "Female"}
226
- + created_user = create_user(:gender => Gender.create!(:sex => "Female"))
227
- + created_gender = created_user.gender
228
- + created_gender.sex.should == "Female"
229
- end
230
-
231
- - it "should call Gender.create! when the default_gender method is evaluated by default_gender" do
232
- - gender = Gender.new
233
- - Gender.should_receive(:create!).and_return gender
234
- - @instance.create_user
235
- + it "should call Gender.save! when the default_gender method is evaluated by default_gender" do
236
- + create_user.gender.saved.should == true
237
- end
238
-
239
- - it "should not call Gender.create! if the default_gender is overwritten by another value (say, a string)" do
240
- - Gender.should_not_receive(:create!)
241
- - @instance.create_user(:gender => "a string")
242
- + it "should not call Gender.save! if the default_gender is overwritten by another value" do
243
- + create_user(:gender => Gender.new).gender.saved.should_not == true
244
- end
245
- end
246
-
247
- describe Generator, "generate_create_method for User when user_attributes is defined, but not valid" do
248
- - before :each do
249
- - User.class_eval do
250
- - def save!
251
- - @saved = true
252
- - end
253
- - end
254
- -
255
- + before :each do
256
- FixtureReplacement.module_eval do
257
- def user_attributes
258
- {
259
- - :key => :val
260
- + :key => "val"
261
- }
262
- end
263
- end
264
- @generator = Generator.new("user")
265
- @generator.generate_new_method
266
- @generator.generate_create_method
267
- -
268
- - @class = Class.new do
269
- - include FixtureReplacement
270
- - end
271
- - @instance = @class.new
272
- end
273
-
274
- it "should generate the method create_user in the module" do
275
- @@ -265,22 +222,9 @@
276
-
277
- it "should generate the method create_user which takes one parameter - a hash" do
278
- @generator.generate_create_method
279
- - @instance.create_user({:key => :value})
280
- + create_user({:key => "value"})
281
- end
282
-
283
- - it "should raise an error with a user which has been saved (with create!)" do
284
- - User.class_eval do
285
- - def save!
286
- - raise
287
- - end
288
- - end
289
- -
290
- - @generator.generate_create_method
291
- - lambda {
292
- - @instance.create_user
293
- - }.should raise_error
294
- - end
295
- -
296
- end
297
-
298
- describe Generator, "generate_new_method for User when user_attributes is defined" do
299
- @@ -290,7 +234,7 @@
300
- FixtureReplacement.module_eval do
301
- def user_attributes
302
- {
303
- - :key => :val
304
- + :key => "val"
305
- }
306
- end
307
-
308
- @@ -302,12 +246,6 @@
309
- end
310
- @generator = Generator.new("user")
311
- @generator.generate_new_method
312
- -
313
- - @class = Class.new do
314
- - include FixtureReplacement
315
- - end
316
- - @instance = @class.new
317
- -
318
- end
319
-
320
- it "should respond to new_user in the module" do
321
- @@ -316,19 +254,21 @@
322
-
323
- it "should return a new User object" do
324
- User.stub!(:new).and_return @user
325
- - @instance.new_user.should == @user
326
- + new_user.should == @user
327
- end
328
-
329
- it "should return a new User object with the keys given in user_attributes" do
330
- - @instance.new_user.hash.should == {:key => :val}
331
- + new_user.key.should == "val"
332
- end
333
-
334
- it "should over-write the User's hash with any hash given to new_user" do
335
- - @instance.new_user(:key => :other_value).hash.should == {:key => :other_value}
336
- + new_user(:key => "other_value").key.should == "other_value"
337
- end
338
-
339
- it "should add any hash key-value pairs which weren't previously given in user_attributes" do
340
- - @instance.new_user(:other_key => :other_value).hash.should == {:key => :val, :other_key => :other_value}
341
- + u = new_user(:other_key => "other_value")
342
- + u.key.should == "val"
343
- + u.other_key.should == "other_value"
344
- end
345
- end
346
-
347
- @@ -365,39 +305,30 @@
348
-
349
- @generator = Generator.new("alien")
350
- @generator.generate_new_method
351
- -
352
- - @class = Class.new do
353
- - include FixtureReplacement
354
- - end
355
- - @instance = @class.new
356
- end
357
-
358
- it "should evaluate any of the default_* methods before returning (if no over-writing key is given)" do
359
- - new_user = @instance.new_user
360
- - new_gender = new_user.hash[:gender]
361
- - new_gender.hash.should == {:sex => "Male"}
362
- + new_gender = new_user.gender
363
- + new_gender.sex.should == "Male"
364
- end
365
-
366
- it %(should evaluate any of the default_* methods before returning, with the hash params given to default_* method) do
367
- - new_alien = @instance.new_alien
368
- - new_gender = new_alien.hash[:gender]
369
- - new_gender.hash.should == {:sex => "unknown"}
370
- + new_gender = new_alien.gender
371
- + new_gender.sex.should == "unknown"
372
- end
373
-
374
- it "should call Gender.save! when the default_gender method is evaluated by default_gender" do
375
- - Gender.should_receive(:create!)
376
- - @instance.new_user
377
- + new_user.gender.saved.should == true
378
- end
379
-
380
- - it "should not call Gender.new if the default_gender is overwritten by another value (say, a string)" do
381
- - Gender.should_not_receive(:create!)
382
- - @instance.new_user(:gender => "a string")
383
- + it "should not call Gender.new if the default_gender is overwritten by another value" do
384
- + new_user(:gender => Gender.new).gender.saved.should_not == true
385
- end
386
-
387
- it "should be able to overwrite a default_* method" do
388
- - new_user = @instance.new_user(:gender => Gender.create!(:sex => "Female"))
389
- - created_gender = new_user.hash[:gender]
390
- - created_gender.hash.should == {:sex => "Female"}
391
- + new_user = new_user(:gender => Gender.create!(:sex => "Female"))
392
- + created_gender = new_user.gender
393
- + created_gender.sex.should == "Female"
394
- end
395
- end
396
-
@@ -1,26 +0,0 @@
1
- Index: lib/fixture_replacement/fixture_replacement.rb
2
- ===================================================================
3
- --- lib/fixture_replacement/fixture_replacement.rb (revision 31)
4
- +++ lib/fixture_replacement/fixture_replacement.rb (working copy)
5
- @@ -70,7 +70,9 @@
6
- hash_given = args[0] || Hash.new
7
- merged_hash = self.send(attributes_method).merge(hash_given)
8
- evaluated_hash = Generator.merge_unevaluated_method(self, :create, merged_hash)
9
- - obj = class_name.create!(evaluated_hash)
10
- + obj = class_name.new
11
- + evaluated_hash.each { |k, v| obj.update_attribute(k, v) }
12
- + obj.save!
13
- obj
14
- end
15
- end
16
- @@ -86,7 +88,9 @@
17
- hash_given = args[0] || Hash.new
18
- merged_hash = self.send(attributes_method).merge(hash_given)
19
- evaluated_hash = Generator.merge_unevaluated_method(self, :create, merged_hash)
20
- - class_name.new(evaluated_hash)
21
- + obj = class_name.new
22
- + evaluated_hash.each { |k, v| obj.update_attribute(k, v) }
23
- + obj
24
- end
25
- end
26
- end
@@ -1,79 +0,0 @@
1
- Index: lib/fixture_replacement/fixture_replacement.rb
2
- ===================================================================
3
- --- lib/fixture_replacement/fixture_replacement.rb (revision 31)
4
- +++ lib/fixture_replacement/fixture_replacement.rb (working copy)
5
- @@ -70,7 +70,9 @@
6
- hash_given = args[0] || Hash.new
7
- merged_hash = self.send(attributes_method).merge(hash_given)
8
- evaluated_hash = Generator.merge_unevaluated_method(self, :create, merged_hash)
9
- - obj = class_name.create!(evaluated_hash)
10
- + obj = class_name.new
11
- + evaluated_hash.each { |k, v| obj.send("#{k}=", v) }
12
- + obj.save!
13
- obj
14
- end
15
- end
16
- @@ -86,7 +88,9 @@
17
- hash_given = args[0] || Hash.new
18
- merged_hash = self.send(attributes_method).merge(hash_given)
19
- evaluated_hash = Generator.merge_unevaluated_method(self, :create, merged_hash)
20
- - class_name.new(evaluated_hash)
21
- + obj = class_name.new
22
- + evaluated_hash.each { |k, v| obj.send("#{k}=", v) }
23
- + obj
24
- end
25
- end
26
- end
27
- Index: spec/fixture_replacement/fixture_replacement_spec.rb
28
- ===================================================================
29
- --- spec/fixture_replacement/fixture_replacement_spec.rb (revision 31)
30
- +++ spec/fixture_replacement/fixture_replacement_spec.rb (working copy)
31
- @@ -18,6 +18,14 @@
32
-
33
- attr_reader :hash
34
-
35
- + def method_missing symbol, *args
36
- + if symbol.id2name =~ /\A(.+)=\z/
37
- + @hash[$~[1].to_sym] = *args
38
- + else
39
- + super
40
- + end
41
- + end
42
- +
43
- def gender # this would be a has_many call in rails
44
- 17
45
- end
46
- @@ -222,14 +230,14 @@
47
- created_gender.hash.should == {:sex => "Female"}
48
- end
49
-
50
- - it "should call Gender.create! when the default_gender method is evaluated by default_gender" do
51
- + it "should call Gender.save! when the default_gender method is evaluated by default_gender" do
52
- gender = Gender.new
53
- - Gender.should_receive(:create!).and_return gender
54
- + Gender.should_receive(:save!).and_return gender
55
- @instance.create_user
56
- end
57
-
58
- - it "should not call Gender.create! if the default_gender is overwritten by another value (say, a string)" do
59
- - Gender.should_not_receive(:create!)
60
- + it "should not call Gender.save! if the default_gender is overwritten by another value (say, a string)" do
61
- + Gender.should_not_receive(:save!)
62
- @instance.create_user(:gender => "a string")
63
- end
64
- end
65
- @@ -385,12 +393,12 @@
66
- end
67
-
68
- it "should call Gender.save! when the default_gender method is evaluated by default_gender" do
69
- - Gender.should_receive(:create!)
70
- + Gender.should_receive(:save!)
71
- @instance.new_user
72
- end
73
-
74
- it "should not call Gender.new if the default_gender is overwritten by another value (say, a string)" do
75
- - Gender.should_not_receive(:create!)
76
- + Gender.should_not_receive(:save!)
77
- @instance.new_user(:gender => "a string")
78
- end
79
-
@@ -1,13 +0,0 @@
1
- Index: lib/fixture_replacement/fixture_replacement.rb
2
- ===================================================================
3
- --- lib/fixture_replacement/fixture_replacement.rb (revision 31)
4
- +++ lib/fixture_replacement/fixture_replacement.rb (working copy)
5
- @@ -22,7 +22,7 @@
6
- end
7
-
8
- # This uses a DelayedEvaluationProc, not a typical proc, for type checking.
9
- - # It maybe absurd to try to store a proc in a database, but even if someone tries,
10
- + # It may be absurd to try to store a proc in a database, but even if someone tries,
11
- # they won't get an error from FixtureReplacement, since the error would be incredibly unclear
12
- def merge_unevaluated_method(obj, method_for_instantiation, hash={})
13
- hash.each do |key, value|