poly_belongs_to 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/poly_belongs_to/poly_belongs_to.rb +4 -0
- data/lib/poly_belongs_to/version.rb +1 -1
- data/test/dummy/app/models/phone.rb +1 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +4128 -0
- data/test/dup_test.rb +13 -7
- data/test/pbt_test.rb +21 -6
- metadata +2 -2
data/test/dup_test.rb
CHANGED
@@ -29,12 +29,18 @@ class DupTest < ActiveSupport::TestCase
|
|
29
29
|
bob_prof = profiles(:bob_prof)
|
30
30
|
contact = user1.contacts.new
|
31
31
|
contact.pbt_deep_dup_build(bob_prof)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
CleanAttrs[
|
36
|
-
CleanAttrs[
|
37
|
-
CleanAttrs[
|
38
|
-
CleanAttrs[
|
32
|
+
cp = contact.profile
|
33
|
+
cpa = cp.addresses
|
34
|
+
cpaf = cpa.first
|
35
|
+
CleanAttrs[cp ].must_equal CleanAttrs[bob_prof]
|
36
|
+
CleanAttrs[cpaf ].must_equal CleanAttrs[bob_prof.addresses.first]
|
37
|
+
CleanAttrs[cpaf.squishies.first ].must_equal CleanAttrs[bob_prof.addresses.first.squishies.first]
|
38
|
+
CleanAttrs[cpaf.geo_location ].must_equal CleanAttrs[bob_prof.addresses.first.geo_location]
|
39
|
+
CleanAttrs[cpaf.geo_location.squishies.first].must_equal CleanAttrs[bob_prof.addresses.first.geo_location.squishies.first]
|
40
|
+
CleanAttrs[cp.addresses.last ].must_equal CleanAttrs[bob_prof.addresses.last]
|
41
|
+
CleanAttrs[cp.phones.first ].must_equal CleanAttrs[bob_prof.phones.first]
|
42
|
+
CleanAttrs[cp.phones.first.squishy ].must_equal CleanAttrs[bob_prof.phones.first.squishy]
|
43
|
+
CleanAttrs[cp.phones.last ].must_equal CleanAttrs[bob_prof.phones.last]
|
44
|
+
CleanAttrs[cp.photo ].must_equal CleanAttrs[bob_prof.photo]
|
39
45
|
end
|
40
46
|
end
|
data/test/pbt_test.rb
CHANGED
@@ -7,42 +7,53 @@ class PbtTest < ActiveSupport::TestCase
|
|
7
7
|
it "AttrSanitizer removes conflicting attributes" do
|
8
8
|
user = users(:bob)
|
9
9
|
PolyBelongsTo::Pbt::AttrSanitizer[user].must_equal Hash[id: nil, content: user.content].stringify_keys
|
10
|
+
PolyBelongsTo::Pbt::AttrSanitizer[nil ].must_equal Hash[]
|
10
11
|
end
|
11
12
|
|
12
13
|
it "BuildCmd returns build command" do
|
13
14
|
profile = profiles(:bob_prof)
|
14
15
|
"#{PolyBelongsTo::Pbt::BuildCmd[profile,Phone]}".must_equal "phones.build"
|
15
16
|
"#{PolyBelongsTo::Pbt::BuildCmd[profile,Photo]}".must_equal "build_photo"
|
17
|
+
PolyBelongsTo::Pbt::BuildCmd[nil, Photo].must_be_nil
|
18
|
+
PolyBelongsTo::Pbt::BuildCmd[profile, nil].must_be_nil
|
16
19
|
end
|
17
20
|
|
18
21
|
it "Reflects retruns has_one and has_many relationships" do
|
19
22
|
profile = profiles(:bob_prof)
|
20
23
|
PolyBelongsTo::Pbt::Reflects[profile].sort.must_equal [:phones, :addresses, :photo].sort
|
24
|
+
PolyBelongsTo::Pbt::Reflects[nil ].must_equal Array[]
|
21
25
|
end
|
22
26
|
|
23
27
|
it "ReflectsAsClasses one and many relations as classes" do
|
24
28
|
profile = profiles(:bob_prof)
|
25
29
|
PolyBelongsTo::Pbt::ReflectsAsClasses[profile].map(&:hash).sort.must_equal [Phone, Address, Photo].map(&:hash).sort
|
30
|
+
PolyBelongsTo::Pbt::ReflectsAsClasses[nil ].must_equal Array[]
|
26
31
|
end
|
27
32
|
|
28
33
|
it "IsReflected gives boolean of child" do
|
29
34
|
profile = profiles(:bob_prof)
|
30
|
-
PolyBelongsTo::Pbt::IsReflected[profile,Phone].must_equal true
|
35
|
+
PolyBelongsTo::Pbt::IsReflected[profile, Phone].must_equal true
|
31
36
|
PolyBelongsTo::Pbt::IsReflected[profile,Address].must_equal true
|
32
|
-
PolyBelongsTo::Pbt::IsReflected[profile,Photo].must_equal true
|
33
|
-
PolyBelongsTo::Pbt::IsReflected[profile,User].must_equal false
|
37
|
+
PolyBelongsTo::Pbt::IsReflected[profile, Photo].must_equal true
|
38
|
+
PolyBelongsTo::Pbt::IsReflected[profile, User].must_equal false
|
39
|
+
PolyBelongsTo::Pbt::IsReflected[nil, User].must_equal false
|
40
|
+
PolyBelongsTo::Pbt::IsReflected[profile, nil].must_equal false
|
34
41
|
end
|
35
42
|
|
36
|
-
it "SingularOrPlural
|
43
|
+
it "SingularOrPlural responds for child relations" do
|
37
44
|
profile = profiles(:susan_prof)
|
38
45
|
PolyBelongsTo::Pbt::SingularOrPlural[profile,Phone].must_equal :plural
|
39
46
|
PolyBelongsTo::Pbt::SingularOrPlural[profile,Photo].must_equal :singular
|
40
|
-
PolyBelongsTo::Pbt::SingularOrPlural[profile,User].
|
47
|
+
PolyBelongsTo::Pbt::SingularOrPlural[profile, User].must_be_nil
|
48
|
+
PolyBelongsTo::Pbt::SingularOrPlural[nil, User].must_be_nil
|
49
|
+
PolyBelongsTo::Pbt::SingularOrPlural[profile, nil].must_be_nil
|
41
50
|
end
|
42
51
|
|
43
52
|
it "IsSingular tells child singleness" do
|
44
53
|
profile = profiles(:steve_prof)
|
45
54
|
PolyBelongsTo::Pbt::IsSingular[profile,Phone].must_be_same_as false
|
55
|
+
PolyBelongsTo::Pbt::IsSingular[nil, Phone].must_be_same_as false
|
56
|
+
PolyBelongsTo::Pbt::IsSingular[profile, nil].must_be_same_as false
|
46
57
|
PolyBelongsTo::Pbt::IsSingular[profile,Photo].must_be_same_as true
|
47
58
|
end
|
48
59
|
|
@@ -50,12 +61,16 @@ class PbtTest < ActiveSupport::TestCase
|
|
50
61
|
profile = profiles(:bob_prof)
|
51
62
|
PolyBelongsTo::Pbt::IsPlural[profile,Phone].must_be_same_as true
|
52
63
|
PolyBelongsTo::Pbt::IsPlural[profile,Photo].must_be_same_as false
|
64
|
+
PolyBelongsTo::Pbt::IsPlural[nil, Photo].must_be_same_as false
|
65
|
+
PolyBelongsTo::Pbt::IsPlural[profile, nil].must_be_same_as false
|
53
66
|
end
|
54
67
|
|
55
68
|
it "CollectionProxy: singular or plural proxy name" do
|
56
69
|
profile = profiles(:steve_prof)
|
57
70
|
PolyBelongsTo::Pbt::CollectionProxy[profile,Phone].must_equal :phones
|
58
71
|
PolyBelongsTo::Pbt::CollectionProxy[profile,Photo].must_equal :photo
|
59
|
-
PolyBelongsTo::Pbt::CollectionProxy[profile,User].
|
72
|
+
PolyBelongsTo::Pbt::CollectionProxy[profile, User].must_be_nil
|
73
|
+
PolyBelongsTo::Pbt::CollectionProxy[nil, User].must_be_nil
|
74
|
+
PolyBelongsTo::Pbt::CollectionProxy[profile, nil].must_be_nil
|
60
75
|
end
|
61
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poly_belongs_to
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel P. Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|