7
7
require "models/cpk"
8
8
9
9
class NonExistentTable < ActiveRecord ::Base ; end
10
- class PkWithDefault < ActiveRecord ::Base ; end
11
10
12
11
class CoreTest < ActiveRecord ::TestCase
13
- fixtures :topics , :cpk_books
14
-
15
- def test_eql_on_default_pk
16
- saved_record = PkWithDefault . new
17
- saved_record . save!
18
- assert_equal 123 , saved_record . id
19
-
20
- record = PkWithDefault . new
21
- assert_equal 123 , record . id
22
-
23
- record2 = PkWithDefault . new
24
- assert_equal 123 , record2 . id
25
-
26
- assert record . eql? ( record ) , "record should eql? itself"
27
- assert_not record . eql? ( saved_record ) , "new record should not eql? saved"
28
- assert_not saved_record . eql? ( record ) , "saved record should not eql? new"
29
- assert_not record . eql? ( record2 ) , "new record should not eql? new record"
30
- assert_not record2 . eql? ( record ) , "new record should not eql? new record"
31
- end
12
+ fixtures :topics
32
13
33
14
def test_inspect_class
34
15
assert_equal "ActiveRecord::Base" , ActiveRecord ::Base . inspect
@@ -174,12 +155,12 @@ def test_find_by_cache_does_not_duplicate_entries
174
155
175
156
def test_composite_pk_models_added_to_a_set
176
157
library = Set . new
177
- # new record with primary key present
158
+ # with primary key present
178
159
library << Cpk ::Book . new ( author_id : 1 , number : 2 )
179
160
180
161
# duplicate
181
- library << cpk_books ( :cpk_great_author_first_book )
182
- library << cpk_books ( :cpk_great_author_first_book )
162
+ library << Cpk :: Book . new ( author_id : 1 , number : 3 )
163
+ library << Cpk :: Book . new ( author_id : 1 , number : 3 )
183
164
184
165
# without primary key being set
185
166
library << Cpk ::Book . new ( title : "Book A" )
@@ -189,34 +170,22 @@ def test_composite_pk_models_added_to_a_set
189
170
end
190
171
191
172
def test_composite_pk_models_equality
192
- book = cpk_books ( :cpk_great_author_first_book )
193
- book_instance_1 = Cpk ::Book . find_by ( author_id : book . author_id , number : book . number )
194
- book_instance_2 = Cpk ::Book . find_by ( author_id : book . author_id , number : book . number )
195
-
196
- assert book_instance_1 == book_instance_1
197
- assert book_instance_1 == book_instance_2
173
+ assert Cpk ::Book . new ( author_id : 1 , number : 2 ) == Cpk ::Book . new ( author_id : 1 , number : 2 )
198
174
199
- # two new records with the same primary key
200
- assert_not Cpk ::Book . new ( author_id : 1 , number : 2 ) == Cpk ::Book . new ( author_id : 1 , number : 2 )
201
- # two new records with an empty primary key values
175
+ assert_not Cpk ::Book . new ( author_id : 1 , number : 2 ) == Cpk ::Book . new ( author_id : 1 , number : 3 )
202
176
assert_not Cpk ::Book . new == Cpk ::Book . new
203
- # two persisted records with a different primary key
204
- assert_not cpk_books ( :cpk_great_author_first_book ) == cpk_books ( :cpk_great_author_second_book )
177
+ assert_not Cpk ::Book . new ( title : "Book A" ) == Cpk ::Book . new ( title : "Book B" )
178
+ assert_not Cpk ::Book . new ( author_id : 1 ) == Cpk ::Book . new ( author_id : 1 )
179
+ assert_not Cpk ::Book . new ( author_id : 1 , title : "Same title" ) == Cpk ::Book . new ( author_id : 1 , title : "Same title" )
205
180
end
206
181
207
182
def test_composite_pk_models_hash
208
- book = cpk_books ( :cpk_great_author_first_book )
209
- book_instance_1 = Cpk ::Book . find_by ( author_id : book . author_id , number : book . number )
210
- book_instance_2 = Cpk ::Book . find_by ( author_id : book . author_id , number : book . number )
211
-
212
- assert_equal book_instance_1 . hash , book_instance_1 . hash
213
- assert_equal book_instance_1 . hash , book_instance_2 . hash
183
+ assert_equal Cpk ::Book . new ( author_id : 1 , number : 2 ) . hash , Cpk ::Book . new ( author_id : 1 , number : 2 ) . hash
214
184
215
- # two new records with the same primary key
216
- assert_not_equal Cpk ::Book . new ( author_id : 1 , number : 2 ) . hash , Cpk ::Book . new ( author_id : 1 , number : 2 ) . hash
217
- # two new records with an empty primary key values
185
+ assert_not_equal Cpk ::Book . new ( author_id : 1 , number : 2 ) . hash , Cpk ::Book . new ( author_id : 1 , number : 3 ) . hash
218
186
assert_not_equal Cpk ::Book . new . hash , Cpk ::Book . new . hash
219
- # two persisted records with a different primary key
220
- assert_not_equal cpk_books ( :cpk_great_author_first_book ) . hash , cpk_books ( :cpk_great_author_second_book ) . hash
187
+ assert_not_equal Cpk ::Book . new ( title : "Book A" ) . hash , Cpk ::Book . new ( title : "Book B" ) . hash
188
+ assert_not_equal Cpk ::Book . new ( author_id : 1 ) . hash , Cpk ::Book . new ( author_id : 1 ) . hash
189
+ assert_not_equal Cpk ::Book . new ( author_id : 1 , title : "Same title" ) . hash , Cpk ::Book . new ( author_id : 1 , title : "Same title" ) . hash
221
190
end
222
191
end
0 commit comments