|
1 | 1 | require "../../spec_helper" |
2 | 2 |
|
3 | | -# describe Factory::Jennifer::Base do |
4 | | -# let(:described_class) { Factory::Jennifer::Base } |
5 | | - |
6 | | -# before do |
7 | | -# ::Jennifer::Adapter.adapter.begin_transaction |
8 | | -# end |
9 | | - |
10 | | -# after do |
11 | | -# ::Jennifer::Adapter.adapter.rollback_transaction |
12 | | -# end |
13 | | - |
14 | | -# describe "%association" do |
15 | | -# it "uses factory's defined association" do |
16 | | -# film = Factory.create_custom_film([:bad, :hit]) |
17 | | -# expect(film.author.nil?).wont_equal(true) |
18 | | -# expect(film.author!.name).must_match(/Author \d*$/) |
19 | | -# end |
20 | | - |
21 | | -# it "uses trait's author if it is given" do |
22 | | -# film = Factory.create_fiction_film([:with_special_author]) |
23 | | -# expect(film.author.nil?).wont_equal(true) |
24 | | -# expect(film.author!.name).must_equal("Special Author") |
25 | | -# end |
26 | | - |
27 | | -# it "uses given overrides for factory" do |
28 | | -# film = Factory.create_fiction_film([:with_special_author]) |
29 | | -# expect(film.author!.name).must_equal("Special Author") |
30 | | -# end |
31 | | - |
32 | | -# it "uses parent association if current factory has no" do |
33 | | -# film = Factory.create_fiction_film |
34 | | -# expect(film.author.nil?).must_equal(false) |
35 | | -# end |
36 | | - |
37 | | -# it "creates object without association if there is no one" do |
38 | | -# film = Factory.create_film |
39 | | -# expect(film.author.nil?).must_equal(true) |
40 | | -# end |
41 | | -# end |
42 | | - |
43 | | -# describe "%factory_creators" do |
44 | | -# it "defines all create methods on module level" do |
45 | | -# expect(Factory.create_custom_film.new_record?).must_equal(false) |
46 | | -# expect(Factory.create_custom_film(name: "New film").new_record?).must_equal(false) |
47 | | -# expect(Factory.create_custom_film({:name => "New"}).new_record?).must_equal(false) |
48 | | -# expect(Factory.create_custom_film([:bad]).new_record?).must_equal(false) |
49 | | -# expect(Factory.create_custom_film([:bad], name: "new").new_record?).must_equal(false) |
50 | | -# expect(Factory.create_custom_film([:bad], {:name => "new"}).new_record?).must_equal(false) |
51 | | -# expect(Factory.create_custom_film(1)[0].new_record?).must_equal(false) |
52 | | -# expect(Factory.create_custom_film(1, name: "asd")[0].new_record?).must_equal(false) |
53 | | -# expect(Factory.create_custom_film(1, [:bad])[0].new_record?).must_equal(false) |
54 | | -# expect(Factory.create_custom_film(1, {:name => "asd"})[0].new_record?).must_equal(false) |
55 | | -# expect(Factory.create_custom_film(1, [:bad], name: "asd")[0].new_record?).must_equal(false) |
56 | | -# expect(Factory.create_custom_film(1, [:bad], {:name => "asd"})[0].new_record?).must_equal(false) |
57 | | -# end |
58 | | -# end |
59 | | - |
60 | | -# describe "%before_create" do |
61 | | -# it "calls before create" do |
62 | | -# film = CustomFilmFactory.create |
63 | | -# expect(film.name).must_match(/before/) |
64 | | -# film.reload |
65 | | -# expect(film.name).must_match(/before/) |
66 | | -# end |
67 | | -# end |
68 | | - |
69 | | -# describe "%after_create" do |
70 | | -# it "calls callback after creating" do |
71 | | -# film = CustomFilmFactory.create |
72 | | -# expect(film.name).must_match(/after$/) |
73 | | -# film.reload |
74 | | -# expect(film.name).wont_match(/after$/) |
75 | | -# end |
76 | | -# end |
77 | | - |
78 | | -# describe ".create" do |
79 | | -# it "accepts hash attributes" do |
80 | | -# film = FilmFactory.create({:name => "Custom"}) |
81 | | -# expect(film.name).must_equal("Custom") |
82 | | -# expect(film.new_record?).must_equal(false) |
83 | | -# end |
84 | | - |
85 | | -# it "accepts traits" do |
86 | | -# film = FilmFactory.create([:hit, :bad]) |
87 | | -# expect(film.rating).must_equal(0) |
88 | | -# expect(film.name).must_match(/Best Film/) |
89 | | -# expect(film.new_record?).must_equal(false) |
90 | | -# end |
91 | | - |
92 | | -# it "accepts traits and attributes" do |
93 | | -# film = FilmFactory.create([:hit, :bad], {:budget => 10.0f32}) |
94 | | -# expect(film.rating).must_equal(0) |
95 | | -# expect(film.name).must_match(/Best Film/) |
96 | | -# expect(film.budget).must_equal(10.0f32) |
97 | | -# expect(film.new_record?).must_equal(false) |
98 | | -# end |
99 | | - |
100 | | -# it "all model callbacks during creating" do |
101 | | -# film = FilmFactory.create |
102 | | -# expect(film.before_create).must_equal(true) |
103 | | -# expect(film.before_save).must_equal(true) |
104 | | -# expect(film.after_initialize).must_equal(true) |
105 | | -# end |
106 | | - |
107 | | -# describe "ancestor factory" do |
108 | | -# it "accepts no arguments" do |
109 | | -# film = CustomFilmFactory.create |
110 | | -# expect(film.name).must_match(/Custom Film \d*/) |
111 | | -# expect(film.new_record?).must_equal(false) |
112 | | -# end |
113 | | - |
114 | | -# it "accepts hash attributes" do |
115 | | -# film = CustomFilmFactory.create({:name => "Custom"}) |
116 | | -# expect(film.name).must_equal("Custombeforeafter") |
117 | | -# expect(film.new_record?).must_equal(false) |
118 | | -# end |
119 | | - |
120 | | -# it "accepts traits" do |
121 | | -# film = CustomFilmFactory.create([:hit, :bad]) |
122 | | -# expect(film.rating).must_equal(0) |
123 | | -# expect(film.name).must_match(/Best Film/) |
124 | | -# expect(film.new_record?).must_equal(false) |
125 | | -# end |
126 | | - |
127 | | -# it "accepts traits and attributes" do |
128 | | -# film = CustomFilmFactory.create([:hit, :bad], {:budget => 10.0f32}) |
129 | | -# expect(film.rating).must_equal(0) |
130 | | -# expect(film.name).must_match(/Best Film/) |
131 | | -# expect(film.budget).must_equal(10.0f32) |
132 | | -# expect(film.new_record?).must_equal(false) |
133 | | -# end |
134 | | -# end |
135 | | -# end |
136 | | -# end |
| 3 | +describe Factory::Jennifer::Base do |
| 4 | + let(:described_class) { Factory::Jennifer::Base } |
| 5 | + |
| 6 | + before do |
| 7 | + ::Jennifer::Adapter.adapter.begin_transaction |
| 8 | + end |
| 9 | + |
| 10 | + after do |
| 11 | + ::Jennifer::Adapter.adapter.rollback_transaction |
| 12 | + end |
| 13 | + |
| 14 | + describe "%association" do |
| 15 | + it "uses factory's defined association" do |
| 16 | + film = Factory.create_custom_film([:bad, :hit]) |
| 17 | + expect(film.author.nil?).wont_equal(true) |
| 18 | + expect(film.author!.name).must_match(/Author \d*$/) |
| 19 | + end |
| 20 | + |
| 21 | + it "uses trait's author if it is given" do |
| 22 | + film = Factory.create_fiction_film([:with_special_author]) |
| 23 | + expect(film.author.nil?).wont_equal(true) |
| 24 | + expect(film.author!.name).must_equal("Special Author") |
| 25 | + end |
| 26 | + |
| 27 | + it "uses given overrides for factory" do |
| 28 | + film = Factory.create_fiction_film([:with_special_author]) |
| 29 | + expect(film.author!.name).must_equal("Special Author") |
| 30 | + end |
| 31 | + |
| 32 | + it "uses parent association if current factory has no" do |
| 33 | + film = Factory.create_fiction_film |
| 34 | + expect(film.author.nil?).must_equal(false) |
| 35 | + end |
| 36 | + |
| 37 | + it "creates object without association if there is no one" do |
| 38 | + film = Factory.create_film |
| 39 | + expect(film.author.nil?).must_equal(true) |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + describe "%factory_creators" do |
| 44 | + it "defines all create methods on module level" do |
| 45 | + expect(Factory.create_custom_film.new_record?).must_equal(false) |
| 46 | + expect(Factory.create_custom_film(name: "New film").new_record?).must_equal(false) |
| 47 | + expect(Factory.create_custom_film({:name => "New"}).new_record?).must_equal(false) |
| 48 | + expect(Factory.create_custom_film([:bad]).new_record?).must_equal(false) |
| 49 | + expect(Factory.create_custom_film([:bad], name: "new").new_record?).must_equal(false) |
| 50 | + expect(Factory.create_custom_film([:bad], {:name => "new"}).new_record?).must_equal(false) |
| 51 | + expect(Factory.create_custom_film(1)[0].new_record?).must_equal(false) |
| 52 | + expect(Factory.create_custom_film(1, name: "asd")[0].new_record?).must_equal(false) |
| 53 | + expect(Factory.create_custom_film(1, [:bad])[0].new_record?).must_equal(false) |
| 54 | + expect(Factory.create_custom_film(1, {:name => "asd"})[0].new_record?).must_equal(false) |
| 55 | + expect(Factory.create_custom_film(1, [:bad], name: "asd")[0].new_record?).must_equal(false) |
| 56 | + expect(Factory.create_custom_film(1, [:bad], {:name => "asd"})[0].new_record?).must_equal(false) |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + describe "%before_create" do |
| 61 | + it "calls before create" do |
| 62 | + film = CustomFilmFactory.create |
| 63 | + expect(film.name).must_match(/before/) |
| 64 | + film.reload |
| 65 | + expect(film.name).must_match(/before/) |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + describe "%after_create" do |
| 70 | + it "calls callback after creating" do |
| 71 | + film = CustomFilmFactory.create |
| 72 | + expect(film.name).must_match(/after$/) |
| 73 | + film.reload |
| 74 | + expect(film.name).wont_match(/after$/) |
| 75 | + end |
| 76 | + end |
| 77 | + |
| 78 | + describe ".create" do |
| 79 | + it "accepts hash attributes" do |
| 80 | + film = FilmFactory.create({:name => "Custom"}) |
| 81 | + expect(film.name).must_equal("Custom") |
| 82 | + expect(film.new_record?).must_equal(false) |
| 83 | + end |
| 84 | + |
| 85 | + it "accepts traits" do |
| 86 | + film = FilmFactory.create([:hit, :bad]) |
| 87 | + expect(film.rating).must_equal(0) |
| 88 | + expect(film.name).must_match(/Best Film/) |
| 89 | + expect(film.new_record?).must_equal(false) |
| 90 | + end |
| 91 | + |
| 92 | + it "accepts traits and attributes" do |
| 93 | + film = FilmFactory.create([:hit, :bad], {:budget => 10.0f32}) |
| 94 | + expect(film.rating).must_equal(0) |
| 95 | + expect(film.name).must_match(/Best Film/) |
| 96 | + expect(film.budget).must_equal(10.0f32) |
| 97 | + expect(film.new_record?).must_equal(false) |
| 98 | + end |
| 99 | + |
| 100 | + it "all model callbacks during creating" do |
| 101 | + film = FilmFactory.create |
| 102 | + expect(film.before_create).must_equal(true) |
| 103 | + expect(film.before_save).must_equal(true) |
| 104 | + expect(film.after_initialize).must_equal(true) |
| 105 | + end |
| 106 | + |
| 107 | + describe "ancestor factory" do |
| 108 | + it "accepts no arguments" do |
| 109 | + film = CustomFilmFactory.create |
| 110 | + expect(film.name).must_match(/Custom Film \d*/) |
| 111 | + expect(film.new_record?).must_equal(false) |
| 112 | + end |
| 113 | + |
| 114 | + it "accepts hash attributes" do |
| 115 | + film = CustomFilmFactory.create({:name => "Custom"}) |
| 116 | + expect(film.name).must_equal("Custombeforeafter") |
| 117 | + expect(film.new_record?).must_equal(false) |
| 118 | + end |
| 119 | + |
| 120 | + it "accepts traits" do |
| 121 | + film = CustomFilmFactory.create([:hit, :bad]) |
| 122 | + expect(film.rating).must_equal(0) |
| 123 | + expect(film.name).must_match(/Best Film/) |
| 124 | + expect(film.new_record?).must_equal(false) |
| 125 | + end |
| 126 | + |
| 127 | + it "accepts traits and attributes" do |
| 128 | + film = CustomFilmFactory.create([:hit, :bad], {:budget => 10.0f32}) |
| 129 | + expect(film.rating).must_equal(0) |
| 130 | + expect(film.name).must_match(/Best Film/) |
| 131 | + expect(film.budget).must_equal(10.0f32) |
| 132 | + expect(film.new_record?).must_equal(false) |
| 133 | + end |
| 134 | + end |
| 135 | + end |
| 136 | +end |
0 commit comments