kuva 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.env.example +4 -0
- data/.gitignore +13 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +26 -0
- data/Gemfile.lock +187 -0
- data/MIT-LICENSE +20 -0
- data/README.md +129 -0
- data/Rakefile +14 -0
- data/app/assets/images/kuva/.keep +0 -0
- data/app/assets/javascripts/kuva/application.js +13 -0
- data/app/assets/javascripts/kuva/jquery-2.1.0.min.js +4 -0
- data/app/assets/javascripts/kuva/jquery.justified_gallery.min.js +7 -0
- data/app/assets/javascripts/kuva/kuva.js.coffee +2 -0
- data/app/assets/stylesheets/kuva/application.css +13 -0
- data/app/assets/stylesheets/kuva/justified_gallery.min.css +7 -0
- data/app/assets/stylesheets/kuva/kuva.css.sass +42 -0
- data/app/controllers/kuva/application_controller.rb +17 -0
- data/app/controllers/kuva/photos_controller.rb +10 -0
- data/app/controllers/kuva/sets_controller.rb +24 -0
- data/app/helpers/kuva/application_helper.rb +31 -0
- data/app/views/kuva/photos/show.html.haml +6 -0
- data/app/views/kuva/sets/index.html.haml +8 -0
- data/app/views/kuva/sets/show.html.haml +8 -0
- data/app/views/layouts/kuva/application.html.haml +10 -0
- data/config/locales/cli.yml +8 -0
- data/config/locales/frontend.yml +4 -0
- data/config/routes.rb +9 -0
- data/kuva.gemspec +25 -0
- data/lib/generators/kuva/install_generator.rb +20 -0
- data/lib/generators/kuva/templates/kuva.rb +34 -0
- data/lib/generators/kuva/views_generator.rb +23 -0
- data/lib/kuva.rb +23 -0
- data/lib/kuva/authorizer.rb +50 -0
- data/lib/kuva/elements/photo.rb +41 -0
- data/lib/kuva/elements/photoset.rb +49 -0
- data/lib/kuva/elements/photoset_collection.rb +25 -0
- data/lib/kuva/elements/url_info.rb +6 -0
- data/lib/kuva/engine.rb +9 -0
- data/lib/kuva/version.rb +3 -0
- data/lib/tasks/kuva_task.rake +6 -0
- data/spec/controllers/kuva/application_controller_spec.rb +42 -0
- data/spec/controllers/kuva/photos_controller_spec.rb +22 -0
- data/spec/controllers/kuva/sets_controller_spec.rb +51 -0
- data/spec/dummy/README.md +1 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +30 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/kuva.rb +29 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/features/photo_spec.rb +40 -0
- data/spec/features/photoset_collection_spec.rb +25 -0
- data/spec/features/photoset_spec.rb +42 -0
- data/spec/generators/kuva/install_generator_spec.rb +30 -0
- data/spec/generators/kuva/views_generator_spec.rb +37 -0
- data/spec/helpers/kuva/application_helper_spec.rb +26 -0
- data/spec/kuva/authorizer_spec.rb +83 -0
- data/spec/kuva/elements/photo_spec.rb +76 -0
- data/spec/kuva/elements/photoset_collection_spec.rb +42 -0
- data/spec/kuva/elements/photoset_spec.rb +106 -0
- data/spec/kuva/elements/url_info_spec.rb +25 -0
- data/spec/kuva_spec.rb +81 -0
- data/spec/spec_helper.rb +68 -0
- data/spec/support/vcr/cassettes/Kuva_ApplicationController/configuring_Kuva/sets_the_API_key.yml +160 -0
- data/spec/support/vcr/cassettes/Kuva_ApplicationController/configuring_Kuva/sets_the_access_secret.yml +160 -0
- data/spec/support/vcr/cassettes/Kuva_ApplicationController/configuring_Kuva/sets_the_access_token.yml +160 -0
- data/spec/support/vcr/cassettes/Kuva_ApplicationHelper/_breadcrumbs_for/when_the_current_page_is_NOT_the_set_page/creates_a_breadcrumb_with_the_set_URL.yml +65 -0
- data/spec/support/vcr/cassettes/Kuva_ApplicationHelper/_breadcrumbs_for/when_the_current_page_is_the_set_page/creates_a_breadcrumb_without_the_set_URL.yml +222 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photo/_find/fetches_the_photo_from_Flickr_specified_by_id.yml +95 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photo/_find/instantiates_a_new_Kuva_Elements_Photo_object.yml +252 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photo/_initialize/does_NOT_set_the_is_primary_boolean.yml +252 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photo/_initialize/returns_itself.yml +95 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photo/_initialize/saves_a_reference_to_the_description.yml +95 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photo/_initialize/saves_a_reference_to_the_farm.yml +95 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photo/_initialize/saves_a_reference_to_the_id.yml +95 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photo/_initialize/saves_a_reference_to_the_secret.yml +95 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photo/_initialize/saves_a_reference_to_the_server.yml +252 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photo/_initialize/saves_a_reference_to_the_title.yml +95 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photo/image_URLs/generates_an_image_URL_for_a_default_sized_medium_image.yml +95 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photo/image_URLs/generates_an_image_URL_for_a_n-sized_small_320_image.yml +252 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photo/image_URLs/instantiates_a_new_URL_info_object_to_create_image_URLs.yml +95 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_find/fetches_the_photoset_from_Flickr_specified_by_id.yml +65 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_find/instantiates_a_new_Kuva_Elements_Photoset_object.yml +65 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_image_url/generates_an_image_URL_for_a_large_square_image.yml +65 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_image_url/instantiates_a_new_URL_info_object_to_create_an_image_URL.yml +222 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_initialize/returns_itself.yml +65 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_initialize/saves_a_reference_to_the_created_at_date.yml +65 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_initialize/saves_a_reference_to_the_description.yml +65 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_initialize/saves_a_reference_to_the_farm.yml +65 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_initialize/saves_a_reference_to_the_id.yml +65 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_initialize/saves_a_reference_to_the_number_of_photos.yml +65 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_initialize/saves_a_reference_to_the_number_of_views.yml +65 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_initialize/saves_a_reference_to_the_primary_id.yml +222 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_initialize/saves_a_reference_to_the_secret.yml +65 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_initialize/saves_a_reference_to_the_server.yml +65 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_initialize/saves_a_reference_to_the_title.yml +222 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_initialize/saves_a_reference_to_the_updated_at_date.yml +65 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_with_photos/returns_an_array.yml +162 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_with_photos/returns_an_array_with_the_size_specified_by_number_of_photos.yml +162 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_Photoset/_with_photos/wraps_the_photos_into_a_Kuva_Elements_Photo_element.yml +319 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_PhotosetCollection/_photosets/retrieves_all_photosets.yml +2761 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_PhotosetCollection/_photosets/returns_an_array.yml +2918 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_PhotosetCollection/_photosets/wraps_the_photosets_into_a_Kuva_Elements_Photoset_element.yml +2761 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_PhotosetCollection/_retrieve/fetches_all_photosets_from_Flickr.yml +2918 -0
- data/spec/support/vcr/cassettes/Kuva_Elements_PhotosetCollection/_retrieve/instantiates_a_new_Kuva_Elements_PhotosetCollection_object.yml +2761 -0
- data/spec/support/vcr/cassettes/Kuva_PhotosController/_show/assigns_the_photo.yml +314 -0
- data/spec/support/vcr/cassettes/Kuva_PhotosController/_show/finds_the_photo.yml +157 -0
- data/spec/support/vcr/cassettes/Kuva_SetsController/_index/assigns_the_photoset_collection_with_photosets.yml +2761 -0
- data/spec/support/vcr/cassettes/Kuva_SetsController/_index/knows_its_type.yml +2918 -0
- data/spec/support/vcr/cassettes/Kuva_SetsController/_index/retrieves_the_entire_photoset_collection.yml +160 -0
- data/spec/support/vcr/cassettes/Kuva_SetsController/_show/assigns_the_photos_of_the_specified_photoset.yml +2858 -0
- data/spec/support/vcr/cassettes/Kuva_SetsController/_show/finds_the_specified_photoset_within_the_entire_photoset_collection.yml +2858 -0
- data/spec/support/vcr/cassettes/Kuva_SetsController/_show/knows_its_type.yml +2858 -0
- data/spec/support/vcr/cassettes/photo/navigating_back_to_the_photoset_page.yml +3169 -0
- data/spec/support/vcr/cassettes/photo/viewing_the_first_photo_of_the_photoset.yml +157 -0
- data/spec/support/vcr/cassettes/photoset/navigating_back_to_the_photoset_collection_page.yml +5616 -0
- data/spec/support/vcr/cassettes/photoset/navigating_to_the_page_with_details_of_the_first_photo.yml +3012 -0
- data/spec/support/vcr/cassettes/photoset/viewing_the_first_photo_of_the_photoset.yml +314 -0
- data/spec/support/vcr/cassettes/photoset/viewing_the_first_photoset_of_the_photoset_collection.yml +3015 -0
- data/spec/support/vcr/cassettes/photoset_collection/navigating_to_the_page_with_photos_of_the_first_photoset.yml +5616 -0
- data/spec/support/vcr/cassettes/photoset_collection/viewing_the_photoset_collection.yml +2761 -0
- data/spec/support/vcr/vcr.rb +17 -0
- metadata +398 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "generators/kuva/install_generator"
|
3
|
+
|
4
|
+
module Kuva
|
5
|
+
module Generators
|
6
|
+
describe InstallGenerator do
|
7
|
+
destination File.expand_path("../../../../tmp", __FILE__)
|
8
|
+
|
9
|
+
let(:initializer) { file("config/initializers/kuva.rb") }
|
10
|
+
let(:locale) { file("config/locales/kuva.en.yml") }
|
11
|
+
|
12
|
+
before do
|
13
|
+
prepare_destination
|
14
|
+
run_generator
|
15
|
+
end
|
16
|
+
|
17
|
+
it "generates config/initializers/kuva.rb" do
|
18
|
+
expect(initializer).to exist
|
19
|
+
end
|
20
|
+
|
21
|
+
it "generates config/locales/kuva.en.yml" do
|
22
|
+
expect(locale).to exist
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
FileUtils.rm_rf File.expand_path("../../../../tmp", __FILE__)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "generators/kuva/views_generator"
|
3
|
+
|
4
|
+
module Kuva
|
5
|
+
module Generators
|
6
|
+
describe ViewsGenerator do
|
7
|
+
destination File.expand_path("../../../../tmp", __FILE__)
|
8
|
+
|
9
|
+
let(:views_directory) { "app/views/kuva" }
|
10
|
+
|
11
|
+
let(:sets_index) { file("#{views_directory}/sets/index.html.haml") }
|
12
|
+
let(:sets_show) { file("#{views_directory}/sets/show.html.haml") }
|
13
|
+
let(:photos_show) { file("#{views_directory}/photos/show.html.haml") }
|
14
|
+
|
15
|
+
before do
|
16
|
+
prepare_destination
|
17
|
+
run_generator
|
18
|
+
end
|
19
|
+
|
20
|
+
it "generates the app/views/kuva/photos/show.html.haml view" do
|
21
|
+
expect(photos_show).to exist
|
22
|
+
end
|
23
|
+
|
24
|
+
it "generates the app/views/kuva/sets/index.html.haml view" do
|
25
|
+
expect(sets_index).to exist
|
26
|
+
end
|
27
|
+
|
28
|
+
it "generates the app/views/kuva/sets/show.html.haml view" do
|
29
|
+
expect(sets_show).to exist
|
30
|
+
end
|
31
|
+
|
32
|
+
after do
|
33
|
+
FileUtils.rm_rf File.expand_path("../../../../tmp", __FILE__)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Kuva::ApplicationHelper, :vcr do
|
4
|
+
|
5
|
+
describe "#breadcrumbs_for" do
|
6
|
+
let(:photoset_id) { "72157632367381040" }
|
7
|
+
let(:photoset) { Kuva::Elements::Photoset.find photoset_id }
|
8
|
+
|
9
|
+
subject { helper.breadcrumbs_for photoset }
|
10
|
+
|
11
|
+
context "when the current page is the set page" do
|
12
|
+
before { allow(helper).to receive(:photoset_page?).and_return true }
|
13
|
+
|
14
|
+
it "creates a breadcrumb without the set URL" do
|
15
|
+
expect(subject).to eq '<ul class="breadcrumbs"><li><a href="http://test.host/kuva/">Photosets</a></li></ul>'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when the current page is NOT the set page" do
|
20
|
+
it "creates a breadcrumb with the set URL" do
|
21
|
+
expect(subject).to eq '<ul class="breadcrumbs"><li><a href="http://test.host/kuva/">Photosets</a></li><li><a href="http://test.host/kuva/sets/72157632367381040">Paris</a></li></ul>'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Kuva
|
4
|
+
describe Authorizer do
|
5
|
+
|
6
|
+
context ".new" do
|
7
|
+
before do
|
8
|
+
allow(Kuva).to receive(:api_key).and_return "<api_key>"
|
9
|
+
allow(Kuva).to receive(:shared_secret).and_return "<shared_secret>"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "configures the FlickRaw API key" do
|
13
|
+
described_class.new
|
14
|
+
expect(FlickRaw.api_key).to eq "<api_key>"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "configures the FlickRaw shared secret" do
|
18
|
+
described_class.new
|
19
|
+
expect(FlickRaw.shared_secret).to eq "<shared_secret>"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context ".authorize" do
|
24
|
+
it "authorizes" do
|
25
|
+
allow_any_instance_of(Authorizer).to receive :authorize
|
26
|
+
described_class.authorize
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "#authorize" do
|
31
|
+
before do
|
32
|
+
allow(STDIN).to receive(:gets).and_return "<authorization_code>"
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:output) do
|
36
|
+
capture(:stdout) { subject.authorize }
|
37
|
+
end
|
38
|
+
|
39
|
+
context "with a valid authentication code" do
|
40
|
+
before do
|
41
|
+
allow(subject).to receive(:flickr).and_return double.as_null_object
|
42
|
+
end
|
43
|
+
|
44
|
+
it "outputs a notice about the authentication url" do
|
45
|
+
allow(subject).to receive(:authentication_url).and_return "<url>"
|
46
|
+
expect(output).to include "\nCopy the URL below and follow the steps on Flickr to authorize Kuva:\n<url>"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "outputs a notice about the authentication code" do
|
50
|
+
expect(output).to include "\nOnce you've authorized Kuva, you'll receive a code (in the form of xxx-xxx-xxx) from Flickr. Copy and paste that code here and press <enter>:\n"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "outputs a confirmation notice" do
|
54
|
+
allow(Kuva).to receive(:api_key).and_return "<api_key>"
|
55
|
+
allow(Kuva).to receive(:shared_secret).and_return "<shared_secret>"
|
56
|
+
subject.stub_chain(:flickr, :test, :login, :username).and_return "<username>"
|
57
|
+
subject.stub_chain(:flickr, :access_token).and_return "<access_token>"
|
58
|
+
subject.stub_chain(:flickr, :access_secret).and_return "<access_secret>"
|
59
|
+
|
60
|
+
expect(output).to include "\n<username>, you've successfully authorized Kuva with Flickr. As you can see we've received your username. Besides that we've got the following access token '<access_token>' and access secret '<access_secret>'. Both the API key, shared secret and the previously mentioned variables should be saved for later use. They're all listed below. Place them in `config/initializers/kuva.rb` and you're good to go.\n\n\tapi_key: <api_key>\n\tshared_secret: <shared_secret>\n\taccess_token: <access_token>\n\taccess_secret: <access_secret>\n\n"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "with an invalid authentication code" do
|
65
|
+
it "outputs an authentication error" do
|
66
|
+
expect(output).to include "Authentication with Flickr failed: token_rejected"
|
67
|
+
end
|
68
|
+
|
69
|
+
context "with an incorrect API key and shared secret" do
|
70
|
+
before do
|
71
|
+
allow(FlickRaw).to receive(:api_key).and_return "<api_key>"
|
72
|
+
allow(FlickRaw).to receive(:shared_secret).and_return "<shared_secret>"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "raises a failed response error" do
|
76
|
+
expect { flickr.get_access_token("<api_key>", "<shared_secret>", "<authentication_code>") }.to raise_error FlickRaw::OAuthClient::FailedResponse
|
77
|
+
capture(:stdout) { subject.authorize }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
module Kuva
|
5
|
+
module Elements
|
6
|
+
describe Photo, :vcr do
|
7
|
+
|
8
|
+
let(:photo_id) { "8317914535" }
|
9
|
+
|
10
|
+
context "#initialize" do
|
11
|
+
subject { described_class.find photo_id }
|
12
|
+
|
13
|
+
it "saves a reference to the id" do
|
14
|
+
expect(subject.id).to eq "8317914535"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "saves a reference to the title" do
|
18
|
+
expect(subject.title).to eq "Musée du Louvre"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "saves a reference to the description" do
|
22
|
+
expect(subject.description).to eq "These shots were taken in Paris, France in December 2012. Most of them are taken with my Nikon D80 and Nikkor 50mm f/1.8 or Tokina 12-24mm f/4."
|
23
|
+
end
|
24
|
+
|
25
|
+
it "saves a reference to the farm" do
|
26
|
+
expect(subject.farm).to eq 9
|
27
|
+
end
|
28
|
+
|
29
|
+
it "saves a reference to the server" do
|
30
|
+
expect(subject.server).to eq "8217"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "saves a reference to the secret" do
|
34
|
+
expect(subject.secret).to eq "c7393787f3"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "does NOT set the is_primary boolean" do
|
38
|
+
expect(subject.is_primary).to be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns itself" do
|
42
|
+
expect(subject).to be_a Kuva::Elements::Photo
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context ".find" do
|
47
|
+
it "fetches the photo from Flickr specified by id" do
|
48
|
+
expect(flickr.photos).to receive(:getInfo).with(photo_id: photo_id).and_call_original
|
49
|
+
described_class.find photo_id
|
50
|
+
end
|
51
|
+
|
52
|
+
it "instantiates a new #{described_class} object" do
|
53
|
+
expect(described_class).to receive(:new).with(any_args).and_call_original
|
54
|
+
described_class.find photo_id
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "image URLs" do
|
59
|
+
subject { described_class.find photo_id }
|
60
|
+
|
61
|
+
it "instantiates a new URL info object to create image URLs" do
|
62
|
+
expect(Kuva::Elements::UrlInfo).to receive(:new).with(any_args).and_call_original
|
63
|
+
subject.url
|
64
|
+
end
|
65
|
+
|
66
|
+
it "generates an image URL for a default sized (medium) image" do
|
67
|
+
expect(subject.url).to eq "https://farm9.staticflickr.com/8217/8317914535_c7393787f3.jpg"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "generates an image URL for a n-sized (small 320) image" do
|
71
|
+
expect(subject.url_n).to eq "https://farm9.staticflickr.com/8217/8317914535_c7393787f3_n.jpg"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Kuva
|
4
|
+
module Elements
|
5
|
+
describe PhotosetCollection, :vcr do
|
6
|
+
|
7
|
+
describe ".retrieve" do
|
8
|
+
subject { described_class.retrieve }
|
9
|
+
|
10
|
+
it "fetches all photosets from Flickr" do
|
11
|
+
expect(flickr.photosets).to receive(:getList).and_call_original
|
12
|
+
subject
|
13
|
+
end
|
14
|
+
|
15
|
+
it "instantiates a new #{described_class} object" do
|
16
|
+
expect(described_class).to receive(:new).and_call_original
|
17
|
+
subject
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#photosets" do
|
22
|
+
subject { described_class.new.photosets }
|
23
|
+
|
24
|
+
it "retrieves all photosets" do
|
25
|
+
expect(flickr.photosets).to receive(:getList).and_call_original
|
26
|
+
subject
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns an array" do
|
30
|
+
expect(subject).to be_an Array
|
31
|
+
end
|
32
|
+
|
33
|
+
it "wraps the photosets into a Kuva::Elements::Photoset element" do
|
34
|
+
subject.each do |photoset|
|
35
|
+
expect(photoset).to be_a Kuva::Elements::Photoset
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Kuva
|
4
|
+
module Elements
|
5
|
+
describe Photoset, :vcr do
|
6
|
+
|
7
|
+
let(:photoset_id) { "72157632367381040" }
|
8
|
+
|
9
|
+
context "#initialize" do
|
10
|
+
subject { described_class.find photoset_id }
|
11
|
+
|
12
|
+
it "saves a reference to the id" do
|
13
|
+
expect(subject.id).to eq "72157632367381040"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "saves a reference to the title" do
|
17
|
+
expect(subject.title).to eq "Paris"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "saves a reference to the description" do
|
21
|
+
expect(subject.description).to eq "These shots were taken in Paris, France in December 2012. Most of them are taken with my Nikon D80 and Nikkor 50mm f/1.8 or Tokina 12-24mm f/4."
|
22
|
+
end
|
23
|
+
|
24
|
+
it "saves a reference to the number of views" do
|
25
|
+
expect(subject.views).to eq "31"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "saves a reference to the number of photos" do
|
29
|
+
expect(subject.number_of_photos).to eq 28
|
30
|
+
end
|
31
|
+
|
32
|
+
it "saves a reference to the farm" do
|
33
|
+
expect(subject.farm).to eq 9
|
34
|
+
end
|
35
|
+
|
36
|
+
it "saves a reference to the server" do
|
37
|
+
expect(subject.server).to eq "8499"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "saves a reference to the secret" do
|
41
|
+
expect(subject.secret).to eq "eda82f692f"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "saves a reference to the primary id" do
|
45
|
+
expect(subject.primary).to eq "8318972536"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "saves a reference to the created at date" do
|
49
|
+
expect(subject.created_at).to eq "1356715289"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "saves a reference to the updated at date" do
|
53
|
+
expect(subject.updated_at).to eq "1356717162"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns itself" do
|
57
|
+
expect(subject).to be_a Kuva::Elements::Photoset
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context ".find" do
|
62
|
+
it "fetches the photoset from Flickr specified by id" do
|
63
|
+
expect(flickr.photosets).to receive(:getInfo).with(photoset_id: photoset_id).and_call_original
|
64
|
+
described_class.find photoset_id
|
65
|
+
end
|
66
|
+
|
67
|
+
it "instantiates a new #{described_class} object" do
|
68
|
+
expect(described_class).to receive(:new).with(any_args).and_call_original
|
69
|
+
described_class.find photoset_id
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "#with_photos" do
|
74
|
+
subject { described_class.find photoset_id }
|
75
|
+
|
76
|
+
it "returns an array" do
|
77
|
+
expect(subject.with_photos).to be_an Array
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns an array with the size specified by number of photos" do
|
81
|
+
expect(subject.with_photos.size).to eq subject.number_of_photos
|
82
|
+
end
|
83
|
+
|
84
|
+
it "wraps the photos into a Kuva::Elements::Photo element" do
|
85
|
+
subject.with_photos.each do |photo|
|
86
|
+
expect(photo).to be_a Kuva::Elements::Photo
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "#image_url" do
|
92
|
+
subject { described_class.find photoset_id }
|
93
|
+
|
94
|
+
it "instantiates a new URL info object to create an image URL" do
|
95
|
+
expect(Kuva::Elements::UrlInfo).to receive(:new).with(any_args).and_call_original
|
96
|
+
subject.image_url
|
97
|
+
end
|
98
|
+
|
99
|
+
it "generates an image URL for a large square image" do
|
100
|
+
expect(subject.image_url).to eq "https://farm9.staticflickr.com/8499/8318972536_eda82f692f_q.jpg"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Kuva
|
4
|
+
module Elements
|
5
|
+
describe UrlInfo do
|
6
|
+
subject { described_class.new "8317914535", "9", "8217", "c7393787f3" }
|
7
|
+
|
8
|
+
it "knows its id" do
|
9
|
+
expect(subject.id).to eq "8317914535"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "knows its farm" do
|
13
|
+
expect(subject.farm).to eq "9"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "knows its server" do
|
17
|
+
expect(subject.server).to eq "8217"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "knows its secret" do
|
21
|
+
expect(subject.secret).to eq "c7393787f3"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/kuva_spec.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Kuva do
|
4
|
+
|
5
|
+
describe ".setup" do
|
6
|
+
it "yields itself" do
|
7
|
+
Kuva.setup do |config|
|
8
|
+
expect(config).to eq Kuva
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "setup block" do
|
14
|
+
before do
|
15
|
+
@old_api_key = Kuva.api_key
|
16
|
+
@old_shared_secret = Kuva.shared_secret
|
17
|
+
@old_access_token = Kuva.access_token
|
18
|
+
@old_access_secret = Kuva.access_secret
|
19
|
+
@old_cache_expiration = Kuva.cache_expiration
|
20
|
+
end
|
21
|
+
|
22
|
+
it "configures the API key" do
|
23
|
+
Kuva.setup do |config|
|
24
|
+
config.api_key = "kuva-api-key"
|
25
|
+
end
|
26
|
+
|
27
|
+
expect(Kuva.api_key).to eq "kuva-api-key"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "configures the shared secret" do
|
31
|
+
Kuva.setup do |config|
|
32
|
+
config.shared_secret = "super-secret"
|
33
|
+
end
|
34
|
+
|
35
|
+
expect(Kuva.shared_secret).to eq "super-secret"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "configures the access token" do
|
39
|
+
Kuva.setup do |config|
|
40
|
+
config.access_token = "access-token"
|
41
|
+
end
|
42
|
+
|
43
|
+
expect(Kuva.access_token).to eq "access-token"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "configures the access secret" do
|
47
|
+
Kuva.setup do |config|
|
48
|
+
config.access_secret = "secret-access-token"
|
49
|
+
end
|
50
|
+
|
51
|
+
expect(Kuva.access_secret).to eq "secret-access-token"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "configures the cache expiration" do
|
55
|
+
Kuva.setup do |config|
|
56
|
+
config.cache_expiration = "cache-expiration"
|
57
|
+
end
|
58
|
+
|
59
|
+
expect(Kuva.cache_expiration).to eq "cache-expiration"
|
60
|
+
end
|
61
|
+
|
62
|
+
after do
|
63
|
+
Kuva.setup do |config|
|
64
|
+
config.api_key = @old_api_key
|
65
|
+
config.shared_secret = @old_shared_secret
|
66
|
+
config.access_token = @old_access_token
|
67
|
+
config.access_secret = @old_access_secret
|
68
|
+
config.cache_expiration = @old_cache_expiration
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "default configuration" do
|
74
|
+
describe "cache expiration" do
|
75
|
+
it "knows its default cache expiration" do
|
76
|
+
expect(Kuva.cache_expiration).to eq 7.days
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|