flickrmocks 0.8.15 → 0.9.0

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.
Files changed (53) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile.lock +123 -0
  3. data/README.rdoc +104 -30
  4. data/Rakefile +12 -0
  5. data/flickrmocks.gemspec +3 -1
  6. data/lib/flickr_mocks/api/api.rb +80 -27
  7. data/lib/flickr_mocks/api/flickr.rb +69 -23
  8. data/lib/flickr_mocks/api/helpers.rb +25 -12
  9. data/lib/flickr_mocks/api/options.rb +71 -53
  10. data/lib/flickr_mocks/api/sanitize.rb +129 -20
  11. data/lib/flickr_mocks/fixtures.rb +7 -1
  12. data/lib/flickr_mocks/flickraw/custom_clone.rb +3 -1
  13. data/lib/flickr_mocks/flickraw/custom_compare.rb +4 -0
  14. data/lib/flickr_mocks/flickraw/custom_marshal.rb +7 -2
  15. data/lib/flickr_mocks/flickraw/flickraw.rb +6 -0
  16. data/lib/flickr_mocks/helpers.rb +8 -1
  17. data/lib/flickr_mocks/models/commons_institution.rb +45 -34
  18. data/lib/flickr_mocks/models/commons_institutions.rb +85 -75
  19. data/lib/flickr_mocks/models/helpers.rb +13 -6
  20. data/lib/flickr_mocks/models/models.rb +7 -0
  21. data/lib/flickr_mocks/models/photo.rb +76 -75
  22. data/lib/flickr_mocks/models/photo_details.rb +71 -69
  23. data/lib/flickr_mocks/models/photo_dimensions.rb +80 -78
  24. data/lib/flickr_mocks/models/photo_search.rb +115 -88
  25. data/lib/flickr_mocks/models/photo_size.rb +57 -56
  26. data/lib/flickr_mocks/models/photo_sizes.rb +68 -67
  27. data/lib/flickr_mocks/models/photos.rb +104 -99
  28. data/lib/flickr_mocks/stubs.rb +151 -14
  29. data/lib/flickr_mocks/version.rb +7 -1
  30. data/spec/api/api_spec.rb +26 -8
  31. data/spec/api/flickr_spec.rb +19 -19
  32. data/spec/api/helper_spec.rb +20 -20
  33. data/spec/api/options_spec.rb +170 -124
  34. data/spec/api/sanitize_spec.rb +174 -59
  35. data/spec/base/stubs_spec.rb +37 -74
  36. data/spec/base/version_spec.rb +11 -4
  37. data/spec/models/commons_institution_spec.rb +3 -2
  38. data/spec/models/commons_institutions_spec.rb +34 -5
  39. data/spec/models/helpers_spec.rb +7 -6
  40. data/spec/models/photo_details_spec.rb +12 -11
  41. data/spec/models/photo_dimensions_spec.rb +5 -4
  42. data/spec/models/photo_search_spec.rb +50 -8
  43. data/spec/models/photo_size_spec.rb +4 -3
  44. data/spec/models/photo_sizes_spec.rb +6 -5
  45. data/spec/models/photo_spec.rb +6 -4
  46. data/spec/models/photos_spec.rb +9 -7
  47. data/spec/shared_examples/hash_options/date_hash_option.rb +42 -0
  48. data/spec/shared_examples/hash_options/page_hash_option.rb +23 -0
  49. data/spec/shared_examples/hash_options/perpage_hash_option.rb +43 -0
  50. data/spec/shared_examples/hash_options/tag_mode_hash_option.rb +31 -0
  51. data/spec/shared_examples/stub_helpers.rb +140 -0
  52. data/spec/spec_helper.rb +5 -5
  53. metadata +55 -16
data/spec/api/api_spec.rb CHANGED
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
  require 'ruby-debug'
3
3
  describe APP::Api do
4
4
  let(:klass) { APP::Api }
5
+ let(:models){APP::Models}
5
6
 
6
7
  let(:fixtures){APP::Fixtures.instance}
7
8
  let(:photo){fixtures.photo}
@@ -21,7 +22,11 @@ describe APP::Api do
21
22
  klass.defaults = @defaults
22
23
  end
23
24
  it "returns has with expected set of keys" do
24
- klass.defaults.keys.sort.should == [:per_page,:license,:media,:extras,:tag_mode,:flickr_tag_modes].sort
25
+ klass.defaults.keys.sort.should == [:page,:per_page,:license,:media,
26
+ :max_entries,:extras,:tag_mode,
27
+ :possible_sizes,:possible_tag_modes].sort
28
+
29
+
25
30
  end
26
31
  it "returns object whose elements can be set similar to a hash" do
27
32
  expected = "#{Random.srand}"
@@ -34,13 +39,26 @@ describe APP::Api do
34
39
  end
35
40
 
36
41
  context "class methods" do
42
+ specify {klass.should respond_to(:default)}
43
+ context "default" do
44
+ it "returns key stored in @defaults class instance variable when symbol specified" do
45
+ klass.default(:per_page).should == klass.defaults[:per_page]
46
+ end
47
+ it "returns key stored in @defaults class instance variable when string specified" do
48
+ klass.default('per_page').should == klass.defaults[:per_page]
49
+ end
50
+ it "returns nil when key that is not in @defaults class instance variable is specified" do
51
+ klass.default('garbage').should == nil
52
+ end
53
+ end
54
+
37
55
  let(:subject){klass}
38
56
  specify {klass.should respond_to(:photo)}
39
57
  context "photo" do
40
58
  it "returns expected Photo object" do
41
59
  flickr.photos.stub(:getInfo).and_return(photo)
42
60
  klass.photo({:photo =>photo.id,
43
- :secret => photo.secret}).should == APP::Photo.new(photo)
61
+ :secret => photo.secret}).should == models::Photo.new(photo)
44
62
  end
45
63
  context "arguments" do
46
64
  let(:method){:photo}
@@ -53,7 +71,7 @@ describe APP::Api do
53
71
  it "returns expected PhotoSearch object" do
54
72
  flickr.photos.stub(:search).and_return(photos)
55
73
  klass.photos({:search_terms => 'iran'}).should ==
56
- APP::PhotoSearch.new(photos,{:search_terms => 'iran'})
74
+ models::PhotoSearch.new(photos,{:search_terms => 'iran'})
57
75
  end
58
76
  it "raises error when non-hash argument provided" do
59
77
  expect {
@@ -69,10 +87,10 @@ describe APP::Api do
69
87
  specify {klass.should respond_to(:photo_sizes)}
70
88
  context "photo_sizes" do
71
89
  it "returns expected PhotoSizes object" do
72
- expected = APP::PhotoSizes.new(sizes)
90
+ expected = models::PhotoSizes.new(sizes)
73
91
  flickr.photos.stub(:getSizes).and_return(sizes)
74
92
  klass.photo_sizes(:photo => expected.id,
75
- :secret => expected.secret).should == expected
93
+ :secret => expected.secret).should == expected
76
94
  end
77
95
  context "arguments" do
78
96
  let(:method){:photos}
@@ -86,7 +104,7 @@ describe APP::Api do
86
104
  flickr.photos.stub(:getSizes).and_return(sizes)
87
105
  flickr.photos.stub(:getInfo).and_return(photo)
88
106
  klass.photo_details(:photo => photo.id,
89
- :secret => photo.secret).should == APP::PhotoDetails.new(photo,sizes)
107
+ :secret => photo.secret).should == models::PhotoDetails.new(photo,sizes)
90
108
  end
91
109
  context "arguments" do
92
110
  let(:method){:photo_details}
@@ -100,7 +118,7 @@ describe APP::Api do
100
118
  it "returns expected PhotoSearch object" do
101
119
  flickr.interestingness.stub(:getList).and_return(interesting_photos)
102
120
  klass.interesting_photos({:date => '2010-01-01'}).should ==
103
- APP::PhotoSearch.new(interesting_photos,{:date => '2010-01-01'})
121
+ models::PhotoSearch.new(interesting_photos,{:date => '2010-01-01'})
104
122
  end
105
123
  context "arguments" do
106
124
  let(:method){:interesting_photos}
@@ -113,7 +131,7 @@ describe APP::Api do
113
131
  it "returns expected CommonsInstitutions object" do
114
132
  flickr.commons.stub(:getInstitutions).and_return(commons_institutions)
115
133
  klass.commons_institutions({}).should ==
116
- APP::CommonsInstitutions.new(commons_institutions)
134
+ models::CommonsInstitutions.new(commons_institutions)
117
135
  end
118
136
  context "arguments" do
119
137
  let(:method){:commons_institutions}
@@ -1,54 +1,54 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe APP::Api do
4
- let(:klass){APP::Api}
3
+ describe APP::Api::Flickr do
4
+ let(:klass){APP::Api::Flickr}
5
5
  let(:fixtures){APP::Fixtures.instance}
6
6
 
7
7
  context "class methods" do
8
- specify {klass.should respond_to(:flickr_photos)}
9
- context "flickr_photos" do
8
+ specify {klass.should respond_to(:photos)}
9
+ context "photos" do
10
10
  it "returns list of photos" do
11
11
  flickr.photos.stub(:search).and_return(fixtures.photos)
12
- klass.flickr_photos({}).should == fixtures.photos
12
+ klass.photos({}).should == fixtures.photos
13
13
  end
14
14
  end
15
15
 
16
- specify {klass.should respond_to(:flickr_photo)}
17
- context "flickr_photos" do
16
+ specify {klass.should respond_to(:photo)}
17
+ context "photos" do
18
18
  it "returns photo" do
19
19
  flickr.photos.stub(:getInfo).and_return(fixtures.photo)
20
- klass.flickr_photo({}).should == fixtures.photo
20
+ klass.photo({}).should == fixtures.photo
21
21
  end
22
22
  end
23
23
 
24
- specify {klass.should respond_to(:flickr_photo_sizes)}
25
- context "flickr_photo_sizes" do
24
+ specify {klass.should respond_to(:photo_sizes)}
25
+ context "photo_sizes" do
26
26
  it "returns list sizes for a photo" do
27
27
  flickr.photos.stub(:getSizes).and_return(fixtures.photo_sizes)
28
- klass.flickr_photo_sizes({}).should == fixtures.photo_sizes
28
+ klass.photo_sizes({}).should == fixtures.photo_sizes
29
29
  end
30
30
  end
31
31
 
32
- specify {klass.should respond_to(:flickr_interestingness)}
33
- context "flickr_interestingness" do
32
+ specify {klass.should respond_to(:interestingness)}
33
+ context "interestingness" do
34
34
  it "returns list of interesting photos" do
35
35
  flickr.interestingness.stub(:getList).and_return(fixtures.interesting_photos)
36
- klass.flickr_interestingness({}).should == fixtures.interesting_photos
36
+ klass.interestingness({}).should == fixtures.interesting_photos
37
37
  end
38
38
  end
39
39
 
40
- specify {klass.should respond_to(:flickr_author)}
41
- context "flickr_author" do
40
+ specify {klass.should respond_to(:author)}
41
+ context "author" do
42
42
  it "returns list of photos for an author" do
43
43
  flickr.photos.stub(:search).and_return(fixtures.author_photos)
44
- klass.flickr_author({}).should == fixtures.author_photos
44
+ klass.author({}).should == fixtures.author_photos
45
45
  end
46
46
  end
47
47
 
48
- specify {klass.should respond_to(:flickr_commons_institutions)}
48
+ specify {klass.should respond_to(:commons_institutions)}
49
49
  it "retuns list of commons institutions" do
50
50
  flickr.commons.stub(:getInstitutions).and_return(fixtures.commons_institutions)
51
- klass.flickr_commons_institutions.should == fixtures.commons_institutions
51
+ klass.commons_institutions.should == fixtures.commons_institutions
52
52
  end
53
53
  end
54
54
  end
@@ -1,37 +1,37 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe APP::Api do
3
+ describe APP::Api::Helpers do
4
4
 
5
- let(:klass) {APP::Api}
5
+ let(:klass) {APP::Api::Helpers}
6
6
  context "class methods" do
7
- specify {klass.should respond_to(:default)}
8
- context "default" do
9
- it "returns key stored in @defaults class instance variable when symbol specified" do
10
- klass.default(:per_page).should == klass.defaults[:per_page]
11
- end
12
- it "returns key stored in @defaults class instance variable when string specified" do
13
- klass.default('per_page').should == klass.defaults[:per_page]
14
- end
15
- it "returns nil when key that is not in @defaults class instance variable is specified" do
16
- klass.default('garbage').should == nil
17
- end
18
- end
19
-
20
- specify {klass.should respond_to(:time)}
21
- context "time" do
7
+ specify {klass.should respond_to(:date)}
8
+ context "date" do
22
9
  it "returns yesterday when no time is specified" do
23
10
  expected = Chronic.parse('yesterday').strftime('%Y-%m-%d')
24
- klass.time.should == expected
11
+ klass.date.should == expected
25
12
  end
26
13
 
27
14
  it "returns user specified date when proper date given" do
28
15
  expected = '2010-12-25'
29
- klass.time(expected).should == expected
16
+ klass.date(expected).should == expected
30
17
  end
31
18
 
32
19
  it "returns yesterday when garbage date given" do
33
- klass.time('garbage').should == Chronic.parse('yesterday').strftime('%Y-%m-%d')
20
+ klass.date('garbage').should == Chronic.parse('yesterday').strftime('%Y-%m-%d')
34
21
  end
35
22
  end
36
23
  end
24
+
25
+ specify {klass.should respond_to(:valid_date?)}
26
+ context "valid_date?" do
27
+ it "returns true when valid string of Format 'YYYY-MM-DD' provided" do
28
+ klass.valid_date?('2001-10-10').should be_true
29
+ end
30
+ it "returns false when integer provided string of format provided" do
31
+ klass.valid_date?(1).should be_false
32
+ end
33
+ it "returns false when ambiguous date provided" do
34
+ klass.valid_date?('2000').should be_false
35
+ end
36
+ end
37
37
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe APP::Api do
4
- let(:api) {APP::Api}
5
- let(:subject) {APP::Api}
4
+ let(:api) {APP::Api::Options}
5
+ let(:subject) {APP::Api::Options}
6
6
  let(:extras){
7
7
  { :license => '4,5,6,7',
8
8
  :media => 'photos',
@@ -23,159 +23,205 @@ describe APP::Api do
23
23
  }.merge(extras.clone)
24
24
  }
25
25
 
26
-
27
- context "search_options" do
26
+ specify {subject.should respond_to(:search)}
27
+ context "search" do
28
+ let(:method){:search}
28
29
  it "should give correct options when all options are specified except :author_id" do
29
- subject.search_options(options.clone.merge(:per_page =>'400')).should == expected
30
+ subject.search(options.clone.merge(:per_page =>'400')).should == expected
30
31
  end
31
32
  it "should return options when fully specified" do
32
- subject.search_options(:per_page => '400',:owner_id => 'authorid',:page => '2').should ==
33
+ subject.search(:per_page => '400',:owner_id => 'authorid',:page => '2').should ==
33
34
  expected.clone.merge(:user_id => 'authorid',:tags => nil)
34
35
 
35
36
  end
36
- it "should give correct values when :perpage given in lieu of :per_page" do
37
- subject.search_options(options.clone.merge({:perpage => '400'})).should == expected
38
- end
39
- it "should give correct value when no :perpage is specified" do
40
- subject.search_options(options).should == expected.clone.merge({:per_page => '200'})
41
- end
42
- it "should give preference to :per_page to :perpage" do
43
- subject.search_options(options.clone.merge({:per_page => '500', :perpage => '444'})).should ==
44
- expected.clone.merge(:per_page => '500')
45
- end
46
- it "should be able to set :tag_mode" do
47
- subject.search_options(options.clone.merge(:per_page => '500', :tag_mode=>'all' )).should ==
48
- expected.clone.merge({:per_page => '500',:tag_mode => 'all'}
49
- )
50
- end
51
- it "should give default tag_mode when not specified" do
52
- subject.search_options(options.clone.merge(:per_page => '500')).should ==
53
- expected.clone.merge({:per_page => '500'}
54
- )
55
- end
56
- it "should give default tag_mode when junk given for tag_mode" do
57
- subject.search_options(options.clone.merge(:per_page => '500', :tag_mode => 'junk')).should ==
58
- expected.clone.merge({:per_page => '500'}
59
- )
37
+ context "tag_mode option" do
38
+ let(:options){
39
+ extras.clone.merge({
40
+ :search_terms => 'france',
41
+ :owner_id => '1234',
42
+ :page => '1',
43
+ :per_page => '50'
44
+ })
45
+ }
46
+ let(:expected){
47
+ extras.clone.merge({
48
+ :tags => options[:search_terms],
49
+ :user_id => options[:owner_id],
50
+ :page => options[:page],
51
+ :per_page => options[:per_page]
52
+ })
53
+ }
54
+ it_behaves_like "tag mode hash option"
55
+ end
56
+ context "per page option" do
57
+ let(:options){
58
+ extras.clone.merge({
59
+ :search_terms => 'france',
60
+ :owner_id => '1234',
61
+ :page => '1',
62
+ })
63
+ }
64
+ let(:expected){
65
+ extras.clone.merge({
66
+ :tags => options[:search_terms],
67
+ :user_id => options[:owner_id],
68
+ :page => options[:page],
69
+ })
70
+ }
71
+ it_behaves_like "per page hash option"
72
+ end
73
+ context "page option" do
74
+ let(:options){
75
+ extras.clone.merge({
76
+ :search_terms => 'france',
77
+ :owner_id => '1234',
78
+ :per_page => '50',
79
+ })
80
+ }
81
+ let(:expected){
82
+ extras.clone.merge({
83
+ :tags => options[:search_terms],
84
+ :user_id => options[:owner_id],
85
+ :per_page => options[:per_page],
86
+ })
87
+ }
88
+ it_behaves_like "page hash option"
60
89
  end
61
90
  end
62
91
 
63
- context "interesting_options" do
64
- let(:expected){
65
- { :date => '2010-02-14',
66
- :per_page => '2',
67
- :page => '2'
68
- }
69
- }
70
- it "should return proper date with default options" do
71
- subject.interesting_options(expected).should == expected.clone.merge(:extras => 'license')
92
+ specify {subject.should respond_to(:interesting)}
93
+ context "interesting" do
94
+ let(:method){:interesting}
95
+ context "date option" do
96
+ let(:options){{
97
+ :per_page => '2',
98
+ :page => '2',
99
+ :extras => 'license'
100
+ }}
101
+ let(:expected){options}
102
+ it_behaves_like "date hash option"
72
103
  end
73
- it "should return proper date when no page given" do
74
- subject.interesting_options(:date => '2010-02-14', :per_page => '2').should ==
75
- expected.clone.merge(:page => '1', :extras => 'license')
76
-
77
- end
78
- it "should return proper date when not specified" do
79
- date = Chronic.parse('yesterday').strftime('%Y-%m-%d')
80
- subject.interesting_options({:date => date})[:date].should == date
104
+
105
+ context "page option" do
106
+ let(:options){
107
+ { :date => '2010-10-10',
108
+ :per_page => '50',
109
+ :extras => FlickrMocks::Api.default(:extras)
110
+ }}
111
+ let(:expected){options}
112
+ it_behaves_like "page hash option"
113
+ end
114
+ context "per page option" do
115
+ let(:options){
116
+ { :date => '2010-10-10',
117
+ :page => '1',
118
+ :extras => FlickrMocks::Api.default(:extras)
119
+ }}
120
+ let(:expected){options}
121
+ it_behaves_like "per page hash option"
81
122
  end
82
123
  end
83
124
 
84
- context "photo_options" do
125
+ specify{subject.should respond_to(:photo)}
126
+ context "photo" do
85
127
  let(:expected) {
86
128
  {:photo_id => '20030', :secret => 'abcdef'}
87
129
  }
88
-
89
- it "should extract :photo_id and :secret" do
90
- subject.photo_options(expected).should == expected
130
+ it "returns :photo_id and :secret when provided" do
131
+ subject.photo(expected).should == expected
91
132
  end
92
- it "should return photo id when present" do
93
- subject.photo_options(:id => '20030',:secret => 'abcdef').should == expected
133
+ it "returns :photo_id when :id provided" do
134
+ subject.photo(:id => '20030',:secret => 'abcdef').should == expected
94
135
  end
95
- it "should give preference to :photo_id over :id" do
96
- subject.photo_options(expected.clone.merge(:id => 'not correct')).should == expected
136
+ it "should prefer :photo_id over :id" do
137
+ subject.photo(expected.clone.merge(:id => 'not correct')).should == expected
97
138
  end
98
- it "should give preference to :photo_secret over :secret" do
99
- subject.photo_options(:photo_secret => 'abcdef', :secret => 'not correct', :id => '20030').should ==
100
- expected
101
-
139
+ it "should prefer :photo_secret over :secret" do
140
+ subject.photo(:photo_secret => 'abcdef', :secret => 'not correct', :id => '20030').should ==
141
+ expected
102
142
  end
103
- end
104
-
105
- context "search_params" do
106
- let(:expected){
107
- {
108
- :search_terms => 'iran,shiraz',
109
- :owner_id => 'authorid',
110
- :base_url => 'http://www.happyboy.com/'
111
- }
112
- }
113
- let(:base_url) {'http://www.example.com/'}
114
-
115
- it "should return properly when all options specified" do
116
- subject.search_params(expected).should == expected
143
+ it "returns nil for :photo_id when no id given" do
144
+ subject.photo({:secret => '22'}).should ==
145
+ {:secret => '22', :photo_id => nil}
117
146
  end
118
- it "should filter non-required options" do
119
- subject.search_params(expected.clone.merge(:date => '2010-10-02',:per_page => '2')).should ==
120
- expected
121
-
147
+ it "returns nil for :secret when no :secret given" do
148
+ subject.photo({:photo_id => '1234'}).should ==
149
+ {:secret => nil, :photo_id => '1234'}
122
150
  end
123
- it "should properly extract :base_url" do
124
- subject.search_params(expected.clone.merge(:base_url => base_url)).should ==
125
- expected.clone.merge(:base_url => base_url)
151
+ it "returns nil for :secret and :photo_id when nil provided" do
152
+ subject.photo({:photo_id => nil, :secret => nil}).should ==
153
+ {:secret => nil, :photo_id => nil}
126
154
  end
127
155
  end
128
156
 
129
- context "interesting_params" do
130
- let(:expected) {
131
- {
132
- :date => 'iran,shiraz',
133
- :base_url => 'http://www.happyboy.com/'
134
- }
157
+
158
+
159
+ specify {subject.should respond_to(:author)}
160
+ context "author" do
161
+ let(:method){:author}
162
+ let(:expected){
163
+ { :per_page => '400',
164
+ :user_id => nil,
165
+ :page => '2'}.merge(extras.clone)
135
166
  }
136
- it "should return correct options when all are specified" do
137
- subject.interesting_params(expected).should == expected
138
- end
139
- it "should filter non-required options" do
140
- subject.interesting_params(expected.clone.merge(:search_terms => 'iran,shiraz',
141
- :owner_id => 'authorid')).should == expected
142
- end
143
- it "should extract base_url options" do
144
- subject.interesting_params(expected.clone.merge(:base_url => expected[:base_url])).should ==
145
- expected.clone.merge(:base_url => expected[:base_url])
167
+ it "should give correct options when all options are specified except :author_id" do
168
+ subject.author(options.clone.merge(:per_page =>'400')).should == expected
146
169
  end
147
- end
170
+ it "should return options when fully specified" do
171
+ subject.author(:per_page => '400',:owner_id => 'authorid',:page => '2').should ==
172
+ expected.clone.merge(:user_id => 'authorid')
148
173
 
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
174
  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
- it "returns :current_page in preference to :page" do
169
- subject.commons_institutions_params(:per_page=>20,:page=>2,:current_page=>3).should ==
170
- {:per_page => 20, :current_page => 3}
171
- end
172
- it "returns :page when :current_page is not specified" do
173
- subject.commons_institutions_params(:per_page=>20,:page=>3).should ==
174
- {:per_page => 20, :current_page => 3}
175
+ context "tag_mode option" do
176
+ it "should be able to set :tag_mode" do
177
+ subject.author(options.clone.merge(:per_page => '500', :tag_mode=>'all' )).should ==
178
+ expected.clone.merge({:per_page => '500',:tag_mode => 'all'}
179
+ )
180
+ end
181
+ it "should give default tag_mode when not specified" do
182
+ subject.author(options.clone.merge(:per_page => '500')).should ==
183
+ expected.clone.merge({:per_page => '500'}
184
+ )
185
+ end
186
+ it "should give default tag_mode when junk given for tag_mode" do
187
+ subject.author(options.clone.merge(:per_page => '500', :tag_mode => 'junk')).should ==
188
+ expected.clone.merge({:per_page => '500'}
189
+ )
190
+ end
191
+ end
192
+ context "per page option" do
193
+ let(:options){
194
+ extras.clone.merge({
195
+ :search_terms => 'france',
196
+ :owner_id => '1234',
197
+ :page => '1',
198
+ })
199
+ }
200
+ let(:expected){
201
+ extras.clone.merge({
202
+ :user_id => options[:owner_id],
203
+ :page => options[:page],
204
+ })
205
+ }
206
+ it_behaves_like "per page hash option"
207
+ end
208
+ context "page option" do
209
+ let(:options){
210
+ extras.clone.merge({
211
+ :search_terms => 'france',
212
+ :owner_id => '1234',
213
+ :per_page => '50',
214
+ })
215
+ }
216
+ let(:expected){
217
+ extras.clone.merge({
218
+ :user_id => options[:owner_id],
219
+ :per_page => options[:per_page],
220
+ })
221
+ }
222
+ it_behaves_like "page hash option"
175
223
  end
176
224
  end
177
-
178
-
179
225
  end
180
226
 
181
227