ruby-tmdb 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,158 +1,158 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
2
-
3
- class TmdbTest < Test::Unit::TestCase
4
-
5
- def setup
6
- register_api_url_stubs
7
- end
8
-
9
- test "allows setting of api_key" do
10
- old_api_key = Tmdb.api_key
11
- api_key = "test1234567890"
12
- Tmdb.api_key = api_key
13
- assert_equal Tmdb.api_key, api_key
14
- Tmdb.api_key = old_api_key
15
- end
16
-
17
- test "should return base API url" do
18
- assert_equal "http://api.themoviedb.org/2.1/", Tmdb.base_api_url
19
- end
20
-
21
- test "get url returns a response object" do
22
- test_response = Tmdb.get_url("http://example.com/")
23
- assert_equal 200, test_response.code.to_i
24
- end
25
-
26
- test "getting nonexistent URL returns response object" do
27
- test_response = Tmdb.get_url('http://thisisaurlthatdoesntexist.co.nz')
28
- assert_equal 404, test_response.code.to_i
29
- end
30
-
31
- test "api_call should raise exception if api_key is not set" do
32
- old_api_key = Tmdb.api_key
33
- Tmdb.api_key = ""
34
- assert_raises ArgumentError do
35
- Tmdb.api_call('Movie.search', 'Transformers')
36
- end
37
- Tmdb.api_key = old_api_key
38
- end
39
-
40
- test "should perform Movie.search API call and return array of results" do
41
- movies = Tmdb.api_call('Movie.search', 'Transformers')
42
- assert_kind_of Array, movies
43
- assert movies.length > 1
44
- movies.each do |movie|
45
- assert_kind_of Hash, movie
46
- ["url", "id", "name"].each do |item|
47
- assert movie[item]
48
- end
49
- end
50
- end
51
-
52
- test "should perform Movie.getInfo API call and return array of results" do
53
- movies = Tmdb.api_call('Movie.getInfo', 187)
54
- assert_kind_of Array, movies
55
- assert movies.length == 1
56
- movies.each do |movie|
57
- assert_kind_of Hash, movie
58
- ["url", "id", "name"].each do |item|
59
- assert movie[item]
60
- end
61
- end
62
- end
63
-
64
- test "should perform Movie.imdbLookup API call and return array of results" do
65
- movies = Tmdb.api_call('Movie.imdbLookup', "tt0401792")
66
- assert_kind_of Array, movies
67
- assert movies.length == 1
68
- movies.each do |movie|
69
- assert_kind_of Hash, movie
70
- ["url", "id", "name"].each do |item|
71
- assert movie[item]
72
- end
73
- end
74
- end
75
-
76
- test "should perform Person.getInfo API call and return array of results" do
77
- people = Tmdb.api_call('Person.getInfo', 287)
78
- assert_kind_of Array, people
79
- assert people.length == 1
80
- people.each do |person|
81
- assert_kind_of Hash, person
82
- ["url", "id", "name"].each do |item|
83
- assert person[item]
84
- end
85
- end
86
- end
87
-
88
- test "should perform Person.search API call and return array of results" do
89
- people = Tmdb.api_call('Person.search', "vince")
90
- assert_kind_of Array, people
91
- assert people.length > 1
92
- people.each do |person|
93
- assert_kind_of Hash, person
94
- ["url", "id", "name"].each do |item|
95
- assert person[item]
96
- end
97
- end
98
- end
99
-
100
- test "failed API call should return nil" do
101
- movies = Tmdb.api_call('Movie.blarg', 'Transformers')
102
- assert_kind_of NilClass, movies
103
- assert_nil movies
104
- end
105
-
106
- test "API call that finds no results should return nil" do
107
- movies = Tmdb.api_call('Search.empty', 'Transformers')
108
- assert_kind_of NilClass, movies
109
- assert_nil movies
110
- end
111
-
112
- test "API call cache should not be changed when data altered in the receiving method" do
113
- person = Tmdb.api_call('Person.getInfo', 287)[0]
114
- assert_not_nil person[person.keys[0]]
115
- person[person.keys[0]] = nil
116
- person = Tmdb.api_call('Person.getInfo', 287)[0]
117
- assert_not_nil person[person.keys[0]]
118
- end
119
-
120
- test "data_to_object should create object from nested data structures" do
121
- test_data = {
122
- :test1 => [
123
- 1,2,3,4
124
- ],
125
- :test2 => 1
126
- }
127
- test_object = Tmdb.data_to_object(test_data)
128
- assert_nothing_raised do
129
- assert_equal [1,2,3,4], test_object.test1
130
- assert_equal 1, test_object.test2
131
- end
132
- end
133
-
134
- test "data_to_object should include raw_data method that returns original data" do
135
- test_data = {
136
- :test1 => [1,2,3]
137
- }
138
- test_object = Tmdb.data_to_object(test_data)
139
- assert_equal test_object.raw_data, test_data
140
- end
141
-
142
- test "data_to_object should convert arrays containing images to nicer format" do
143
- test_data = {
144
- "backdrops" => [
145
- {
146
- "image" => {
147
- :test => 1
148
- }
149
- }
150
- ]
151
- }
152
- test_object = Tmdb.data_to_object(test_data)
153
- assert_nothing_raised do
154
- assert_equal 1, test_object.backdrops[0].test
155
- end
156
- end
157
-
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
2
+
3
+ class TmdbTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ register_api_url_stubs
7
+ end
8
+
9
+ test "allows setting of api_key" do
10
+ old_api_key = Tmdb.api_key
11
+ api_key = "test1234567890"
12
+ Tmdb.api_key = api_key
13
+ assert_equal Tmdb.api_key, api_key
14
+ Tmdb.api_key = old_api_key
15
+ end
16
+
17
+ test "should return base API url" do
18
+ assert_equal "http://api.themoviedb.org/2.1/", Tmdb.base_api_url
19
+ end
20
+
21
+ test "get url returns a response object" do
22
+ test_response = Tmdb.get_url("http://example.com/")
23
+ assert_equal 200, test_response.code.to_i
24
+ end
25
+
26
+ test "getting nonexistent URL returns response object" do
27
+ test_response = Tmdb.get_url('http://thisisaurlthatdoesntexist.co.nz')
28
+ assert_equal 404, test_response.code.to_i
29
+ end
30
+
31
+ test "api_call should raise exception if api_key is not set" do
32
+ old_api_key = Tmdb.api_key
33
+ Tmdb.api_key = ""
34
+ assert_raises ArgumentError do
35
+ Tmdb.api_call('Movie.search', 'Transformers')
36
+ end
37
+ Tmdb.api_key = old_api_key
38
+ end
39
+
40
+ test "should perform Movie.search API call and return array of results" do
41
+ movies = Tmdb.api_call('Movie.search', 'Transformers')
42
+ assert_kind_of Array, movies
43
+ assert movies.length > 1
44
+ movies.each do |movie|
45
+ assert_kind_of Hash, movie
46
+ ["url", "id", "name"].each do |item|
47
+ assert movie[item]
48
+ end
49
+ end
50
+ end
51
+
52
+ test "should perform Movie.getInfo API call and return array of results" do
53
+ movies = Tmdb.api_call('Movie.getInfo', 187)
54
+ assert_kind_of Array, movies
55
+ assert movies.length == 1
56
+ movies.each do |movie|
57
+ assert_kind_of Hash, movie
58
+ ["url", "id", "name"].each do |item|
59
+ assert movie[item]
60
+ end
61
+ end
62
+ end
63
+
64
+ test "should perform Movie.imdbLookup API call and return array of results" do
65
+ movies = Tmdb.api_call('Movie.imdbLookup', "tt0401792")
66
+ assert_kind_of Array, movies
67
+ assert movies.length == 1
68
+ movies.each do |movie|
69
+ assert_kind_of Hash, movie
70
+ ["url", "id", "name"].each do |item|
71
+ assert movie[item]
72
+ end
73
+ end
74
+ end
75
+
76
+ test "should perform Person.getInfo API call and return array of results" do
77
+ people = Tmdb.api_call('Person.getInfo', 287)
78
+ assert_kind_of Array, people
79
+ assert people.length == 1
80
+ people.each do |person|
81
+ assert_kind_of Hash, person
82
+ ["url", "id", "name"].each do |item|
83
+ assert person[item]
84
+ end
85
+ end
86
+ end
87
+
88
+ test "should perform Person.search API call and return array of results" do
89
+ people = Tmdb.api_call('Person.search', "vince")
90
+ assert_kind_of Array, people
91
+ assert people.length > 1
92
+ people.each do |person|
93
+ assert_kind_of Hash, person
94
+ ["url", "id", "name"].each do |item|
95
+ assert person[item]
96
+ end
97
+ end
98
+ end
99
+
100
+ test "failed API call should return nil" do
101
+ movies = Tmdb.api_call('Movie.blarg', 'Transformers')
102
+ assert_kind_of NilClass, movies
103
+ assert_nil movies
104
+ end
105
+
106
+ test "API call that finds no results should return nil" do
107
+ movies = Tmdb.api_call('Search.empty', 'Transformers')
108
+ assert_kind_of NilClass, movies
109
+ assert_nil movies
110
+ end
111
+
112
+ test "API call cache should not be changed when data altered in the receiving method" do
113
+ person = Tmdb.api_call('Person.getInfo', 287)[0]
114
+ assert_not_nil person[person.keys[0]]
115
+ person[person.keys[0]] = nil
116
+ person = Tmdb.api_call('Person.getInfo', 287)[0]
117
+ assert_not_nil person[person.keys[0]]
118
+ end
119
+
120
+ test "data_to_object should create object from nested data structures" do
121
+ test_data = {
122
+ :test1 => [
123
+ 1,2,3,4
124
+ ],
125
+ :test2 => 1
126
+ }
127
+ test_object = Tmdb.data_to_object(test_data)
128
+ assert_nothing_raised do
129
+ assert_equal [1,2,3,4], test_object.test1
130
+ assert_equal 1, test_object.test2
131
+ end
132
+ end
133
+
134
+ test "data_to_object should include raw_data method that returns original data" do
135
+ test_data = {
136
+ :test1 => [1,2,3]
137
+ }
138
+ test_object = Tmdb.data_to_object(test_data)
139
+ assert_equal test_object.raw_data, test_data
140
+ end
141
+
142
+ test "data_to_object should convert arrays containing images to nicer format" do
143
+ test_data = {
144
+ "backdrops" => [
145
+ {
146
+ "image" => {
147
+ :test => 1
148
+ }
149
+ }
150
+ ]
151
+ }
152
+ test_object = Tmdb.data_to_object(test_data)
153
+ assert_nothing_raised do
154
+ assert_equal 1, test_object.backdrops[0].test
155
+ end
156
+ end
157
+
158
158
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Aaron Gough
@@ -14,27 +14,27 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-20 00:00:00 -04:00
17
+ date: 2010-08-23 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: deepopenstruct
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
24
  requirements:
26
25
  - - ">="
27
26
  - !ruby/object:Gem::Version
28
27
  segments:
29
28
  - 0
30
- version: "0"
29
+ - 1
30
+ - 2
31
+ version: 0.1.2
31
32
  type: :runtime
32
33
  version_requirements: *id001
33
34
  - !ruby/object:Gem::Dependency
34
35
  name: webmock
35
36
  prerelease: false
36
37
  requirement: &id002 !ruby/object:Gem::Requirement
37
- none: false
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
@@ -93,7 +93,6 @@ rdoc_options:
93
93
  require_paths:
94
94
  - lib
95
95
  required_ruby_version: !ruby/object:Gem::Requirement
96
- none: false
97
96
  requirements:
98
97
  - - ">="
99
98
  - !ruby/object:Gem::Version
@@ -101,7 +100,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
100
  - 0
102
101
  version: "0"
103
102
  required_rubygems_version: !ruby/object:Gem::Requirement
104
- none: false
105
103
  requirements:
106
104
  - - ">="
107
105
  - !ruby/object:Gem::Version
@@ -111,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
109
  requirements: []
112
110
 
113
111
  rubyforge_project:
114
- rubygems_version: 1.3.7
112
+ rubygems_version: 1.3.6
115
113
  signing_key:
116
114
  specification_version: 3
117
115
  summary: An ActiveRecord-style API wrapper for TheMovieDB.org