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,71 +0,0 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
2
-
3
- module FixtureReplacement
4
- describe "create_user with attr_protected attributes" do
5
- before :each do
6
- @obj = use_module do
7
- attributes_for :admin do |u|
8
- u.admin_status = true
9
- u.name = "Scott"
10
- end
11
- end
12
- end
13
-
14
- it "should not complain when an apparent mass assignment has happened with default values" do
15
- lambda {
16
- @obj.create_admin
17
- }.should_not raise_error
18
- end
19
-
20
- it "should not be a new record" do
21
- @obj.create_admin.should_not be_a_new_record
22
- end
23
-
24
- it "should have admin_status equal to the default value (when it has not been overwritten)" do
25
- @obj.create_admin.admin_status.should == true
26
- end
27
-
28
- it "should have admin_status equal to the overwritten value" do
29
- @obj.create_admin(:admin_status => false).admin_status.should be_false
30
- end
31
-
32
- it "should have the other attributes assigned when the attr_value has been overwritten" do
33
- @obj.create_admin(:admin_status => false).name.should == "Scott"
34
- end
35
-
36
- it "should have the other attributes assigned even when the attr_value has not been overwritten" do
37
- @obj.create_admin.name.should == "Scott"
38
- end
39
- end
40
-
41
- describe "new_user with attr_protected attributes" do
42
- before :each do
43
- @obj = use_module do |s|
44
- attributes_for :admin do |s|
45
- s.admin_status = true
46
- s.name = "Scott"
47
- end
48
- end
49
- end
50
-
51
- it "should return a new Admin with new_admin" do
52
- @obj.new_admin.should be_a_kind_of(Admin)
53
- end
54
-
55
- it "should have admin_status equal to the default value (when it has not been overwritten)" do
56
- @obj.new_admin.admin_status.should == true
57
- end
58
-
59
- it "should have admin_status equal to the overwritten value" do
60
- @obj.new_admin(:admin_status => false).admin_status.should be_false
61
- end
62
-
63
- it "should have the other attributes assigned when the attr_value has been overwritten" do
64
- @obj.new_admin(:admin_status => false).name.should == "Scott"
65
- end
66
-
67
- it "should have the other attributes assigned even when the attr_value has not been overwritten" do
68
- @obj.new_admin.name.should == "Scott"
69
- end
70
- end
71
- end
@@ -1,14 +0,0 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
2
-
3
- module FixtureReplacement
4
- describe "keys passed to attributes for" do
5
- it "should raise an invalid key error when an invalid key is passed" do
6
- lambda {
7
- use_module do
8
- attributes_for :user, :class_name => "foo"
9
- end
10
- }.should raise_error(FixtureReplacement::AttributeBuilder::InvalidKeyError,
11
- ":class_name is not a valid option to attributes_for. Valid keys are: [:from, :class]")
12
- end
13
- end
14
- end
@@ -1,52 +0,0 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
2
-
3
- module FixtureReplacement
4
- describe AttributeBuilder do
5
- include FixtureReplacementControllerHelper
6
-
7
- before :each do
8
- @obj = use_module do
9
- attributes_for :user do |u|
10
- u.username = random_string
11
- u.key = random_string
12
- end
13
-
14
- attributes_for :scott, :from => :user
15
-
16
- attributes_for :foo, :class => User
17
-
18
- attributes_for :admin do |a|
19
- a.admin_status = true
20
- end
21
- end
22
- end
23
-
24
- models = "user", "foo", "scott"
25
-
26
- models.each do |model|
27
- it "should have the new_#{model} method as a (module) method on the module" do
28
- @obj.should respond_to("new_#{model}")
29
- end
30
-
31
- it "should have the new_#{model} method as a private method in the test case" do
32
- @obj.private_methods.should include("new_#{model}")
33
- end
34
-
35
- it "should have the create_#{model} method as a private method in the test case" do
36
- @obj.private_methods.should include("create_#{model}")
37
- end
38
-
39
- it "should have the create_#{model} method as a (module) method on the module" do
40
- @obj.should respond_to("create_#{model}")
41
- end
42
- end
43
-
44
- it "should have the username as a string (for User) for new_user" do
45
- @obj.new_user.username.class.should == String
46
- end
47
-
48
- it "should have the username as a string (for User) for create_user" do
49
- @obj.create_user.username.class.should == String
50
- end
51
- end
52
- end
@@ -1,61 +0,0 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
2
-
3
- module FixtureReplacement
4
- describe "the create_* method" do
5
- it "should be a user for attributes_for :user" do
6
- obj = use_module do
7
- attributes_for :user
8
- end
9
-
10
- obj.create_user.should be_a_kind_of(User)
11
- end
12
-
13
- it "should use the given class" do
14
- obj = use_module do
15
- attributes_for :foo, :class => User
16
- end
17
-
18
- obj.create_foo.should be_a_kind_of(User)
19
- end
20
-
21
- it "should find the correct class name" do
22
- obj = use_module do
23
- attributes_for :admin
24
- end
25
-
26
- obj.create_admin.should be_a_kind_of(Admin)
27
- end
28
-
29
- it "should over-write the User's hash with any hash given to create_user" do
30
- obj = use_module do
31
- attributes_for :user do |u|
32
- u.key = "val"
33
- end
34
- end
35
-
36
- obj.create_user(:key => "other_value").key.should == "other_value"
37
- end
38
-
39
- it "should add any hash key-value pairs which weren't previously given in user_attributes" do
40
- obj = use_module do
41
- attributes_for :user do |u|
42
- u.key = "val"
43
- end
44
- end
45
-
46
- user = obj.create_user(:other_key => "other_value")
47
- user.key.should == "val"
48
- user.other_key.should == "other_value"
49
- end
50
-
51
- it "should not be saved to the database" do
52
- obj = use_module do
53
- attributes_for :user do |u|
54
- u.key = "val"
55
- end
56
- end
57
-
58
- obj.create_user.should_not be_a_new_record
59
- end
60
- end
61
- end
@@ -1,32 +0,0 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
2
-
3
- describe "cyclic dependencies" do
4
- before do
5
- @mod = use_module do
6
- attributes_for :event do |e, hash|
7
- e.schedule = new_schedule(:event => e) unless hash[:schedule]
8
- end
9
-
10
- attributes_for :schedule do |s, hash|
11
- s.event = new_event(:schedule => s) unless hash[:event]
12
- end
13
- end
14
- end
15
-
16
- it "should allow them" do
17
- @mod.new_event.should be_a_kind_of(Event)
18
- end
19
-
20
- it "should associate an event with a schedule" do
21
- @mod.new_event.schedule.should be_a_kind_of(Schedule)
22
- end
23
-
24
- it "should associate a schedule with an event" do
25
- @mod.new_schedule.event.should be_a_kind_of(Event)
26
- end
27
-
28
- it "should back associate" do
29
- schedule = @mod.new_schedule
30
- schedule.event.schedule.should == schedule
31
- end
32
- end
@@ -1,29 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
-
3
- describe "default_* warnings" do
4
- before do
5
- @mod = use_module do
6
- attributes_for :post
7
-
8
- attributes_for :comment
9
- end
10
- end
11
-
12
- it "should warn when using default_" do
13
- Kernel.should_receive(:warn).with("default_post has been deprecated. Please replace instances of default_post with the new_post method")
14
- @mod.default_post
15
- end
16
-
17
- it "should use the correct builder name" do
18
- Kernel.should_receive(:warn).with("default_comment has been deprecated. Please replace instances of default_comment with the new_comment method")
19
- @mod.default_comment
20
- end
21
-
22
- it "should return a new instance" do
23
- Kernel.stub!(:warn).and_return nil
24
-
25
- post = @mod.default_post
26
- post.should be_a_kind_of(Post)
27
- post.should be_a_new_record
28
- end
29
- end
@@ -1,37 +0,0 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
2
-
3
- module FixtureReplacement
4
- describe "extending an object" do
5
- it "should not create the create_* method in every instance of the class" do
6
- mod = Module.new do
7
- extend FixtureReplacement::ClassMethods
8
-
9
- attributes_for :user do |x|
10
- x.first_name = "Scott"
11
- end
12
- end
13
-
14
- o1 = Object.new
15
- o1.extend mod
16
-
17
- Object.new.should_not respond_to(:create_user)
18
- end
19
- end
20
-
21
- describe "including an object" do
22
- it "should include methods into instances of the class" do
23
- mod = Module.new do
24
- extend FixtureReplacement::ClassMethods
25
-
26
- attributes_for :user do |x|
27
- x.first_name = "Scott"
28
- end
29
- end
30
-
31
- klass = Class.new { include mod }
32
- obj = klass.new
33
-
34
- obj.should respond_to(:create_user)
35
- end
36
- end
37
- end
@@ -1,64 +0,0 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
2
-
3
- module FixtureReplacement
4
- describe "HasAndBelongsToMany Associations" do
5
- before :each do
6
- @obj = use_module do
7
- attributes_for :subscriber do |s|
8
- s.first_name = "Scott"
9
- s.subscriptions = [new_subscription]
10
- end
11
-
12
- attributes_for :subscription do |s|
13
- s.name = "The New York Times"
14
- end
15
-
16
- attributes_for :subscriber_with_two_subscriptions, :from => :subscriber, :class => Subscriber do |s|
17
- s.subscriptions = [new_harpers_subscription, new_ny_times_subscription]
18
- end
19
-
20
- attributes_for :harpers_subscription, :class => Subscription do |s|
21
- s.name = "Harper's Magazine"
22
- end
23
-
24
- attributes_for :ny_times_subscription, :from => :subscription, :class => Subscription
25
- end
26
- end
27
-
28
- it "should have the fixture create_subscriber" do
29
- @obj.should respond_to(:create_subscriber)
30
- end
31
-
32
- it "should have the fixture create_subscription" do
33
- @obj.should respond_to(:create_subscription)
34
- end
35
-
36
- it "should be able to create a new subscriber" do
37
- lambda {
38
- @obj.create_subscriber
39
- }.should_not raise_error
40
- end
41
-
42
- it "should have the subscriber with the default subscription" do
43
- subscriber = @obj.create_subscriber
44
- subscriber.should have(1).subscription
45
- subscriber.subscriptions.first.name.should == "The New York Times"
46
- end
47
-
48
- it "should be able to create a subscriber with two subscriptions (inline)" do
49
- subscription_one = @obj.create_harpers_subscription
50
- subscription_two = @obj.create_ny_times_subscription
51
-
52
- subscriptions = [subscription_one, subscription_two]
53
-
54
- subscriber = @obj.create_subscriber(:subscriptions => subscriptions)
55
-
56
- subscriber.subscriptions.should == subscriptions
57
- end
58
-
59
- it "should be able to create a subscriber with two subscriptions, from the fixtures" do
60
- subscriber = @obj.create_subscriber_with_two_subscriptions
61
- subscriber.should have(2).subscriptions
62
- end
63
- end
64
- end
@@ -1,96 +0,0 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
2
-
3
- module FixtureReplacement
4
- describe "the new_* method" do
5
- it "should be a user for attributes_for :user" do
6
- obj = use_module do
7
- attributes_for :user
8
- end
9
-
10
- obj.new_user.should be_a_kind_of(User)
11
- end
12
-
13
- it "should use the given class" do
14
- obj = use_module do
15
- attributes_for :foo, :class => User
16
- end
17
-
18
- obj.new_foo.should be_a_kind_of(User)
19
- end
20
-
21
- it "should find the correct class name" do
22
- obj = use_module do
23
- attributes_for :admin
24
- end
25
-
26
- obj.new_admin.should be_a_kind_of(Admin)
27
- end
28
-
29
- it "should return a new object with the keys given in user_attributes" do
30
- obj = use_module do
31
- attributes_for :user do |u|
32
- u.key = "val"
33
- end
34
- end
35
-
36
- obj.new_user.key.should == "val"
37
- end
38
-
39
- it "should over-write the User's hash with any hash given to new_user" do
40
- obj = use_module do
41
- attributes_for :user do |u|
42
- u.key = "val"
43
- end
44
- end
45
-
46
- obj.new_user(:key => "other_value").key.should == "other_value"
47
- end
48
-
49
- it "should add any hash key-value pairs which weren't previously given in user_attributes" do
50
- obj = use_module do
51
- attributes_for :user do |u|
52
- u.key = "val"
53
- end
54
- end
55
-
56
- user = obj.new_user(:other_key => "other_value")
57
- user.key.should == "val"
58
- user.other_key.should == "other_value"
59
- end
60
-
61
- it "should not be saved to the database" do
62
- obj = use_module do
63
- attributes_for :user do |u|
64
- u.key = "val"
65
- end
66
- end
67
-
68
- obj.new_user.should be_a_new_record
69
- end
70
-
71
- it "should be able to be saved to the database" do
72
- obj = use_module do
73
- attributes_for :user do |u|
74
- u.key = "val"
75
- end
76
- end
77
-
78
- lambda {
79
- obj.new_user.save!
80
- }.should_not raise_error
81
- end
82
-
83
- it "should yield the object inside the block" do
84
- obj = nil
85
-
86
- mod = use_module do
87
- attributes_for :user do |u|
88
- obj = u
89
- end
90
- end
91
-
92
- mod.new_user # trigger the block
93
- obj.should be_a_kind_of(User)
94
- end
95
- end
96
- end
@@ -1,43 +0,0 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
2
-
3
- module FixtureReplacement
4
- describe "With a public, user defined method" do
5
- before do
6
- @obj = use_module do
7
- attributes_for :user_with_a_public_method, :class => User do |u|
8
- u.key = a_public_method
9
- end
10
-
11
- def a_public_method
12
- :public
13
- end
14
- end
15
- end
16
-
17
- it "should be able to call it" do
18
- user = @obj.new_user_with_a_public_method
19
- user.key.should == :public
20
- end
21
- end
22
-
23
- describe "With a private, user defined method" do
24
- before do
25
- @obj = use_module do
26
- attributes_for :user_with_a_private_method, :class => User do |u|
27
- u.key = a_private_method
28
- end
29
-
30
- private
31
-
32
- def a_private_method
33
- :private
34
- end
35
- end
36
- end
37
-
38
- it "should be able to call it" do
39
- user = @obj.new_user_with_a_private_method
40
- user.key.should == :private
41
- end
42
- end
43
- end
@@ -1,21 +0,0 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
2
-
3
- module FixtureReplacement
4
- describe "including methods" do
5
- it "should have the create_user method as public" do
6
- obj = use_module do
7
- attributes_for :user
8
- end
9
-
10
- obj.public_methods.should include("create_user")
11
- end
12
-
13
- it "should respond_to? create_user" do
14
- obj = use_module do
15
- attributes_for :user
16
- end
17
-
18
- obj.respond_to?(:create_user).should be_true
19
- end
20
- end
21
- end
@@ -1,41 +0,0 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
2
-
3
- module FixtureReplacement
4
- describe "valid_*_attributes" do
5
- it "should generate the method valid_user_attributes when attributes_for is specified" do
6
- obj = use_module do
7
- attributes_for :user
8
- end
9
-
10
- obj.should respond_to(:valid_user_attributes)
11
- end
12
-
13
- it "should generate the method valid_member_attributes when attributes_for is specified" do
14
- obj = use_module do
15
- attributes_for :member
16
- end
17
-
18
- obj.should respond_to(:valid_member_attributes)
19
- end
20
-
21
- it "should have the attributes given as a hash" do
22
- obj = use_module do
23
- attributes_for :user do |x|
24
- x.key = 17
25
- end
26
- end
27
-
28
- obj.valid_user_attributes.should include({ "key" => 17 })
29
- end
30
-
31
- it "should have the attributes given" do
32
- obj = use_module do
33
- attributes_for :user do |x|
34
- x.key = 18
35
- end
36
- end
37
-
38
- obj.valid_user_attributes.should include({ "key" => 18 })
39
- end
40
- end
41
- end
@@ -1,54 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
-
3
- module FixtureReplacement
4
- describe "validations" do
5
- it "should not raise with a record that has no validations" do
6
- fr = mock_fr_module do
7
- attributes_for :no_validation do
8
- end
9
- end
10
-
11
- lambda {
12
- fr.validate!
13
- }.should_not raise_error
14
- end
15
-
16
- it "should raise an error when the record is not valid" do
17
- fr = mock_fr_module do
18
- attributes_for :validate_name
19
- end
20
-
21
- lambda {
22
- fr.validate!
23
- }.should raise_error
24
- end
25
-
26
- it "should not raise if the record is valid" do
27
- fr = mock_fr_module do
28
- attributes_for :validate_name do |n|
29
- n.name = "Scott"
30
- end
31
- end
32
-
33
- lambda {
34
- fr.validate!
35
- }.should_not raise_error
36
- end
37
-
38
- it "should not raise if first loaded with an invalid record, and later a valid one after reloading" do
39
- fr = mock_fr_module do
40
- attributes_for :validate_name
41
- end
42
-
43
- fr.reload!
44
-
45
- fr.attributes_for :validate_name do |n|
46
- n.name = "Scott"
47
- end
48
-
49
- lambda {
50
- fr.validate!
51
- }.should_not raise_error
52
- end
53
- end
54
- end
@@ -1,71 +0,0 @@
1
- #
2
- # Bug Report:
3
- #
4
- #
5
- # [#17249] String.random in a STI base class works, but doesn't work with inherited classes
6
- # Date:
7
- # 2008-01-20 14:01 Priority:
8
- # 3
9
- # Submitted By:
10
- # andy watts (andywatts) Assigned To:
11
- # Nobody (None)
12
- # Category:
13
- # Console (script/console) State:
14
- # Open
15
- # Summary:
16
- # String.random in a STI base class works, but doesn't work with inherited classes
17
- #
18
- # Detailed description
19
- #
20
- # Love the plugin, but seem to have found a bug with the latest FixtureReplacemnt2.
21
- #
22
- # There appears to be a problem when a base STI class in example_data has a random string.
23
- # The derived STI classes do not get a fresh random string with each call.
24
- #
25
- # Eg.
26
- # Given the below example_data.rb, repeated new_user/create_user will work fine.
27
- # Each call creating a new object with a new random string.
28
- #
29
- # However the STI classes do not work as expected...
30
- # new_player/create_player will always return an object with the same random string
31
- #
32
- #
33
- # attributes_for :user do |u|
34
- # u.first_name = "First_name_" + String.random
35
- # u.email = "#{u.first_name}@aaa.com"
36
- # end
37
- #
38
- # attributes_for :player, :from => :user, :class => Player
39
- #
40
- #
41
- # Thanks
42
- # Andy
43
- #
44
- require File.dirname(__FILE__) + "/../../spec_helper"
45
-
46
- module FixtureReplacement
47
- describe "random_string" do
48
- before :each do
49
- @obj = use_module do
50
- attributes_for :user do |u|
51
- u.key = "foo"
52
- u.username = random_string(55)
53
- end
54
-
55
- attributes_for :player, :class => Player, :from => :user
56
- end
57
- end
58
-
59
- it "should have a different string for each instance in the base class" do
60
- user1 = @obj.create_user
61
- user2 = @obj.create_user
62
- user1.username.should_not == user2.username
63
- end
64
-
65
- it "should have a different string for each instance in the inherited class (with STI)" do
66
- player1 = @obj.create_player
67
- player2 = @obj.create_player
68
- player1.username.should_not == player2.username
69
- end
70
- end
71
- end