flickrmocks 0.8.5
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/.autotest +36 -0
- data/.document +5 -0
- data/.gitignore +23 -0
- data/.rspec +3 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +59 -0
- data/Rakefile +76 -0
- data/VERSION +1 -0
- data/autotest/discover.rb +1 -0
- data/flickrmocks.gemspec +155 -0
- data/lib/flickr_mocks/api/api.rb +42 -0
- data/lib/flickr_mocks/api/flickr.rb +27 -0
- data/lib/flickr_mocks/api/helpers.rb +19 -0
- data/lib/flickr_mocks/api/options.rb +55 -0
- data/lib/flickr_mocks/api/sanitize.rb +29 -0
- data/lib/flickr_mocks/fixtures.rb +35 -0
- data/lib/flickr_mocks/flickraw/custom_clone.rb +19 -0
- data/lib/flickr_mocks/flickraw/custom_compare.rb +25 -0
- data/lib/flickr_mocks/flickraw/custom_marshal.rb +39 -0
- data/lib/flickr_mocks/flickraw/flickraw.rb +14 -0
- data/lib/flickr_mocks/helpers.rb +52 -0
- data/lib/flickr_mocks/models/helpers.rb +14 -0
- data/lib/flickr_mocks/models/photo.rb +101 -0
- data/lib/flickr_mocks/models/photo_details.rb +86 -0
- data/lib/flickr_mocks/models/photo_dimensions.rb +103 -0
- data/lib/flickr_mocks/models/photo_search.rb +115 -0
- data/lib/flickr_mocks/models/photo_size.rb +60 -0
- data/lib/flickr_mocks/models/photo_sizes.rb +93 -0
- data/lib/flickr_mocks/models/photos.rb +133 -0
- data/lib/flickr_mocks/stubs.rb +103 -0
- data/lib/flickr_mocks/version.rb +4 -0
- data/lib/flickrmocks.rb +27 -0
- data/spec/api/api_spec.rb +84 -0
- data/spec/api/flickr_spec.rb +48 -0
- data/spec/api/helper_spec.rb +37 -0
- data/spec/api/options_spec.rb +152 -0
- data/spec/api/sanitize_spec.rb +90 -0
- data/spec/base/fixtures_spec.rb +89 -0
- data/spec/base/flickraw/custom_clone_spec.rb +70 -0
- data/spec/base/flickraw/custom_compare_spec.rb +98 -0
- data/spec/base/flickraw/custom_marshal_spec.rb +45 -0
- data/spec/base/helpers_spec.rb +63 -0
- data/spec/base/stubs_spec.rb +180 -0
- data/spec/base/version_spec.rb +15 -0
- data/spec/fixtures/author_photos.marshal +0 -0
- data/spec/fixtures/empty_photos.marshal +0 -0
- data/spec/fixtures/expected_methods.marshal +17 -0
- data/spec/fixtures/interesting_photos.marshal +0 -0
- data/spec/fixtures/photo.marshal +0 -0
- data/spec/fixtures/photo_details.marshal +0 -0
- data/spec/fixtures/photo_size.marshal +0 -0
- data/spec/fixtures/photo_sizes.marshal +0 -0
- data/spec/fixtures/photos.marshal +0 -0
- data/spec/models/helpers_spec.rb +25 -0
- data/spec/models/photo_details_spec.rb +224 -0
- data/spec/models/photo_dimensions_spec.rb +208 -0
- data/spec/models/photo_search_spec.rb +255 -0
- data/spec/models/photo_size_spec.rb +122 -0
- data/spec/models/photo_sizes_spec.rb +168 -0
- data/spec/models/photo_spec.rb +278 -0
- data/spec/models/photos_spec.rb +305 -0
- data/spec/shared_examples/array_accessor.rb +157 -0
- data/spec/shared_examples/collection.rb +49 -0
- data/spec/shared_examples/image_url_helpers.rb +56 -0
- data/spec/shared_examples/size_accessor.rb +13 -0
- data/spec/spec_helper.rb +24 -0
- data/tasks/fixtures.rb +164 -0
- metadata +259 -0
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe APP::PhotoSize do
|
4
|
+
let(:klass){APP::PhotoSize}
|
5
|
+
let(:fixtures){ APP::Fixtures.new}
|
6
|
+
let(:size_fixture){fixtures.photo_size}
|
7
|
+
|
8
|
+
subject {klass.new size_fixture}
|
9
|
+
|
10
|
+
context "#initialize" do
|
11
|
+
context "size fixture" do
|
12
|
+
it "returns object of proper class" do
|
13
|
+
subject.should be_a(APP::PhotoSize)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
context "FlickRaw::ResponseList object" do
|
17
|
+
it "raises error" do
|
18
|
+
expect {
|
19
|
+
klass.new(fixtures.photos)
|
20
|
+
}.to raise_error(ArgumentError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
context "unexpected object" do
|
24
|
+
it "raises error when array object provided" do
|
25
|
+
expect{
|
26
|
+
klass.new([])
|
27
|
+
}.to raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
it "raises error when Hash object provided" do
|
30
|
+
expect{
|
31
|
+
klass.new({})
|
32
|
+
}.to raise_error(ArgumentError)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "instance methods" do
|
38
|
+
specify {subject.should respond_to(:size)}
|
39
|
+
describe "#size" do
|
40
|
+
it "should return proper size" do
|
41
|
+
subject.size.should == size_fixture.label.downcase.sub('_',' ').to_s
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
specify {subject.should respond_to(:id)}
|
46
|
+
describe "#id" do
|
47
|
+
it "should return proper :id" do
|
48
|
+
subject.id.should == size_fixture.source.split('/')[-1].split('_')[0]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
specify {subject.should respond_to(:secret)}
|
53
|
+
describe "#secret" do
|
54
|
+
it "should return :secret" do
|
55
|
+
subject.secret.should == size_fixture.source.split('/')[-1].split('_')[1]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
specify{subject.should respond_to(:==)}
|
61
|
+
context "#==" do
|
62
|
+
it "returns true when object is compared to clone of itself" do
|
63
|
+
subject.should == subject.clone
|
64
|
+
end
|
65
|
+
it "returns true when object is compared to an array" do
|
66
|
+
subject.should_not == [1,2,3,4]
|
67
|
+
end
|
68
|
+
it "returns false when compared to object that is different in one attribute" do
|
69
|
+
subject.delegated_instance_methods do |method|
|
70
|
+
value = case subject.send(method)
|
71
|
+
when String then Faker::Lorem.sentence(3)
|
72
|
+
when FixNum then Random.rand
|
73
|
+
else Random.rand
|
74
|
+
end
|
75
|
+
other = subject.clone
|
76
|
+
other.stub(method).returns(value)
|
77
|
+
subject.should_not == other
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "metaprogramming methods" do
|
84
|
+
|
85
|
+
context "#delegated_instance_methods" do
|
86
|
+
it "should delegate to FlickRaw::Response" do
|
87
|
+
subject.delegated_instance_methods.sort.should == fixtures.expected_methods.photo_size.sort
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "#respond_to?" do
|
92
|
+
it "returns true when given on of delegated_instance methods" do
|
93
|
+
subject.delegated_instance_methods.each do |method|
|
94
|
+
subject.should respond_to(method)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
it "returns true when given expected methods" do
|
98
|
+
subject.methods do |method|
|
99
|
+
subject.should respond_to(method)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "#methods" do
|
105
|
+
it "returns list that includes the methods that are delegated" do
|
106
|
+
expected_methods = subject.old_methods + fixtures.expected_methods.photo_size
|
107
|
+
(subject.methods - expected_methods).should be_empty
|
108
|
+
subject.methods.length.should == expected_methods.length
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "custom cloning methods" do
|
115
|
+
context "#initialize_copy" do
|
116
|
+
it "returns photo object that have distinct __id__ as compared with original" do
|
117
|
+
other = subject.clone
|
118
|
+
subject.instance_eval('@delegated_to_object.__id__').should_not == other.instance_eval('@delegated_to_object.__id__')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe APP::PhotoSizes do
|
4
|
+
let(:klass){APP::PhotoSizes}
|
5
|
+
let(:fixtures){APP::Fixtures.new}
|
6
|
+
|
7
|
+
subject {APP::PhotoSizes.new fixtures.photo_sizes}
|
8
|
+
|
9
|
+
context "initialize" do
|
10
|
+
context "with FlickRaw::ResponseList" do
|
11
|
+
it "returns object of proper class" do
|
12
|
+
klass.new(fixtures.photo_sizes).should be_a(APP::PhotoSizes)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
context "with FlickRaw::Response" do
|
16
|
+
it "raises an error" do
|
17
|
+
expect {
|
18
|
+
klass.new(fixtures.photo)
|
19
|
+
}.to raise_error(ArgumentError)
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
context "with an Array object" do
|
24
|
+
it "raises an error" do
|
25
|
+
expect {
|
26
|
+
klass.new([])
|
27
|
+
}.to raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
context "with a nil object" do
|
31
|
+
it "raises an error" do
|
32
|
+
expect {
|
33
|
+
klass.new(nil)
|
34
|
+
}.to raise_error(ArgumentError)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "instance methods" do
|
40
|
+
specify {subject.should respond_to(:id)}
|
41
|
+
context "#id" do
|
42
|
+
it "returns id for expected photo" do
|
43
|
+
subject.id.should == fixtures.photo_size.source.split('/')[-1].split('_')[0]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
specify {subject.should respond_to(:secret)}
|
48
|
+
context "#secret" do
|
49
|
+
it "returns secret for correct photo" do
|
50
|
+
subject.secret.should == fixtures.photo_size.source.split('/')[-1].split('_')[1]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
specify {subject.should respond_to(:sizes)}
|
55
|
+
context "#sizes" do
|
56
|
+
it "returns array of PhotoSize objects" do
|
57
|
+
subject.sizes.should == subject.map do |size| size end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
specify {subject.should respond_to(:available_sizes)}
|
62
|
+
context "#available_sizes" do
|
63
|
+
it "returns array of sizes availalbe" do
|
64
|
+
subject.available_sizes.should == subject.sizes.map do |size|
|
65
|
+
size.size.to_sym
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
specify {subject.should respond_to(:possible_sizes)}
|
71
|
+
context "possible_sizes" do
|
72
|
+
it "returns list of sizes that are possible for an image" do
|
73
|
+
subject.possible_sizes == FlickrMocks::Models::Helpers.possible_sizes
|
74
|
+
end
|
75
|
+
end
|
76
|
+
specify {subject.should respond_to(:to_s)}
|
77
|
+
context "#to_s" do
|
78
|
+
it "should return expected string" do
|
79
|
+
expected = subject.map do |size| "#{size.label.downcase.sub(' ','_')}:#{size.width}x#{size.height}" end.join(',')
|
80
|
+
subject.to_s.should == expected
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
specify {subject.should respond_to(:==)}
|
85
|
+
describe "#==" do
|
86
|
+
it "returns true when object is compared to itself" do
|
87
|
+
subject.should == subject
|
88
|
+
end
|
89
|
+
it "returns true when object is compared to clone of itself" do
|
90
|
+
subject.should == subject.clone
|
91
|
+
end
|
92
|
+
it "returns false when object is compared to Fixnum" do
|
93
|
+
subject.should_not == 2
|
94
|
+
end
|
95
|
+
it "returns false when object is compared to Array" do
|
96
|
+
subject.should_not == []
|
97
|
+
end
|
98
|
+
it "returns false when object compared to object with only a single difference" do
|
99
|
+
other = subject.clone
|
100
|
+
other[0].instance_eval('@delegated_to_object').instance_eval('@h["label"] = "random size"')
|
101
|
+
subject.should_not == other
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "#collection" do
|
106
|
+
|
107
|
+
specify { subject.should respond_to(:collection)}
|
108
|
+
context "#collection" do
|
109
|
+
let(:reference){
|
110
|
+
OpenStruct.new :current_page => 1,
|
111
|
+
:per_page => subject.available_sizes.length,
|
112
|
+
:total_entries => subject.available_sizes.length,
|
113
|
+
:collection => subject.sizes
|
114
|
+
}
|
115
|
+
it_behaves_like "object that responds to collection"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "metaprogramming methods" do
|
121
|
+
|
122
|
+
specify{subject.should respond_to(:delegated_instance_methods)}
|
123
|
+
context "#delegated_instance_methods" do
|
124
|
+
it "returns array accessor methods + size methods" do
|
125
|
+
subject.delegated_instance_methods.sort.should == (subject.possible_sizes +
|
126
|
+
APP::Models::Helpers.array_accessor_methods).sort
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
specify{subject.should respond_to(:methods)}
|
131
|
+
context "#methods" do
|
132
|
+
it "returns all methods including those that are delegated" do
|
133
|
+
subject.methods.sort.should == ( subject.delegated_instance_methods +
|
134
|
+
subject.old_methods).sort
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
specify{ subject.should respond_to(:respond_to?)}
|
139
|
+
context "#respond_to?" do
|
140
|
+
it "recognizes all methods returned by #methods" do
|
141
|
+
subject.methods.each do |method|
|
142
|
+
subject.should respond_to(method)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "iteratable methods" do
|
148
|
+
let(:reference) {subject.sizes}
|
149
|
+
it_behaves_like "object with delegated Array accessor helpers"
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
context "custom cloning methods" do
|
155
|
+
context "initialize_copy" do
|
156
|
+
it "returns clone with distinct id from original object" do
|
157
|
+
other = subject.clone
|
158
|
+
subject.each_index do |index|
|
159
|
+
subject[index].__id__.should_not == other[index].__id__
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
|
@@ -0,0 +1,278 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe APP::Photo do
|
4
|
+
let(:klass){APP::Photo}
|
5
|
+
let(:fixtures){APP::Fixtures.new}
|
6
|
+
let(:basic_photo){klass.new fixtures.photo}
|
7
|
+
let(:extended_photo){klass.new fixtures.photo_details}
|
8
|
+
|
9
|
+
subject {basic_photo}
|
10
|
+
|
11
|
+
context "initialize" do
|
12
|
+
context "with extended photo" do
|
13
|
+
it "returns object of proper class" do
|
14
|
+
klass.new(fixtures.photo_details).should be_a(APP::Photo)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with basic photo" do
|
19
|
+
subject {klass.new fixtures.photo}
|
20
|
+
it "returns object of proper class" do
|
21
|
+
klass.new(fixtures.photo).should be_a(APP::Photo)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
context "with nil" do
|
25
|
+
it "raises error" do
|
26
|
+
expect { klass.new nil}.to raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
context "with FlickRaw::ResponseList class" do
|
30
|
+
it "raises error" do
|
31
|
+
expect { klass.new fixtures.photos}.to raise_error(ArgumentError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
context "with an Array class" do
|
35
|
+
it "raises error" do
|
36
|
+
expect { klass.new []}.to raise_error(ArgumentError)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "instance methods" do
|
42
|
+
specify {subject.should respond_to(:photo_id)}
|
43
|
+
context "#photo_id" do
|
44
|
+
it "returns correct photo_id" do
|
45
|
+
subject.photo_id.should == subject.id
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
specify {subject.should respond_to(:usable?)}
|
50
|
+
context "#usable?" do
|
51
|
+
context "licenses that DO NOT reserve ALL copyright" do
|
52
|
+
it "returns false when license is '0'" do
|
53
|
+
subject.stub(:license).and_return("0")
|
54
|
+
subject.should_not be_usable
|
55
|
+
end
|
56
|
+
end
|
57
|
+
context "licenses that DO NOT allow for commercial usage" do
|
58
|
+
it "returns false when license is '1'" do
|
59
|
+
subject.stub(:license).and_return("1")
|
60
|
+
subject.should_not be_usable
|
61
|
+
end
|
62
|
+
it "returns false when license is '2'" do
|
63
|
+
subject.stub(:license).and_return("2")
|
64
|
+
subject.should_not be_usable
|
65
|
+
end
|
66
|
+
it "returns false when license is '3'" do
|
67
|
+
subject.stub(:license).and_return("3")
|
68
|
+
subject.should_not be_usable
|
69
|
+
end
|
70
|
+
end
|
71
|
+
context "licenses that allow for commercial usage" do
|
72
|
+
it "returns false when license is '4'" do
|
73
|
+
subject.stub(:license).and_return('4')
|
74
|
+
subject.should be_usable
|
75
|
+
end
|
76
|
+
it "returns false when license is '5'" do
|
77
|
+
subject.stub(:license).and_return('5')
|
78
|
+
subject.should be_usable
|
79
|
+
end
|
80
|
+
it "returns false when license is '6'" do
|
81
|
+
subject.stub(:license).and_return('6')
|
82
|
+
subject.should be_usable
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "url image helpers" do
|
88
|
+
context "basic photo" do
|
89
|
+
subject {basic_photo}
|
90
|
+
it_behaves_like "object with flickr image url helpers"
|
91
|
+
end
|
92
|
+
|
93
|
+
context "extended photo" do
|
94
|
+
subject {extended_photo}
|
95
|
+
it_behaves_like "object with flickr image url helpers"
|
96
|
+
end
|
97
|
+
|
98
|
+
context "#original" do
|
99
|
+
context "basic photo" do
|
100
|
+
subject {basic_photo}
|
101
|
+
specify {subject.should respond_to(:original)}
|
102
|
+
it "returns nil for basic photo" do
|
103
|
+
subject.original.should be_nil
|
104
|
+
end
|
105
|
+
end
|
106
|
+
context "extended photo" do
|
107
|
+
subject {extended_photo}
|
108
|
+
specify {subject.should respond_to(:original)}
|
109
|
+
it "returns expected url for detail photo" do
|
110
|
+
subject.original.should == subject.square.sub('_%s_s.' % subject.secret, '_%s_o.' % subject.originalsecret)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
specify {subject.should respond_to(:owner_url)}
|
117
|
+
context "#owner_url" do
|
118
|
+
it "returns expected url link for owner of image" do
|
119
|
+
subject.owner_url.should == "http://www.flickr.com/photos/#{fixtures.photo['owner']}/#{fixtures.photo['id']}"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
specify {subject.should respond_to(:owner_id)}
|
124
|
+
context "#owner_id" do
|
125
|
+
it "returns expected value id for owner of image" do
|
126
|
+
subject.owner_id.should == fixtures.photo['owner']
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
specify {subject.should respond_to(:owner)}
|
132
|
+
context "#owner" do
|
133
|
+
it "returns expected name for owner of image" do
|
134
|
+
subject.owner.should == fixtures.photo['owner']
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
specify{subject.should respond_to(:==)}
|
139
|
+
context "#==" do
|
140
|
+
subject {basic_photo}
|
141
|
+
context "basic photo" do
|
142
|
+
it "returns true when object is compared to itself" do
|
143
|
+
subject.should == subject
|
144
|
+
end
|
145
|
+
it "returns true when object is compared to clone of itself" do
|
146
|
+
subject.should == subject.clone
|
147
|
+
end
|
148
|
+
|
149
|
+
it "returns true when object is compared to an object of another class" do
|
150
|
+
subject.should_not == [1,2,3,4]
|
151
|
+
end
|
152
|
+
it "returns true when object is compared to another object with slight difference" do
|
153
|
+
subject.delegated_instance_methods.find_all do |value| value != :flickr_type end.each do |method|
|
154
|
+
other = subject.clone
|
155
|
+
value = case subject.send(method)
|
156
|
+
when String then Faker::Lorem.sentence(3)
|
157
|
+
when Fixnum then next
|
158
|
+
else Random.rand
|
159
|
+
end
|
160
|
+
other.instance_eval('@delegated_to_object').instance_eval('@h[method.to_s]=value')
|
161
|
+
subject.should_not == other
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "detailed photo" do
|
167
|
+
subject {extended_photo}
|
168
|
+
|
169
|
+
it "returns true when object is compared to itself" do
|
170
|
+
subject.should == subject
|
171
|
+
end
|
172
|
+
it "returns true when object is compared to clone of itself" do
|
173
|
+
subject.should == subject.clone
|
174
|
+
end
|
175
|
+
it "returns true when object is compared to an object of another class" do
|
176
|
+
other = subject.clone
|
177
|
+
other.instance_eval('@delegated_to_object').instance_eval('@h["dates"]').instance_eval('@h["taken"]="boobooje"')
|
178
|
+
subject.should_not == other
|
179
|
+
end
|
180
|
+
|
181
|
+
it "returns true when object is compared to another object with slight difference" do
|
182
|
+
subject.delegated_instance_methods.find_all do |value| value != :flickr_type end.each do |method|
|
183
|
+
other = subject.clone
|
184
|
+
value = case subject.send(method)
|
185
|
+
when String then Faker::Lorem.sentence(3)
|
186
|
+
when Fixnum then next
|
187
|
+
else Random.rand
|
188
|
+
end
|
189
|
+
other.instance_eval('@delegated_to_object').instance_eval('@h[method.to_s]=value')
|
190
|
+
subject.should_not == other
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
context "metaprogramming methods" do
|
200
|
+
context "#delegated_instance_methods" do
|
201
|
+
context "basic photo" do
|
202
|
+
subject {basic_photo}
|
203
|
+
it "returns methods for basic photos" do
|
204
|
+
subject.delegated_instance_methods.sort.should == fixtures.expected_methods.photo.sort
|
205
|
+
end
|
206
|
+
end
|
207
|
+
context "detailed photo" do
|
208
|
+
subject {extended_photo}
|
209
|
+
it "returns methods for extended photos" do
|
210
|
+
subject.delegated_instance_methods.sort.should == fixtures.expected_methods.photo_details.sort
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
215
|
+
|
216
|
+
context "#respond_to?" do
|
217
|
+
context "basic photo" do
|
218
|
+
subject {basic_photo}
|
219
|
+
it "responds to methods that are delegated to basic photo object" do
|
220
|
+
fixtures.expected_methods.photo.each do |method|
|
221
|
+
subject.should respond_to(method)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
it "responds to all methods returned by #methods" do
|
225
|
+
subject.methods.each do |method|
|
226
|
+
subject.should respond_to(method)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context "detailed photo" do
|
232
|
+
subject {extended_photo}
|
233
|
+
it "responds to methods that are delegated to detailed photo object" do
|
234
|
+
fixtures.photo_details.methods(false).push(:flickr_type).each do |method|
|
235
|
+
subject.should respond_to(method)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
it "responds to all methods returned by #methods" do
|
239
|
+
subject.methods.each do |method|
|
240
|
+
subject.should respond_to(method)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
context "#methods" do
|
247
|
+
context "basic photo" do
|
248
|
+
subject {basic_photo}
|
249
|
+
|
250
|
+
specify {subject.should respond_to(:methods)}
|
251
|
+
it "returns expected methods including delegated methods for basic photo fixture" do
|
252
|
+
expected_methods = fixtures.expected_methods.photo + subject.old_methods
|
253
|
+
(subject.methods - expected_methods).should be_empty
|
254
|
+
subject.methods.length.should == expected_methods.length
|
255
|
+
end
|
256
|
+
end
|
257
|
+
context "detailed photo" do
|
258
|
+
subject {extended_photo}
|
259
|
+
specify {subject.should respond_to(:methods)}
|
260
|
+
it "returns expected methods including delegated methods to photo details fixture" do
|
261
|
+
expected_methods = fixtures.expected_methods.photo_details + subject.old_methods
|
262
|
+
(subject.methods - expected_methods).should be_empty
|
263
|
+
subject.methods.length.should == expected_methods.length
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
end
|
269
|
+
|
270
|
+
context "custom cloning methods" do
|
271
|
+
context "#initialize_copy" do
|
272
|
+
it "returns photo objects that have distinct @delegated_to_object ids from cloned object" do
|
273
|
+
other = subject.clone
|
274
|
+
subject.instance_eval("@delegated_to_object.__id__").should_not == other.instance_eval("@delegated_to_object.__id__")
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|