@@ -11,6 +11,52 @@ describe Factory::Jennifer::Base do
1111 ::Jennifer ::Adapter .adapter.rollback_transaction
1212 end
1313
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+
1460 describe " %before_create" do
1561 it " calls before create" do
1662 film = CustomFilmFactory .create
@@ -51,6 +97,13 @@ describe Factory::Jennifer::Base do
5197 expect(film.new_record?).must_equal(false )
5298 end
5399
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+
54107 describe " ancestor factory" do
55108 it " accepts no arguments" do
56109 film = CustomFilmFactory .create
0 commit comments