enceladus 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/enceladus.gemspec +2 -0
- data/lib/enceladus/configuration/image.rb +1 -0
- data/lib/enceladus/exceptions.rb +8 -1
- data/lib/enceladus/logger.rb +57 -0
- data/lib/enceladus/models/movie.rb +4 -3
- data/lib/enceladus/models/production_company.rb +49 -1
- data/lib/enceladus/models/production_company_collection.rb +3 -0
- data/lib/enceladus/requester.rb +13 -2
- data/lib/enceladus/version.rb +1 -1
- data/lib/enceladus.rb +3 -1
- data/spec/enceladus/configuration/api_spec.rb +11 -2
- data/spec/enceladus/configuration/image_spec.rb +7 -1
- data/spec/enceladus/enceladus_spec.rb +1 -1
- data/spec/enceladus/logger_spec.rb +45 -0
- data/spec/enceladus/models/account_spec.rb +13 -25
- data/spec/enceladus/models/cast_spec.rb +1 -1
- data/spec/enceladus/models/guest_account_spec.rb +1 -1
- data/spec/enceladus/models/movie_collection_spec.rb +7 -13
- data/spec/enceladus/models/movie_spec.rb +20 -19
- data/spec/enceladus/models/production_company_spec.rb +118 -0
- data/spec/enceladus/requester_spec.rb +16 -0
- data/spec/factories/accounts.rb +10 -0
- data/spec/factories/authentications.rb +6 -0
- data/spec/factories/certifications.rb +9 -0
- data/spec/factories/configurations.rb +34 -0
- data/spec/factories/credits.rb +11 -0
- data/spec/factories/credits_collection.rb +6 -0
- data/spec/factories/errors.rb +6 -0
- data/spec/factories/genres.rb +6 -0
- data/spec/factories/guest_accounts.rb +9 -0
- data/spec/factories/movie_collection_resources.rb +16 -0
- data/spec/factories/movie_collections.rb +8 -0
- data/spec/factories/movies.rb +31 -0
- data/spec/factories/movies_production_companies.rb +6 -0
- data/spec/factories/production_companies.rb +11 -0
- data/spec/factories/production_company_collection_resources.rb +9 -0
- data/spec/factories/production_company_collections.rb +8 -0
- data/spec/factories/production_countries.rb +6 -0
- data/spec/factories/request_tokens.rb +9 -0
- data/spec/factories/sessions.rb +8 -0
- data/spec/factories/spoken_languages.rb +6 -0
- data/spec/factories/youtube_trailers.rb +8 -0
- data/spec/spec_helper.rb +14 -5
- data/spec/support/api_resource.rb +25 -0
- data/spec/support/responses/collection_response.rb +18 -0
- data/spec/support/responses/movie_collection_response.rb +2 -16
- data/spec/support/responses/production_company_collection_resource_response.rb +22 -0
- data/spec/support/responses/production_company_collection_response.rb +6 -0
- data/spec/support/responses/production_company_response.rb +29 -0
- metadata +102 -2
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Enceladus::ProductionCompany do
|
4
|
+
before do
|
5
|
+
stub_request(:get, /api.themoviedb.org\/3\/configuration/).to_return(status: 200, body: build(:configuration_response).to_json)
|
6
|
+
Enceladus.connect("token") # start configuration with default values
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".find_by_name" do
|
10
|
+
subject(:companies) { Enceladus::ProductionCompany.find_by_name("marvel") }
|
11
|
+
let(:collection_response) { build(:production_company_collection_response) }
|
12
|
+
let(:company_from_response) { collection_response.results.first }
|
13
|
+
|
14
|
+
before do
|
15
|
+
stub_request(:get, "https://api.themoviedb.org/3/search/company?api_key=token&page=1&query=marvel").
|
16
|
+
to_return(status: 200, body: collection_response.to_json)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return a Enceladus::ProductionCompanyCollection" do
|
20
|
+
is_expected.to be_kind_of Enceladus::ProductionCompanyCollection
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should fetch company details" do
|
24
|
+
company = companies.first
|
25
|
+
expect(company.id).to eq company_from_response.id
|
26
|
+
expect(company.logo_path).to eq company_from_response.logo_path
|
27
|
+
expect(company.name).to eq company_from_response.name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".find" do
|
32
|
+
subject(:company) { Enceladus::ProductionCompany.find(123) }
|
33
|
+
let(:company_from_response) { build(:production_company_response) }
|
34
|
+
before do
|
35
|
+
stub_request(:get, "https://api.themoviedb.org/3/company/123?api_key=token&append_to_response=description,headquarters,homepage,id,logo_path,name&language=en").
|
36
|
+
to_return(status: 200, body: company_from_response.to_json)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return Enceladus::ProductionCompany" do
|
40
|
+
is_expected.to be_kind_of(Enceladus::ProductionCompany)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should fetch company details" do
|
44
|
+
expect(company.description).to eq company_from_response.description
|
45
|
+
expect(company.headquarters).to eq company_from_response.headquarters
|
46
|
+
expect(company.homepage).to eq company_from_response.homepage
|
47
|
+
expect(company.id).to eq company_from_response.id
|
48
|
+
expect(company.logo_path).to eq company_from_response.logo_path
|
49
|
+
expect(company.name).to eq company_from_response.name
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#logo_urls" do
|
54
|
+
subject { company.logo_urls }
|
55
|
+
let(:company) { Enceladus::ProductionCompany.new }
|
56
|
+
|
57
|
+
before do
|
58
|
+
company.logo_path = "/pic.png"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "shold return an array containing the absolute logo urls" do
|
62
|
+
is_expected.to include *["http://test.com/w45/pic.png", "http://test.com/w92/pic.png", "http://test.com/w154/pic.png", "http://test.com/w185/pic.png", "http://test.com/w300/pic.png", "http://test.com/w500/pic.png", "http://test.com/original/pic.png"]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#reload" do
|
67
|
+
subject(:reload) { company.reload }
|
68
|
+
let(:company) { Enceladus::ProductionCompany.new }
|
69
|
+
let(:company_from_response) { build(:production_company_response, id: company.id) }
|
70
|
+
|
71
|
+
before do
|
72
|
+
company.id = 123
|
73
|
+
stub_request(:get, "https://api.themoviedb.org/3/company/#{company.id}?api_key=token&append_to_response=description,headquarters,homepage,id,logo_path,name&language=en").
|
74
|
+
to_return(status: 200, body: company_from_response.to_json)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should fetch company details" do
|
78
|
+
reload
|
79
|
+
expect(company.description).to eq company_from_response.description
|
80
|
+
expect(company.headquarters).to eq company_from_response.headquarters
|
81
|
+
expect(company.homepage).to eq company_from_response.homepage
|
82
|
+
expect(company.id).to eq company_from_response.id
|
83
|
+
expect(company.logo_path).to eq company_from_response.logo_path
|
84
|
+
expect(company.name).to eq company_from_response.name
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#movies" do
|
89
|
+
subject(:movies) { company.movies }
|
90
|
+
let(:company) { Enceladus::ProductionCompany.new }
|
91
|
+
let(:response) { build(:movie_collection_response) }
|
92
|
+
let(:movie_from_response) { response.results.first }
|
93
|
+
|
94
|
+
before do
|
95
|
+
company.id = 123
|
96
|
+
stub_request(:get, "https://api.themoviedb.org/3/company/#{company.id}/movies?api_key=token&append_to_response=releases,trailers&include_adult=false&include_image_language=en&language=en&page=1").
|
97
|
+
to_return(status: 200, body: response.to_json)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return a Enceladus::MovieCollection" do
|
101
|
+
is_expected.to be_kind_of Enceladus::MovieCollection
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should fetch movie details" do
|
105
|
+
movie = movies.first
|
106
|
+
expect(movie.adult).to eq movie_from_response.adult
|
107
|
+
expect(movie.backdrop_path).to eq movie_from_response.backdrop_path
|
108
|
+
expect(movie.id).to eq movie_from_response.id
|
109
|
+
expect(movie.original_title).to eq movie_from_response.original_title
|
110
|
+
expect(movie.release_date).to eq movie_from_response.release_date
|
111
|
+
expect(movie.poster_path).to eq movie_from_response.poster_path
|
112
|
+
expect(movie.popularity).to eq movie_from_response.popularity
|
113
|
+
expect(movie.title).to eq movie_from_response.title
|
114
|
+
expect(movie.vote_average).to eq movie_from_response.vote_average
|
115
|
+
expect(movie.vote_count).to eq movie_from_response.vote_count
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Enceladus::Requester do
|
4
|
+
# Other requester methods are covered by other tests that fetch TMDb API resources, such as Movies, Cast, Genres, etc.
|
5
|
+
describe "response parse error" do
|
6
|
+
subject { Enceladus::Requester.get("/movie") }
|
7
|
+
|
8
|
+
before do
|
9
|
+
stub_request(:get, /api.themoviedb.org\/movie/).to_return(status: 200, body: "")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise error Enceladus::Exception::JsonParseError" do
|
13
|
+
expect{ subject }.to raise_error Enceladus::Exception::JsonParseError
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class FactoryConfigurationResponse < ApiResource
|
2
|
+
attr_accessor :base_url, :secure_base_url, :backdrop_sizes, :logo_sizes, :poster_sizes, :profile_sizes, :still_sizes, :change_keys
|
3
|
+
|
4
|
+
def to_json
|
5
|
+
{
|
6
|
+
images: {
|
7
|
+
base_url: base_url,
|
8
|
+
secure_base_url: secure_base_url,
|
9
|
+
backdrop_sizes: backdrop_sizes,
|
10
|
+
logo_sizes: logo_sizes,
|
11
|
+
poster_sizes: poster_sizes,
|
12
|
+
profile_sizes: profile_sizes,
|
13
|
+
still_sizes: still_sizes
|
14
|
+
},
|
15
|
+
change_keys: change_keys
|
16
|
+
}.to_json
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
FactoryGirl.define do
|
21
|
+
factory :configuration_response, class: FactoryConfigurationResponse do
|
22
|
+
base_url "http://test.com/"
|
23
|
+
secure_base_url "https://test.com/"
|
24
|
+
backdrop_sizes [ "w300", "w780", "w1280", "original" ]
|
25
|
+
logo_sizes [ "w45", "w92", "w154", "w185", "w300", "w500", "original" ]
|
26
|
+
poster_sizes [ "w92", "w154", "w185", "w342", "w500", "w780", "original" ]
|
27
|
+
profile_sizes [ "w45", "w185", "h632", "original" ]
|
28
|
+
still_sizes [ "w92", "w185", "w300", "original" ]
|
29
|
+
change_keys [ "adult", "also_known_as", "alternative_titles", "biography", "birthday", "budget", "cast",
|
30
|
+
"character_names", "crew", "deathday", "general", "genres", "homepage", "images", "imdb_id", "name", "original_title",
|
31
|
+
"overview", "plot_keywords", "production_companies", "production_countries", "releases", "revenue", "runtime",
|
32
|
+
"spoken_languages", "status", "tagline", "title", "trailers", "translations" ]
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :credits_response, class: ApiResource do
|
3
|
+
cast_id { rand(10) }
|
4
|
+
character { Faker::Lorem.word }
|
5
|
+
credit_id { "#{rand(999999)}" }
|
6
|
+
id { rand(1000) }
|
7
|
+
name { Faker::Name.name }
|
8
|
+
order { rand(10) }
|
9
|
+
profile_path { "/#{rand(99999)}.png" }
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
FactoryGirl.define do
|
4
|
+
factory :movie_collection_resource_response, class: ApiResource do
|
5
|
+
adult false
|
6
|
+
backdrop_path { "/#{Faker::Name.name}.png" }
|
7
|
+
id { rand(1000) }
|
8
|
+
original_title { Faker::Lorem.sentence }
|
9
|
+
release_date { (Date.new - rand(10)).to_s }
|
10
|
+
poster_path { "/#{Faker::Name.name}.png" }
|
11
|
+
popularity { rand * 10 }
|
12
|
+
title { Faker::Lorem.sentence }
|
13
|
+
vote_average { rand * 10 }
|
14
|
+
vote_count { rand(9999) }
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
FactoryGirl.define do
|
4
|
+
factory :movie_response, class: ApiResource do
|
5
|
+
adult false
|
6
|
+
backdrop_path { "/#{Faker::Name.name}.png" }
|
7
|
+
belongs_to_collection nil
|
8
|
+
budget { rand(99999999) }
|
9
|
+
genres { [ build(:genre_response) ] }
|
10
|
+
homepage { Faker::Internet.url }
|
11
|
+
id { rand(9999) }
|
12
|
+
imdb_id { "tt#{rand(9999999)}" }
|
13
|
+
original_title { Faker::Lorem.sentence }
|
14
|
+
overview { Faker::Lorem.sentence }
|
15
|
+
popularity { rand * 10 }
|
16
|
+
poster_path { "/#{Faker::Name.name}.png" }
|
17
|
+
production_companies { [ build(:movies_production_company_response) ] }
|
18
|
+
production_countries { [ build(:production_country_response) ] }
|
19
|
+
release_date { (Date.new - rand(10)).to_s }
|
20
|
+
revenue { rand(9999999) }
|
21
|
+
runtime { rand(999) }
|
22
|
+
spoken_languages { [ build(:spoken_language_response) ] }
|
23
|
+
status "Released"
|
24
|
+
tagline { Faker::Lorem.sentence }
|
25
|
+
title { Faker::Lorem.sentence }
|
26
|
+
vote_average { rand * 10 }
|
27
|
+
vote_count { rand(9999) }
|
28
|
+
releases { { countries: [ build(:certification_response) ] } }
|
29
|
+
trailers { { youtube: [ build(:youtube_trailer_response) ] } }
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :production_company_response, class: ApiResource do
|
3
|
+
description { Faker::Lorem.sentence }
|
4
|
+
headquarters { Faker::Address.street_address }
|
5
|
+
homepage { Faker::Internet.url }
|
6
|
+
id { rand(1000) }
|
7
|
+
logo_path { "/#{Faker::Name.name}.png" }
|
8
|
+
name { Faker::Company.name }
|
9
|
+
parent_company { Faker::Company.name }
|
10
|
+
end
|
11
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "codeclimate-test-reporter"
|
2
|
-
|
2
|
+
SimpleCov.start do
|
3
|
+
formatter SimpleCov::Formatter::MultiFormatter[SimpleCov::Formatter::HTMLFormatter,CodeClimate::TestReporter::Formatter]
|
3
4
|
add_filter "/support/responses"
|
4
5
|
end
|
5
6
|
|
@@ -8,15 +9,23 @@ require 'json'
|
|
8
9
|
require 'webmock/rspec'
|
9
10
|
require 'byebug'
|
10
11
|
require 'enceladus'
|
12
|
+
require 'factory_girl'
|
13
|
+
require 'faker'
|
14
|
+
require File.dirname(__FILE__) + "/support/api_resource"
|
11
15
|
|
12
|
-
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.mock_with :rspec
|
13
18
|
|
14
|
-
|
15
|
-
|
19
|
+
config.include FactoryGirl::Syntax::Methods
|
20
|
+
FactoryGirl.find_definitions
|
16
21
|
|
17
22
|
WebMock.disable_net_connect!(allow: "codeclimate.com")
|
18
23
|
|
19
|
-
|
24
|
+
config.before do |example|
|
20
25
|
Enceladus::Configuration::Api.instance.send(:api_key=, "token")
|
26
|
+
|
27
|
+
unless example.metadata[:logger_test]
|
28
|
+
Enceladus::Logger.logger_output = nil
|
29
|
+
end
|
21
30
|
end
|
22
31
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class ApiResource < OpenStruct
|
2
|
+
def to_h
|
3
|
+
hashfied_resource = super
|
4
|
+
|
5
|
+
hashfied_resource.keys.each do |attr|
|
6
|
+
if self.send(attr).kind_of?(ApiResource)
|
7
|
+
hashfied_resource[attr] = hashfied_resource[attr].to_h
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
hashfied_resource
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_json(*args)
|
15
|
+
jsonfied_resource = to_h
|
16
|
+
|
17
|
+
jsonfied_resource.keys.each do |attr|
|
18
|
+
if self.send(attr).kind_of?(ApiResource)
|
19
|
+
jsonfied_resource[attr] = jsonfied_resource[attr].to_h
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
jsonfied_resource.to_json(args)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CollectionResponse
|
2
|
+
attr_accessor :results, :page, :total_pages, :total_results
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
self.page = 1
|
6
|
+
self.total_pages = 1
|
7
|
+
self.total_results = results.size
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_json
|
11
|
+
{
|
12
|
+
page: page,
|
13
|
+
results: results.map(&:to_hash),
|
14
|
+
total_pages: total_pages,
|
15
|
+
total_results: total_results
|
16
|
+
}.to_json
|
17
|
+
end
|
18
|
+
end
|
@@ -1,20 +1,6 @@
|
|
1
|
-
class MovieCollectionResponse
|
2
|
-
|
3
|
-
attr_accessor :results, :page, :total_pages, :total_results
|
4
|
-
|
1
|
+
class MovieCollectionResponse < CollectionResponse
|
5
2
|
def initialize
|
6
3
|
self.results = [MovieCollectionResourceResponse.new]
|
7
|
-
|
8
|
-
self.total_pages = 1
|
9
|
-
self.total_results = results.size
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_json
|
13
|
-
{
|
14
|
-
page: page,
|
15
|
-
results: results.map(&:to_hash),
|
16
|
-
total_pages: total_pages,
|
17
|
-
total_results: total_results
|
18
|
-
}.to_json
|
4
|
+
super
|
19
5
|
end
|
20
6
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class ProductionCompanyCollectionResourceResponse
|
2
|
+
|
3
|
+
attr_accessor :id, :logo_path, :name
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.id = 34
|
7
|
+
self.logo_path = "/56VlAu08MIE926dQNfBcUwTY8np.png"
|
8
|
+
self.name = "Sony Pictures"
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_hash
|
12
|
+
{
|
13
|
+
id: id,
|
14
|
+
logo_path: logo_path,
|
15
|
+
name: name
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_json
|
20
|
+
to_hash.to_json
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class ProductionCompanyResponse
|
2
|
+
attr_accessor :description, :headquarters, :homepage, :id, :logo_path, :name, :parent_company
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
self.description = "This is a sample description"
|
6
|
+
self.headquarters = "San Francisco, California"
|
7
|
+
self.homepage = "http://github.com/enceladus"
|
8
|
+
self.id = 123
|
9
|
+
self.logo_path = "/pic.jpg"
|
10
|
+
self.name = "Super Company"
|
11
|
+
self.parent_company = "My Parent Company"
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_hash
|
15
|
+
{
|
16
|
+
description: description,
|
17
|
+
headquarters: headquarters,
|
18
|
+
homepage: homepage,
|
19
|
+
id: id,
|
20
|
+
logo_path: logo_path,
|
21
|
+
name: name,
|
22
|
+
parent_company: parent_company,
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_json
|
27
|
+
to_hash.to_json
|
28
|
+
end
|
29
|
+
end
|