poly_belongs_to 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/dup_test.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  require 'test_helper'
3
2
  require 'minitest/autorun'
4
3
 
@@ -24,7 +23,6 @@ class DupTest < ActiveSupport::TestCase
24
23
  end
25
24
 
26
25
  it "builds deep copy of dup'd attributes" do
27
- #skip "Prepping method. It's in the making."
28
26
  user1 = users(:steve)
29
27
  bob_prof = profiles(:bob_prof)
30
28
  contact = user1.contacts.new
@@ -0,0 +1,75 @@
1
+ require 'test_helper'
2
+ require 'minitest/autorun'
3
+
4
+ class FakedCollectionTest < ActiveSupport::TestCase
5
+ fixtures :all
6
+
7
+ let(:photos){
8
+ steve_prof = users(:steve).profiles.first
9
+ PolyBelongsTo::FakedCollection.new(steve_prof, Photo)
10
+ }
11
+
12
+ it ".all is an Array" do
13
+ photos.all.is_a?(Array).must_be_same_as true
14
+ photos.all.kind_of?(Array).must_be_same_as true
15
+ end
16
+
17
+ it "first is the item" do
18
+ photos.first.class.name.must_equal "Photo"
19
+ end
20
+
21
+ it "last is the item" do
22
+ photos.last.class.name.must_equal "Photo"
23
+ end
24
+
25
+ it "counts as 1 or 0" do
26
+ photos.count.between?(0,1).must_be_same_as true
27
+ photos.size.between?(0,1).must_be_same_as true
28
+ end
29
+
30
+ it "FakedCollection has ancestors" do
31
+ photos.ancestors.include?(Object).must_be_same_as true
32
+ end
33
+
34
+ it "build returns FakedCollection object" do
35
+ photos.kind_of?(PolyBelongsTo::FakedCollection).must_be_same_as true
36
+ end
37
+
38
+ it "builds appropriately" do
39
+ photos.build({content: "cheese"})
40
+ photos.first.content.must_equal "cheese"
41
+ end
42
+
43
+ it "build returns self and not nil" do
44
+ res = photos.build({content: "cheese"})
45
+ res.wont_be_nil
46
+ res.class.name.must_equal photos.class.name
47
+ res.first.content.must_equal "cheese"
48
+ photos.first.content.must_equal "cheese"
49
+ end
50
+
51
+ it "loops appropriately" do
52
+ photos.each do |photo|
53
+ photo.class.name.must_equal "Photo"
54
+ end
55
+ end
56
+
57
+ it "defines klass to inner items class" do
58
+ photos.klass.name.must_equal "Photo"
59
+ end
60
+
61
+ it "respond_to? :first and :last" do
62
+ photos.respond_to?(:first).must_be_same_as true
63
+ photos.respond_to?(:last).must_be_same_as true
64
+ end
65
+
66
+ it "knows sneeze is a missing method" do
67
+ ->{photos.sneeze}.must_raise NoMethodError
68
+ end
69
+
70
+ it "will not initialize on has_many" do
71
+ steve = users(:steve)
72
+ ->{ PolyBelongsTo::FakedCollection.new(steve, Profile) }.must_raise RuntimeError
73
+ end
74
+
75
+ end
data/test/pbt_test.rb CHANGED
@@ -73,4 +73,37 @@ class PbtTest < ActiveSupport::TestCase
73
73
  PolyBelongsTo::Pbt::CollectionProxy[nil, User].must_be_nil
74
74
  PolyBelongsTo::Pbt::CollectionProxy[profile, nil].must_be_nil
75
75
  end
76
+
77
+ it "AsCollectionProxy: has_one emulated collectionproxy" do
78
+ address = profiles(:bob_prof).addresses.first
79
+ address_to_geo = PolyBelongsTo::Pbt::AsCollectionProxy[address, GeoLocation]
80
+ address_to_geo.respond_to?(:klass).must_be_same_as true
81
+ address_to_geo.respond_to?(:build).must_be_same_as true
82
+ address_to_geo.respond_to?(:each ).must_be_same_as true
83
+ address_to_geo.respond_to?(:all ).must_be_same_as true
84
+ address_to_geo.respond_to?(:first).must_be_same_as true
85
+ address_to_geo.respond_to?(:last ).must_be_same_as true
86
+ address_to_geo.kind_of?(PolyBelongsTo::FakedCollection).must_be_same_as true
87
+ end
88
+
89
+ it "AsCollectionProxy: has one or zero items" do
90
+ address = profiles(:bob_prof).addresses.first
91
+ address_to_geo = PolyBelongsTo::Pbt::AsCollectionProxy[address, GeoLocation]
92
+ address_to_geo.count.between?(0,1).must_be_same_as true
93
+ address_to_geo.size.between?(0,1).must_be_same_as true
94
+ end
95
+
96
+
97
+ it "AsCollectionProxy: has_many uses AR CollectionProxy" do
98
+ bob = users(:bob)
99
+ bob_to_prof = PolyBelongsTo::Pbt::AsCollectionProxy[bob, Profile]
100
+ bob_to_prof.respond_to?(:klass).must_be_same_as true
101
+ bob_to_prof.respond_to?(:build).must_be_same_as true
102
+ bob_to_prof.respond_to?(:each ).must_be_same_as true
103
+ bob_to_prof.respond_to?(:all ).must_be_same_as true
104
+ bob_to_prof.respond_to?(:first).must_be_same_as true
105
+ bob_to_prof.respond_to?(:last ).must_be_same_as true
106
+ bob_to_prof.kind_of?(ActiveRecord::Associations::CollectionProxy).must_be_same_as true
107
+ end
108
+
76
109
  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.6
4
+ version: 0.1.7
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-21 00:00:00.000000000 Z
11
+ date: 2015-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -96,6 +96,7 @@ files:
96
96
  - Rakefile
97
97
  - lib/poly_belongs_to.rb
98
98
  - lib/poly_belongs_to/dup.rb
99
+ - lib/poly_belongs_to/faked_collection.rb
99
100
  - lib/poly_belongs_to/poly_belongs_to.rb
100
101
  - lib/poly_belongs_to/version.rb
101
102
  - lib/tasks/poly_belongs_to_tasks.rake
@@ -152,6 +153,7 @@ files:
152
153
  - test/dummy/log/test.log
153
154
  - test/dummy/public/favicon.ico
154
155
  - test/dup_test.rb
156
+ - test/faked_collection_test.rb
155
157
  - test/fixtures/addresses.yml
156
158
  - test/fixtures/geo_locations.yml
157
159
  - test/fixtures/phones.yml
@@ -201,6 +203,7 @@ test_files:
201
203
  - test/fixtures/tags.yml
202
204
  - test/fixtures/ssns.yml
203
205
  - test/test_helper.rb
206
+ - test/faked_collection_test.rb
204
207
  - test/dummy/db/test.sqlite3
205
208
  - test/dummy/db/schema.rb
206
209
  - test/dummy/db/migrate/20150220230146_create_squishies.rb