flickrmocks 0.8.6 → 0.8.8

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/Rakefile CHANGED
@@ -22,7 +22,6 @@ begin
22
22
  gem.homepage = "http://github.com/takaltoo/flickrmocks"
23
23
  gem.authors = ["Takaltoo"]
24
24
 
25
- gem.add_development_dependency "thoughtbot-shoulda", ">= 2.10"
26
25
  gem.add_development_dependency "rspec", ">=2.0.0.beta.22"
27
26
  gem.add_development_dependency "capybara"
28
27
  #gem.add_development_dependency 'ruby-debug19', :require => 'ruby-debug'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.6
1
+ 0.8.8
data/flickrmocks.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{flickrmocks}
8
- s.version = "0.8.6"
8
+ s.version = "0.8.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Takaltoo"]
12
- s.date = %q{2010-11-09}
12
+ s.date = %q{2010-11-18}
13
13
  s.description = %q{FlickrMocks makes it possible to Marshal responses
14
14
  generated from the FLickRaw gem. This is useful for
15
15
  Mocking/Stubbing the Flickr interface for testing purposes.
@@ -41,6 +41,8 @@ Gem::Specification.new do |s|
41
41
  "lib/flickr_mocks/flickraw/custom_marshal.rb",
42
42
  "lib/flickr_mocks/flickraw/flickraw.rb",
43
43
  "lib/flickr_mocks/helpers.rb",
44
+ "lib/flickr_mocks/models/commons_institution.rb",
45
+ "lib/flickr_mocks/models/commons_institutions.rb",
44
46
  "lib/flickr_mocks/models/helpers.rb",
45
47
  "lib/flickr_mocks/models/photo.rb",
46
48
  "lib/flickr_mocks/models/photo_details.rb",
@@ -65,6 +67,7 @@ Gem::Specification.new do |s|
65
67
  "spec/base/stubs_spec.rb",
66
68
  "spec/base/version_spec.rb",
67
69
  "spec/fixtures/author_photos.marshal",
70
+ "spec/fixtures/commons_institutions.marshal",
68
71
  "spec/fixtures/empty_photos.marshal",
69
72
  "spec/fixtures/expected_methods.marshal",
70
73
  "spec/fixtures/interesting_photos.marshal",
@@ -73,6 +76,8 @@ Gem::Specification.new do |s|
73
76
  "spec/fixtures/photo_size.marshal",
74
77
  "spec/fixtures/photo_sizes.marshal",
75
78
  "spec/fixtures/photos.marshal",
79
+ "spec/models/commons_institution_spec.rb",
80
+ "spec/models/commons_institutions_spec.rb",
76
81
  "spec/models/helpers_spec.rb",
77
82
  "spec/models/photo_details_spec.rb",
78
83
  "spec/models/photo_dimensions_spec.rb",
@@ -101,7 +106,9 @@ Gem::Specification.new do |s|
101
106
  "spec/models/helpers_spec.rb",
102
107
  "spec/models/photo_details_spec.rb",
103
108
  "spec/models/photo_size_spec.rb",
109
+ "spec/models/commons_institution_spec.rb",
104
110
  "spec/models/photo_sizes_spec.rb",
111
+ "spec/models/commons_institutions_spec.rb",
105
112
  "spec/models/photos_spec.rb",
106
113
  "spec/models/photo_dimensions_spec.rb",
107
114
  "spec/models/photo_spec.rb",
@@ -126,7 +133,6 @@ Gem::Specification.new do |s|
126
133
  s.specification_version = 3
127
134
 
128
135
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
129
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 2.10"])
130
136
  s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.22"])
131
137
  s.add_development_dependency(%q<capybara>, [">= 0"])
132
138
  s.add_development_dependency(%q<factory_girl_rails>, [">= 1.0"])
@@ -134,7 +140,6 @@ Gem::Specification.new do |s|
134
140
  s.add_runtime_dependency(%q<flickraw>, [">= 0.8.2"])
135
141
  s.add_runtime_dependency(%q<chronic>, [">= 0"])
136
142
  else
137
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 2.10"])
138
143
  s.add_dependency(%q<rspec>, [">= 2.0.0.beta.22"])
139
144
  s.add_dependency(%q<capybara>, [">= 0"])
140
145
  s.add_dependency(%q<factory_girl_rails>, [">= 1.0"])
@@ -143,7 +148,6 @@ Gem::Specification.new do |s|
143
148
  s.add_dependency(%q<chronic>, [">= 0"])
144
149
  end
145
150
  else
146
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 2.10"])
147
151
  s.add_dependency(%q<rspec>, [">= 2.0.0.beta.22"])
148
152
  s.add_dependency(%q<capybara>, [">= 0"])
149
153
  s.add_dependency(%q<factory_girl_rails>, [">= 1.0"])
@@ -38,5 +38,10 @@ module FlickrMocks
38
38
  PhotoSearch.new photos,Api.interesting_params(params)
39
39
  end
40
40
 
41
+ def self.commons_institutions(params)
42
+ institutions = Api.flickr_commons_institutions
43
+ CommonsInstitutions.new institutions,Api.commons_institutions_params(params)
44
+ end
45
+
41
46
  end
42
47
  end
@@ -21,6 +21,10 @@ module FlickrMocks
21
21
  def self.flickr_author(params)
22
22
  flickr.photos.search self.author_options(params)
23
23
  end
24
+
25
+ def self.flickr_commons_institutions
26
+ flickr.commons.getInstitutions
27
+ end
24
28
  end
25
29
  end
26
30
 
@@ -49,6 +49,13 @@ module FlickrMocks
49
49
  :base_url => params[:base_url]
50
50
  }
51
51
  end
52
+
53
+ def self.commons_institutions_params(params)
54
+ return {
55
+ :per_page => params[:per_page] || params[:perpage],
56
+ :current_page => params[:current_page] || 1
57
+ }
58
+ end
52
59
  end
53
60
 
54
61
 
@@ -3,7 +3,7 @@ require 'ostruct'
3
3
  module FlickrMocks
4
4
  class Fixtures
5
5
  attr_accessor :photos,:interesting_photos,:author_photos,:photo,:photo_details,
6
- :photo_sizes,:photo_size,:expected_methods,:empty_photos
6
+ :photo_sizes,:photo_size,:expected_methods,:empty_photos,:commons_institutions
7
7
 
8
8
  def initialize
9
9
  @photos = load_fixture(:photos)
@@ -15,10 +15,13 @@ module FlickrMocks
15
15
 
16
16
  @photo_sizes = load_fixture(:photo_sizes)
17
17
  @photo_size = load_fixture(:photo_size)
18
+
19
+ @commons_institutions = load_fixture(:commons_institutions)
18
20
 
19
21
  @empty_photos = load_fixture(:empty_photos)
20
22
 
21
23
  @expected_methods = load_fixture(:expected_methods)
24
+
22
25
  end
23
26
 
24
27
  def self.repository
@@ -0,0 +1,56 @@
1
+
2
+ module FlickrMocks
3
+ class CommonsInstitution
4
+ def initialize(object)
5
+ self.delegated_to_object = object
6
+ end
7
+
8
+ def launch_date
9
+ @delegated_to_object.date_launch
10
+ end
11
+
12
+ def owner_id
13
+ @delegated_to_object.nsid
14
+ end
15
+ alias :owner :owner_id
16
+
17
+ def owner_name
18
+ @delegated_to_object.name
19
+ end
20
+
21
+ def flickr_url
22
+ get_url(:flickr)
23
+ end
24
+
25
+ def site_url
26
+ get_url(:site)
27
+ end
28
+
29
+ def license_url
30
+ get_url(:license)
31
+ end
32
+
33
+ def ==(other)
34
+ @delegated_to_object == other.instance_eval('@delegated_to_object')
35
+ end
36
+
37
+ def initialize_copy(orig)
38
+ super
39
+ @delegated_to_object = @delegated_to_object.clone
40
+ end
41
+
42
+ private
43
+ def delegated_to_object=(object)
44
+ raise ArgumentError, "Expected object of class FlickRaw::Response but received #{object.class}" unless object.class == FlickRaw::Response
45
+ @delegated_to_object = object
46
+ end
47
+
48
+ def get_url(type)
49
+ @delegated_to_object.urls[get_url_index(type)]['_content']
50
+ end
51
+
52
+ def get_url_index(type)
53
+ @delegated_to_object.urls.map do |url| url['type'].to_sym end.find_index(type.to_sym)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,93 @@
1
+
2
+ module FlickrMocks
3
+ class CommonsInstitutions
4
+ attr_accessor :per_page,:current_page
5
+
6
+ @defaults = FlickrMocks::Models::Helpers.paging_defaults.clone
7
+
8
+ class << self
9
+ attr_accessor :defaults
10
+ end
11
+
12
+ def initialize(institutions,options={})
13
+ self.delegated_to_object = institutions
14
+ self.per_page = options[:per_page]
15
+ self.current_page = options[:current_page]
16
+ end
17
+
18
+ def default(value)
19
+ CommonsInstitutions.defaults[value.to_s.to_sym]
20
+ end
21
+
22
+ def ==(other)
23
+ per_page == other.per_page and
24
+ current_page == other.current_page and
25
+ @delegated_to_object == other.instance_eval('@delegated_to_object')
26
+ end
27
+
28
+ def initialize_copy(orig)
29
+ super
30
+ @delegated_to_object = @delegated_to_object.clone
31
+ end
32
+
33
+ def delegated_instance_methods
34
+ FlickrMocks::Models::Helpers.array_accessor_methods
35
+ end
36
+
37
+ def method_missing(id,*args,&block)
38
+ return @delegated_to_object.send(id,*args,&block) if delegated_instance_methods.include?(id)
39
+ super
40
+ end
41
+
42
+ alias :old_respond_to? :respond_to?
43
+ def respond_to?(method,type=false)
44
+ return true if delegated_instance_methods.include?(method)
45
+ old_respond_to?(method,type)
46
+ end
47
+
48
+ alias :old_methods :methods
49
+ def methods
50
+ delegated_instance_methods + old_methods
51
+ end
52
+
53
+ # custom cloning methods
54
+ def initialize_copy(orig)
55
+ super
56
+ @delegated_to_object = @delegated_to_object.map do |institution|
57
+ institution.clone
58
+ end
59
+ end
60
+
61
+ def total_entries
62
+ @delegated_to_object.size
63
+ end
64
+
65
+ def institutions
66
+ @delegated_to_object
67
+ end
68
+
69
+ def collection
70
+ ::WillPaginate::Collection.create(current_page, per_page, total_entries) do |obj|
71
+ obj.replace(institutions)
72
+ end
73
+ end
74
+
75
+ private
76
+ def delegated_to_object=(object)
77
+ raise ArgumentError, "FlickRaw::ResponseList expected" unless object.class == FlickRaw::ResponseList
78
+ @delegated_to_object = object.institution
79
+ end
80
+
81
+ def per_page=(value)
82
+ @per_page = value.to_i == 0 ? default(:per_page) : value.to_i
83
+ end
84
+
85
+ def current_page=(value)
86
+ page = value.to_i < 1 ? 1 : value.to_i
87
+
88
+ max_page = total_entries / @per_page
89
+ page = page > max_page ? max_page : page
90
+ @current_page = page
91
+ end
92
+ end
93
+ end
@@ -1,11 +1,21 @@
1
1
  module FlickrMocks
2
2
  module Models
3
3
  module Helpers
4
+
4
5
  def self.array_accessor_methods
5
6
  [:[], :first, :last,:empty?,:length,:size,:each,:each_index,
6
- :map, :select, :keep_if,:at,:fetch, :reverse_each,
7
+ :each_with_index,:map, :select, :keep_if,:at,:fetch, :reverse_each,
7
8
  :find_index, :index,:rindex, :collect,:values_at]
8
9
  end
10
+
11
+ def self.paging_defaults
12
+ {
13
+ :max_entries => 4000,
14
+ :per_page => 50,
15
+ :current_page => 1
16
+ }
17
+ end
18
+
9
19
  def self.possible_sizes
10
20
  [:square, :thumbnail, :small, :medium, :medium_640, :large, :original]
11
21
  end
@@ -3,10 +3,7 @@ module FlickrMocks
3
3
  attr_reader :current_page,:per_page,:total_entries,:total_pages,:photos
4
4
  alias :perpage :per_page
5
5
 
6
- @defaults = {
7
- :max_entries => 4000,
8
- :per_page => 50
9
- }
6
+ @defaults = FlickrMocks::Models::Helpers.paging_defaults.clone
10
7
 
11
8
 
12
9
  class << self
@@ -2,7 +2,7 @@ module FlickrMocks
2
2
  module Stubs
3
3
 
4
4
  def self.stub_flickr
5
- [:stub_search,:stub_getInfo,:stub_getSizes,:stub_interestingness].each do |method|
5
+ [:stub_search,:stub_getInfo,:stub_getSizes,:stub_interestingness,:stub_commons_institutions].each do |method|
6
6
  self.send(method)
7
7
  end
8
8
  end
@@ -90,6 +90,14 @@ module FlickrMocks
90
90
  }.call
91
91
  end
92
92
 
93
+ def self.stub_commons_institutions
94
+ Proc.new {
95
+ flickr.commons.stub(:getInstitutions) do
96
+ Fixtures.new.commons_institutions
97
+ end
98
+ }.call
99
+ end
100
+
93
101
  end
94
102
  end
95
103
 
data/lib/flickrmocks.rb CHANGED
@@ -26,28 +26,31 @@ end
26
26
  # end
27
27
  # end
28
28
 
29
- require 'flickr_mocks/version.rb'
30
- require 'flickr_mocks/stubs.rb'
31
- require 'flickr_mocks/helpers.rb'
32
- require 'flickr_mocks/fixtures.rb'
33
-
34
- require 'flickr_mocks/models/helpers.rb'
35
- require 'flickr_mocks/models/photo_sizes.rb'
36
- require 'flickr_mocks/models/photo_dimensions.rb'
37
- require 'flickr_mocks/models/photo_size.rb'
38
- require 'flickr_mocks/models/photos.rb'
39
- require 'flickr_mocks/models/photo.rb'
40
- require 'flickr_mocks/models/photo_search.rb'
41
- require 'flickr_mocks/models/photo_details.rb'
42
-
43
- require 'flickr_mocks/api/helpers.rb'
44
- require 'flickr_mocks/api/options.rb'
45
- require 'flickr_mocks/api/flickr.rb'
46
- require 'flickr_mocks/api/sanitize.rb'
47
- require 'flickr_mocks/api/api.rb'
48
-
49
- require 'flickr_mocks/flickraw/custom_clone.rb'
50
- require 'flickr_mocks/flickraw/custom_compare.rb'
51
- require 'flickr_mocks/flickraw/custom_marshal.rb'
52
- require 'flickr_mocks/flickraw/flickraw.rb'
29
+ [
30
+ 'flickr_mocks/version.rb',
31
+ 'flickr_mocks/stubs.rb',
32
+ 'flickr_mocks/helpers.rb',
33
+ 'flickr_mocks/fixtures.rb',
34
+ 'flickr_mocks/models/helpers.rb',
35
+ 'flickr_mocks/models/photo_sizes.rb',
36
+ 'flickr_mocks/models/photo_dimensions.rb',
37
+ 'flickr_mocks/models/photo_size.rb',
38
+ 'flickr_mocks/models/photos.rb',
39
+ 'flickr_mocks/models/photo.rb',
40
+ 'flickr_mocks/models/photo_search.rb',
41
+ 'flickr_mocks/models/photo_details.rb',
42
+ 'flickr_mocks/models/commons_institutions.rb',
43
+ 'flickr_mocks/models/commons_institution.rb',
44
+ 'flickr_mocks/api/helpers.rb',
45
+ 'flickr_mocks/api/options.rb',
46
+ 'flickr_mocks/api/flickr.rb',
47
+ 'flickr_mocks/api/sanitize.rb',
48
+ 'flickr_mocks/api/api.rb',
49
+ 'flickr_mocks/flickraw/custom_clone.rb',
50
+ 'flickr_mocks/flickraw/custom_compare.rb',
51
+ 'flickr_mocks/flickraw/custom_marshal.rb',
52
+ 'flickr_mocks/flickraw/flickraw.rb'
53
+ ].each do |file|
54
+ require File.expand_path(File.dirname(__FILE__)) + '/' + file
55
+ end
53
56
 
data/spec/api/api_spec.rb CHANGED
@@ -9,6 +9,7 @@ describe APP::Api do
9
9
  let(:sizes) {fixtures.photo_sizes}
10
10
  let(:photo_details) {fixtures.photo_details}
11
11
  let(:interesting_photos) {fixtures.interesting_photos}
12
+ let(:commons_institutions) {fixtures.commons_institutions}
12
13
 
13
14
 
14
15
  context "class instance variables" do
@@ -80,5 +81,14 @@ describe APP::Api do
80
81
  end
81
82
  end
82
83
 
84
+ specify {klass.should respond_to(:commons_institutions)}
85
+ describe "commons_institutions" do
86
+ it "returns expected CommonsInstitutions object" do
87
+ flickr.commons.stub(:getInstitutions).and_return(commons_institutions)
88
+ klass.commons_institutions({}).should ==
89
+ APP::CommonsInstitutions.new(commons_institutions)
90
+ end
91
+ end
92
+
83
93
  end
84
94
  end
@@ -44,5 +44,11 @@ describe APP::Api do
44
44
  klass.flickr_author({}).should == fixtures.author_photos
45
45
  end
46
46
  end
47
+
48
+ specify {klass.should respond_to(:flickr_commons_institutions)}
49
+ it "retuns list of commons institutions" do
50
+ flickr.commons.stub(:getInstitutions).and_return(fixtures.commons_institutions)
51
+ klass.flickr_commons_institutions.should == fixtures.commons_institutions
52
+ end
47
53
  end
48
54
  end
@@ -24,7 +24,7 @@ describe APP::Api do
24
24
  }
25
25
 
26
26
 
27
- describe "search_options" do
27
+ context "search_options" do
28
28
  it "should give correct options when all options are specified except :author_id" do
29
29
  subject.search_options(options.clone.merge(:per_page =>'400')).should == expected
30
30
  end
@@ -60,7 +60,7 @@ describe APP::Api do
60
60
  end
61
61
  end
62
62
 
63
- describe "interesting_options" do
63
+ context "interesting_options" do
64
64
  let(:expected){
65
65
  { :date => '2010-02-14',
66
66
  :per_page => '2',
@@ -81,7 +81,7 @@ describe APP::Api do
81
81
  end
82
82
  end
83
83
 
84
- describe "photo_options" do
84
+ context "photo_options" do
85
85
  let(:expected) {
86
86
  {:photo_id => '20030', :secret => 'abcdef'}
87
87
  }
@@ -102,7 +102,7 @@ describe APP::Api do
102
102
  end
103
103
  end
104
104
 
105
- describe "search_params" do
105
+ context "search_params" do
106
106
  let(:expected){
107
107
  {
108
108
  :search_terms => 'iran,shiraz',
@@ -126,8 +126,7 @@ describe APP::Api do
126
126
  end
127
127
  end
128
128
 
129
- describe "interesting_params" do
130
-
129
+ context "interesting_params" do
131
130
  let(:expected) {
132
131
  {
133
132
  :date => 'iran,shiraz',
@@ -146,6 +145,28 @@ describe APP::Api do
146
145
  expected.clone.merge(:base_url => expected[:base_url])
147
146
  end
148
147
  end
148
+
149
+ context "institution_params" do
150
+ it "returns :per_page and :current_page if specified" do
151
+ expected = {:per_page => 2, :current_page => 3}
152
+ subject.commons_institutions_params(expected).should == expected
153
+ end
154
+ it "returns :per_page is prefereed over :perpage is specified" do
155
+ expected = {:per_page => 2, :current_page => 1}
156
+ subject.commons_institutions_params(:per_page => 3, :perpage => 20, :current_page => 1).should ==
157
+ {:per_page => 3, :current_page => 1}
158
+ end
159
+ it "returns :perpage if :per_page is not specified" do
160
+ expected = {:perpage => 3}
161
+ subject.commons_institutions_params(:perpage => 20, :current_page => 1).should ==
162
+ {:per_page => 20, :current_page => 1}
163
+ end
164
+ it "returns :current_page of 1 if not specified" do
165
+ subject.commons_institutions_params(:per_page => 20).should ==
166
+ {:per_page => 20, :current_page => 1}
167
+ end
168
+ end
169
+
149
170
 
150
171
  end
151
172
 
@@ -78,6 +78,12 @@ describe APP::Fixtures do
78
78
  let(:fixture) {:photo_sizes}
79
79
  it_behaves_like "a flickraw fixture"
80
80
  end
81
+
82
+ specify {subject.should respond_to(:commons_institutions)}
83
+ context "commons_institutions" do
84
+ let(:fixture){:commons_institutions}
85
+ it_behaves_like "a flickraw fixture"
86
+ end
81
87
  end
82
88
 
83
89
  end
@@ -23,6 +23,10 @@ describe APP::Stubs do
23
23
  it "stubs flickr.interestingness.getList" do
24
24
  flickr.interestingness.getList.should == fixtures.interesting_photos
25
25
  end
26
+
27
+ it "stubs flickr.commons.getInstitutions" do
28
+ flickr.commons.getInstitutions.should == fixtures.commons_institutions
29
+ end
26
30
  end
27
31
 
28
32
  specify {klass.should respond_to(:stub_search)}
@@ -176,5 +180,15 @@ describe APP::Stubs do
176
180
  end
177
181
  end
178
182
 
183
+ specify {klass.should respond_to(:stub_commons_institutions)}
184
+ context "stub_commons_institutions" do
185
+ before(:each) do
186
+ klass.stub_commons_institutions
187
+ end
188
+ it "returns commons_institutions fixture" do
189
+ flickr.commons.getInstitutions.should == fixtures.commons_institutions
190
+ end
191
+ end
192
+
179
193
  end
180
194
  end
Binary file
@@ -1,4 +1,4 @@
1
- U:OpenStruct{
1
+ U:OpenStruct{: photos[ : page:
2
2
  pages: perpage:
3
3
  total:
4
4
  photo:flickr_type:empty_photos[ ;;; ;
@@ -6,12 +6,12 @@ photo:flickr_type:empty_photos[ ;;; ;
6
6
  ; ; :author_photos[ ;;; ;
7
7
  ; ; ; [:id:
8
8
  owner: secret: server: farm:
9
- title:
9
+ title:
10
10
  dates:
11
- views:editability:
11
+ views:editability:publiceditability:
12
12
  usage:
13
13
  notes: tags:
14
14
  media; :photo_sizes[
15
15
  : canblog:
16
16
  label:
17
- width: height: source:url;,;
17
+ width: height: source:url;-; :commons_institutions[:institution;
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe APP::CommonsInstitution do
4
+ let(:api) {APP::Api}
5
+ let(:klass) {APP::CommonsInstitution}
6
+ let(:fixtures){APP::Fixtures.new}
7
+ let(:fixture){fixtures.commons_institutions[0]}
8
+ subject {klass.new(fixture)}
9
+
10
+ context "initialization" do
11
+ it "returns object of proper class when supplied FlickRaw::Response" do
12
+ klass.new(fixture).class.should == klass
13
+ end
14
+ it "raises an error when FlickRaw::ResponseList is provided" do
15
+ expect { klass.new(fixtures.photos)}.to raise_error
16
+ end
17
+ it "raises an Error when an Array is specified" do
18
+ expect { klass.new([1,2,3,4])}.to raise_error
19
+ end
20
+ end
21
+
22
+ context "instance methods" do
23
+
24
+ specify {subject.should respond_to(:launch_date)}
25
+ context "#launch_date" do
26
+ it "returns expected launch date" do
27
+ subject.launch_date.should == fixture.date_launch
28
+ end
29
+ end
30
+
31
+ specify {subject.should respond_to(:owner_id)}
32
+ context "#owner_id" do
33
+ it "returns expected id for owner of photo" do
34
+ subject.owner_id.should == fixture.nsid
35
+ end
36
+ end
37
+
38
+ context "#owner" do
39
+ it "returns expected id for owner of photo" do
40
+ subject.owner.should == fixture.nsid
41
+ end
42
+ end
43
+
44
+ specify {subject.should respond_to(:owner_name)}
45
+ context "#owner_name" do
46
+ it "returns expected owner_name" do
47
+ subject.owner_name.should == fixture.name
48
+ end
49
+ end
50
+
51
+ specify {subject.should respond_to(:site_url)}
52
+ context "#site_url" do
53
+ it "returns expected url for site owner" do
54
+ subject.site_url.should == fixture.urls[0]['_content']
55
+ end
56
+ end
57
+
58
+ specify {subject.should respond_to(:license_url)}
59
+ context "#license_url" do
60
+ it "returns expected url for license of photos" do
61
+ subject.license_url.should == fixture.urls[1]['_content']
62
+ end
63
+ end
64
+
65
+ specify {subject.should respond_to(:flickr_url)}
66
+ context "#flickr_url" do
67
+ it "returns expected url for institution on flickr" do
68
+ subject.flickr_url.should == fixture.urls[2]['_content']
69
+ end
70
+ end
71
+
72
+ specify {subject.should respond_to(:==)}
73
+ context "#==" do
74
+ it "returns true when object is compared to itself" do
75
+ subject.should == subject
76
+ end
77
+ it "returns true when object is compared to clone of itself" do
78
+ subject.should == subject.clone
79
+ end
80
+ it "returns flase when object is compared to identical object EXCEPT with one element" do
81
+ subject.should_not == subject.clone.instance_eval('@delegated_to_object').instance_eval('@h["urls"][0].instance_eval("@h")["type"]="garbage"')
82
+ end
83
+ it "returns false when object is compared to random object" do
84
+ subject.should_not == [1,2,3,4]
85
+ end
86
+ it "returns false when object is compared to another object of same calss" do
87
+ subject.should_not == klass.new(fixtures.commons_institutions[1])
88
+ end
89
+ end
90
+ end
91
+
92
+
93
+ context "custom cloning" do
94
+ context "#initialize_copy" do
95
+ it "returns institution objects that have distinct ids from the cloned object" do
96
+ other = subject.clone
97
+ subject.instance_eval('@delegated_to_object').__id__.should_not == other.instance_eval('@delegated_to_object').__id__
98
+ end
99
+ end
100
+ end
101
+
102
+ end
@@ -0,0 +1,167 @@
1
+ require 'spec_helper'
2
+
3
+ describe APP::CommonsInstitutions do
4
+ let(:api) {APP::Api}
5
+ let(:klass) {APP::CommonsInstitutions}
6
+ let(:fixtures){APP::Fixtures.new}
7
+ let(:fixture){fixtures.commons_institutions}
8
+ subject {klass.new(fixture)}
9
+
10
+
11
+ context "class methods" do
12
+ specify { klass.should respond_to(:defaults)}
13
+ it "returns expected set of defaults" do
14
+ klass.defaults.should == FlickrMocks::Models::Helpers.paging_defaults
15
+ end
16
+ end
17
+
18
+ context "initialization" do
19
+ it "returns object of a proper class when photos FlickRaw::ResponseList provided" do
20
+ klass.new(fixture).class.should == klass
21
+ end
22
+ it "raises an error when FlickRaw::Response provided" do
23
+ expect {klass.new(fixtures.photo)}.to raise_error(ArgumentError)
24
+ end
25
+ it "raises an error when an Array class specified" do
26
+ expect {klass.new([1,3,4])}.to raise_error(ArgumentError)
27
+ end
28
+ end
29
+
30
+ context "instance methods" do
31
+ specify {subject.should respond_to(:default)}
32
+ context "#default" do
33
+ it "should return default when proper symbol provided" do
34
+ klass.defaults.keys.each do |symbol|
35
+ subject.default(symbol).should == klass.defaults[symbol]
36
+ end
37
+ end
38
+ it "should return default when proper string provided" do
39
+ klass.defaults.keys.each do |symbol|
40
+ subject.default(symbol.to_s).should == klass.defaults[symbol]
41
+ end
42
+ end
43
+ it "should return nil when 'garbage' provided" do
44
+ subject.default(:garbage).should == nil
45
+ end
46
+ end
47
+
48
+ context "paging methods" do
49
+ specify {subject.should respond_to(:current_page)}
50
+ context "#current_page" do
51
+ it "should return 1 when no current_page given at initialization" do
52
+ klass.new(fixture,:per_page => 20).current_page.should == 1
53
+ end
54
+ it "should return specified current_page is valid" do
55
+ klass.new(fixture,:per_page => 20, :current_page => 2).current_page.should == 2
56
+ end
57
+ it "should return 1 when current page is 0" do
58
+ klass.new(fixture,:per_page => 20, :current_page => 0).current_page.should == 1
59
+ end
60
+ it "should return max page when current_page is greater than max_page" do
61
+ max_page = (fixture.size / 20)
62
+ klass.new(fixture,:per_page => 20,
63
+ :current_page => max_page+1).current_page.should == max_page
64
+ end
65
+ end
66
+
67
+ specify {subject.should respond_to(:per_page)}
68
+ context "#per_page" do
69
+ it "returns default per_page when none specified at initialization" do
70
+ klass.new(fixture,:current_page => 1).per_page.should ==
71
+ FlickrMocks::Models::Helpers.paging_defaults[:per_page]
72
+ end
73
+ it "returns per_page value that was specified during initialization" do
74
+ klass.new(fixture,:per_page => 33, :current_page => 1).per_page.should == 33
75
+ end
76
+ it "returns 1 when per_page is set to 0" do
77
+ klass.new(fixture,:per_page => 0, :current_page => 1).per_page.should ==
78
+ FlickrMocks::Models::Helpers.paging_defaults[:per_page]
79
+ end
80
+ end
81
+
82
+ specify {subject.should respond_to(:total_entries)}
83
+ context "#total_entries" do
84
+ it "returns expected number of photos" do
85
+ subject.total_entries.should == fixtures.commons_institutions.size
86
+ end
87
+ end
88
+
89
+ specify {subject.should respond_to(:==)}
90
+ context "#==" do
91
+ subject{klass.new(fixture,:per_page => 20, :current_page => 1)}
92
+ it "returns true when object compared to itself" do
93
+ subject.should == subject
94
+ end
95
+ it "returns true when object compared to clone of itself" do
96
+ subject.should == subject.clone
97
+ end
98
+ it "returns false when object is compared to object with different :per_page" do
99
+ subject.should_not == klass.new(fixture, :per_page => subject.per_page + 1,
100
+ :current_page => subject.current_page)
101
+ end
102
+ it "returns false when object is compared to object with different :current_page" do
103
+ subject.should_not == klass.new(fixture,:per_page => subject.per_page,
104
+ :current_page => subject.current_page + 1)
105
+ end
106
+ end
107
+ end
108
+ end
109
+
110
+ context "metaprogramming methods" do
111
+ specify{ subject.should respond_to(:delegated_instance_methods)}
112
+ context "#delegated_instance_methods" do
113
+ it "returns expected list of methods that are delegated to other objects" do
114
+ subject.delegated_instance_methods.sort.should == (FlickrMocks::Models::Helpers.array_accessor_methods).sort
115
+ end
116
+ end
117
+
118
+ specify { subject.should respond_to(:methods)}
119
+ context "#methods" do
120
+ it "should return all methods as well as array iteration methods" do
121
+ subject.methods.sort.should == (subject.old_methods + subject.delegated_instance_methods).sort
122
+ end
123
+ end
124
+
125
+ specify{ subject.should respond_to(:respond_to?)}
126
+ context "#respond_to?" do
127
+ it "recognizes all methods returned by #methods" do
128
+ subject.methods.each do |method|
129
+ subject.should respond_to(method)
130
+ end
131
+ end
132
+ end
133
+
134
+ context "iteratable methods" do
135
+ let(:reference) {subject.instance_eval('@delegated_to_object')}
136
+ it_behaves_like "object with delegated Array accessor helpers"
137
+ end
138
+
139
+ specify {subject.should respond_to(:collection)}
140
+ context "#collection" do
141
+ context "usable argument set to nil" do
142
+ let(:subject){
143
+ klass.new(fixture,:per_page => 20, :current_page => 1)
144
+ }
145
+ let(:reference){
146
+ OpenStruct.new :current_page => 1,
147
+ :per_page => 20,
148
+ :total_entries => fixture.size,
149
+ :collection => subject.institutions
150
+ }
151
+ it_behaves_like "object that responds to collection"
152
+ end
153
+ end
154
+ end
155
+
156
+ context "custom cloning methods" do
157
+ context "#initialize_copy" do
158
+ it "returns institution objects that have distinct ids from the cloned object" do
159
+ other = subject.clone
160
+ subject.each_index do |index|
161
+ subject[index].__id__.should_not == other[index].__id__
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
167
+
@@ -8,9 +8,9 @@ describe APP::Models::Helpers do
8
8
  context "array_accessor_methods" do
9
9
  it "returns expected array methods" do
10
10
  klass.array_accessor_methods.sort.should == [:[], :at,:fetch, :first, :last,:each,
11
- :each_index, :reverse_each,:length, :size,
12
- :empty?, :find_index, :index,:rindex, :collect,
13
- :map, :select, :keep_if, :values_at].sort
11
+ :each_index, :reverse_each,:length, :size,
12
+ :empty?, :find_index, :index, :each_with_index,:rindex, :collect,
13
+ :map, :select, :keep_if, :values_at].sort
14
14
  end
15
15
  end
16
16
 
@@ -18,8 +18,20 @@ describe APP::Models::Helpers do
18
18
  context "possible_sizes" do
19
19
  it "returns expected array of possible image sizes" do
20
20
  klass.possible_sizes.should == [:square, :thumbnail, :small, :medium,
21
- :medium_640, :large, :original]
21
+ :medium_640, :large, :original]
22
22
  end
23
23
  end
24
+
25
+ specify {klass.should respond_to(:paging_defaults)}
26
+ context "paging_defaults" do
27
+ it "returns expected hash of paging defaults" do
28
+ klass.paging_defaults.should == {
29
+ :max_entries => 4000,
30
+ :per_page => 50,
31
+ :current_page => 1
32
+ }
33
+ end
34
+ end
35
+
24
36
  end
25
37
  end
@@ -12,8 +12,7 @@ describe APP::Photos do
12
12
  let(:max_pages){subject.default(:max_entries)/subject.default(:per_page)}
13
13
 
14
14
  context "class methods" do
15
- specify { klass.should respond_to(:defaults)}
16
-
15
+ specify { klass.should respond_to(:defaults)}
17
16
  context "defaults" do
18
17
  before(:each) do
19
18
  @defaults = klass.defaults.clone
@@ -9,6 +9,7 @@ shared_examples_for "object with delegated Array accessor helpers" do
9
9
  specify{subject.should respond_to(:last)}
10
10
  specify{subject.should respond_to(:each)}
11
11
  specify{subject.should respond_to(:each_index)}
12
+ specify{subject.should respond_to(:each_with_index)}
12
13
  specify{subject.should respond_to(:reverse_each)}
13
14
  specify{subject.should respond_to(:length)}
14
15
  specify{subject.should respond_to(:size)}
@@ -101,6 +102,17 @@ shared_examples_for "object with delegated Array accessor helpers" do
101
102
  end
102
103
  end
103
104
 
105
+ context "#each_with_index" do
106
+ it "returns value and index" do
107
+ subject.each_with_index do |value,index|
108
+ value.should == reference[index]
109
+ end
110
+ reference.each_with_index do |value,index|
111
+ value.should == subject[index]
112
+ end
113
+ end
114
+ end
115
+
104
116
 
105
117
  context "#each_index" do
106
118
  it "returns same list as reference" do
data/tasks/fixtures.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../lib/flickrmocks')
2
2
  require 'fileutils'
3
+ require 'ruby-debug'
3
4
 
4
5
 
5
6
  # used for providing fixtures to users of the gem
6
7
  namespace :fixtures do
7
8
  desc 'generate all fixtures for USERS of the GEM'
8
9
  task :all => [:photos,:empty_photos,:interesting_photos,:author_photos,:photo,:photo_details,
9
- :photo_sizes,:photo_size,:expected_methods]
10
+ :photo_sizes,:photo_size,:expected_methods, :commons_institutions]
10
11
 
11
12
  desc 'generate fixture for flickr.photos.search'
12
13
  task :photos => :repository do
@@ -51,12 +52,17 @@ namespace :fixtures do
51
52
  dump default_photo_sizes,:photo_sizes
52
53
  end
53
54
 
54
- desc 'generated fixture for single size'
55
+ desc 'generate fixture for single size'
55
56
  task :photo_size => :repository do
56
57
  config_flickr
57
58
  dump default_photo_sizes[0],:photo_size
58
59
  end
59
60
 
61
+ desc 'generate fixture for commons institutions'
62
+ task :commons_institutions => :repository do
63
+ config_flickr
64
+ dump default_commons_institutions, :commons_institutions
65
+ end
60
66
 
61
67
  desc 'expected methods'
62
68
  task :expected_methods => :repository do
@@ -70,6 +76,7 @@ namespace :fixtures do
70
76
  data.photo_details = default_methods(default_photo_details)
71
77
  data.photo_sizes = default_methods(default_photo_sizes)
72
78
  data.photo_size = default_methods(default_photo_size)
79
+ data.commons_institutions = default_methods(default_commons_institutions)
73
80
  dump data,:expected_methods
74
81
  end
75
82
 
@@ -106,7 +113,7 @@ namespace :fixtures do
106
113
  end
107
114
 
108
115
  def repo_dir
109
- FlickrMocks::Fixtures.repository
116
+ config_dir + '/spec/fixtures/'
110
117
  end
111
118
 
112
119
  def dump(data,fname)
@@ -155,6 +162,11 @@ namespace :fixtures do
155
162
  @default_empty_photos
156
163
  end
157
164
 
165
+ def default_commons_institutions
166
+ @default_commons_institutions ||= flickr.commons.getInstitutions
167
+ @default_commons_institutions
168
+ end
169
+
158
170
  def default_methods(obj)
159
171
  obj.methods(false).push(:flickr_type)
160
172
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
- - 6
9
- version: 0.8.6
8
+ - 8
9
+ version: 0.8.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Takaltoo
@@ -14,27 +14,13 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-09 00:00:00 -08:00
17
+ date: 2010-11-18 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: thoughtbot-shoulda
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 2
30
- - 10
31
- version: "2.10"
32
- type: :development
33
- version_requirements: *id001
34
20
  - !ruby/object:Gem::Dependency
35
21
  name: rspec
36
22
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
38
24
  none: false
39
25
  requirements:
40
26
  - - ">="
@@ -47,11 +33,11 @@ dependencies:
47
33
  - 22
48
34
  version: 2.0.0.beta.22
49
35
  type: :development
50
- version_requirements: *id002
36
+ version_requirements: *id001
51
37
  - !ruby/object:Gem::Dependency
52
38
  name: capybara
53
39
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ requirement: &id002 !ruby/object:Gem::Requirement
55
41
  none: false
56
42
  requirements:
57
43
  - - ">="
@@ -60,11 +46,11 @@ dependencies:
60
46
  - 0
61
47
  version: "0"
62
48
  type: :development
63
- version_requirements: *id003
49
+ version_requirements: *id002
64
50
  - !ruby/object:Gem::Dependency
65
51
  name: factory_girl_rails
66
52
  prerelease: false
67
- requirement: &id004 !ruby/object:Gem::Requirement
53
+ requirement: &id003 !ruby/object:Gem::Requirement
68
54
  none: false
69
55
  requirements:
70
56
  - - ">="
@@ -74,11 +60,11 @@ dependencies:
74
60
  - 0
75
61
  version: "1.0"
76
62
  type: :development
77
- version_requirements: *id004
63
+ version_requirements: *id003
78
64
  - !ruby/object:Gem::Dependency
79
65
  name: faker
80
66
  prerelease: false
81
- requirement: &id005 !ruby/object:Gem::Requirement
67
+ requirement: &id004 !ruby/object:Gem::Requirement
82
68
  none: false
83
69
  requirements:
84
70
  - - ">="
@@ -89,11 +75,11 @@ dependencies:
89
75
  - 1
90
76
  version: 0.3.1
91
77
  type: :development
92
- version_requirements: *id005
78
+ version_requirements: *id004
93
79
  - !ruby/object:Gem::Dependency
94
80
  name: flickraw
95
81
  prerelease: false
96
- requirement: &id006 !ruby/object:Gem::Requirement
82
+ requirement: &id005 !ruby/object:Gem::Requirement
97
83
  none: false
98
84
  requirements:
99
85
  - - ">="
@@ -104,11 +90,11 @@ dependencies:
104
90
  - 2
105
91
  version: 0.8.2
106
92
  type: :runtime
107
- version_requirements: *id006
93
+ version_requirements: *id005
108
94
  - !ruby/object:Gem::Dependency
109
95
  name: chronic
110
96
  prerelease: false
111
- requirement: &id007 !ruby/object:Gem::Requirement
97
+ requirement: &id006 !ruby/object:Gem::Requirement
112
98
  none: false
113
99
  requirements:
114
100
  - - ">="
@@ -117,7 +103,7 @@ dependencies:
117
103
  - 0
118
104
  version: "0"
119
105
  type: :runtime
120
- version_requirements: *id007
106
+ version_requirements: *id006
121
107
  description: |-
122
108
  FlickrMocks makes it possible to Marshal responses
123
109
  generated from the FLickRaw gem. This is useful for
@@ -153,6 +139,8 @@ files:
153
139
  - lib/flickr_mocks/flickraw/custom_marshal.rb
154
140
  - lib/flickr_mocks/flickraw/flickraw.rb
155
141
  - lib/flickr_mocks/helpers.rb
142
+ - lib/flickr_mocks/models/commons_institution.rb
143
+ - lib/flickr_mocks/models/commons_institutions.rb
156
144
  - lib/flickr_mocks/models/helpers.rb
157
145
  - lib/flickr_mocks/models/photo.rb
158
146
  - lib/flickr_mocks/models/photo_details.rb
@@ -177,6 +165,7 @@ files:
177
165
  - spec/base/stubs_spec.rb
178
166
  - spec/base/version_spec.rb
179
167
  - spec/fixtures/author_photos.marshal
168
+ - spec/fixtures/commons_institutions.marshal
180
169
  - spec/fixtures/empty_photos.marshal
181
170
  - spec/fixtures/expected_methods.marshal
182
171
  - spec/fixtures/interesting_photos.marshal
@@ -185,6 +174,8 @@ files:
185
174
  - spec/fixtures/photo_size.marshal
186
175
  - spec/fixtures/photo_sizes.marshal
187
176
  - spec/fixtures/photos.marshal
177
+ - spec/models/commons_institution_spec.rb
178
+ - spec/models/commons_institutions_spec.rb
188
179
  - spec/models/helpers_spec.rb
189
180
  - spec/models/photo_details_spec.rb
190
181
  - spec/models/photo_dimensions_spec.rb
@@ -239,7 +230,9 @@ test_files:
239
230
  - spec/models/helpers_spec.rb
240
231
  - spec/models/photo_details_spec.rb
241
232
  - spec/models/photo_size_spec.rb
233
+ - spec/models/commons_institution_spec.rb
242
234
  - spec/models/photo_sizes_spec.rb
235
+ - spec/models/commons_institutions_spec.rb
243
236
  - spec/models/photos_spec.rb
244
237
  - spec/models/photo_dimensions_spec.rb
245
238
  - spec/models/photo_spec.rb