7digital 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/README.rdoc +9 -7
  2. data/lib/sevendigital.rb +54 -53
  3. data/lib/sevendigital/api_operator.rb +33 -30
  4. data/lib/sevendigital/api_operator_cached.rb +23 -23
  5. data/lib/sevendigital/api_request.rb +23 -23
  6. data/lib/sevendigital/client.rb +136 -124
  7. data/lib/sevendigital/default_configuration.yml +2 -2
  8. data/lib/sevendigital/digestion_tract/api_response_digestor.rb +52 -52
  9. data/lib/sevendigital/digestion_tract/artist_digestor.rb +31 -31
  10. data/lib/sevendigital/digestion_tract/chart_item_digestor.rb +27 -27
  11. data/lib/sevendigital/digestion_tract/digestor.rb +66 -66
  12. data/lib/sevendigital/digestion_tract/format_digestor.rb +21 -21
  13. data/lib/sevendigital/digestion_tract/label_digestor.rb +19 -19
  14. data/lib/sevendigital/digestion_tract/pager_digestor.rb +23 -23
  15. data/lib/sevendigital/digestion_tract/price_digestor.rb +24 -24
  16. data/lib/sevendigital/digestion_tract/release_digestor.rb +52 -52
  17. data/lib/sevendigital/digestion_tract/track_digestor.rb +37 -37
  18. data/lib/sevendigital/management/artist_manager.rb +45 -39
  19. data/lib/sevendigital/management/manager.rb +11 -11
  20. data/lib/sevendigital/management/release_manager.rb +57 -50
  21. data/lib/sevendigital/management/track_manager.rb +28 -17
  22. data/lib/sevendigital/model/api_response.rb +24 -12
  23. data/lib/sevendigital/model/artist.rb +46 -36
  24. data/lib/sevendigital/model/chart_item.rb +9 -9
  25. data/lib/sevendigital/model/format.rb +9 -9
  26. data/lib/sevendigital/model/label.rb +9 -9
  27. data/lib/sevendigital/model/price.rb +11 -11
  28. data/lib/sevendigital/model/release.rb +33 -33
  29. data/lib/sevendigital/model/sevendigital_error.rb +3 -3
  30. data/lib/sevendigital/model/sevendigital_object.rb +51 -51
  31. data/lib/sevendigital/model/track.rb +28 -7
  32. data/lib/sevendigital/pager.rb +16 -16
  33. data/lib/sevendigital/peachy_patch.rb +19 -0
  34. data/lib/sevendigital/proxy_police.rb +23 -23
  35. data/spec/api_operator_cached_spec.rb +47 -46
  36. data/spec/api_operator_spec.rb +114 -107
  37. data/spec/api_request_spec.rb +26 -27
  38. data/spec/client_spec.rb +75 -45
  39. data/spec/data/config/sevendigital.yml +5 -5
  40. data/spec/data/configuration_env_override.yml +5 -5
  41. data/spec/digestion_tract/api_response_digestor_spec.rb +78 -74
  42. data/spec/digestion_tract/artist_digestor_spec.rb +81 -82
  43. data/spec/digestion_tract/chart_digestor_spec.rb +52 -53
  44. data/spec/digestion_tract/format_digestor_spec.rb +38 -39
  45. data/spec/digestion_tract/label_digestor_spec.rb +33 -34
  46. data/spec/digestion_tract/pager_digestor_spec.rb +50 -51
  47. data/spec/digestion_tract/price_digestor_spec.rb +57 -57
  48. data/spec/digestion_tract/release_digestor_spec.rb +101 -102
  49. data/spec/digestion_tract/track_digestor_spec.rb +104 -106
  50. data/spec/management/artist_manager_spec.rb +128 -107
  51. data/spec/management/release_manager_spec.rb +222 -178
  52. data/spec/management/track_manager_spec.rb +88 -52
  53. data/spec/model/api_response_spec.rb +44 -31
  54. data/spec/model/artist_spec.rb +166 -121
  55. data/spec/model/release_spec.rb +109 -110
  56. data/spec/model/track_spec.rb +140 -0
  57. data/spec/pager_spec.rb +7 -8
  58. data/spec/peachy_spec_helper_patch.rb +7 -0
  59. data/spec/proxy_police_spec.rb +47 -48
  60. data/spec/spec_helper.rb +52 -48
  61. data/spec/test-xml/methods/artist/byTag/top.xml +50 -50
  62. data/spec/test-xml/methods/artist/details.xml +9 -9
  63. data/spec/test-xml/methods/artist/releases.xml +544 -544
  64. data/spec/test-xml/methods/artist/search.xml +19 -0
  65. data/spec/test-xml/methods/artist/similar.xml +39 -39
  66. data/spec/test-xml/methods/artist/toptracks.xml +279 -279
  67. data/spec/test-xml/methods/release/bydate.xml +173 -173
  68. data/spec/test-xml/methods/release/bytag/top.xml +150 -150
  69. data/spec/test-xml/methods/release/chart.xml +181 -181
  70. data/spec/test-xml/methods/release/details.xml +48 -48
  71. data/spec/test-xml/methods/release/recommend.xml +89 -89
  72. data/spec/test-xml/methods/release/search.xml +195 -0
  73. data/spec/test-xml/methods/release/tracks.xml +28 -28
  74. data/spec/test-xml/methods/track/chart.xml +149 -149
  75. data/spec/test-xml/methods/track/details.xml +30 -30
  76. data/spec/test-xml/methods/track/search.xml +160 -0
  77. data/spec/test-xml/objects/artist.xml +6 -6
  78. data/spec/test-xml/objects/artist_chart_item.xml +7 -7
  79. data/spec/test-xml/objects/artist_list.xml +22 -22
  80. data/spec/test-xml/objects/artist_list_empty.xml +4 -4
  81. data/spec/test-xml/objects/price.xml +7 -7
  82. data/spec/test-xml/objects/release.xml +40 -40
  83. data/spec/test-xml/objects/release_chart_item.xml +39 -34
  84. data/spec/test-xml/objects/release_list.xml +18 -18
  85. data/spec/test-xml/objects/release_list_empty.xml +4 -4
  86. data/spec/test-xml/objects/response.xml +39 -0
  87. data/spec/test-xml/objects/track.xml +33 -33
  88. data/spec/test-xml/objects/track_chart_item.xml +27 -27
  89. metadata +10 -5
  90. data/lib/peachy_patchy.rb +0 -14
  91. data/lib/sevendigital/version.rb +0 -3
@@ -0,0 +1,19 @@
1
+ module Peachy
2
+ module MorphIntoArray
3
+ private
4
+
5
+ def array_can? method_name
6
+ (Array.instance_methods - Object.instance_methods).include?( version_safe_method_id(method_name))
7
+ end
8
+ end
9
+ end
10
+
11
+ if RUBY_VERSION < "1.9"
12
+ def version_safe_method_id(method_name)
13
+ method_name.to_s
14
+ end
15
+ else
16
+ def version_safe_method_id(method_name)
17
+ method_name.to_sym
18
+ end
19
+ end
@@ -1,24 +1,24 @@
1
- module Sevendigital
2
- class ProxyPolice
3
-
4
- def ProxyPolice.ensure_is_proxy(xml_or_proxy, element_name)
5
- if xml_or_proxy.kind_of? Peachy::Proxy then
6
- return xml_or_proxy
7
- else
8
- return ProxyPolice.create_release_proxy(xml_or_proxy, element_name)
9
- end
10
- end
11
-
12
- def ProxyPolice.create_release_proxy(xml, element_name)
13
- #TODO don't use eval
14
- parent_proxy = Peachy::Proxy.new(xml)
15
- if element_name
16
- # parent_proxy.send(element_name)
17
- eval "parent_proxy.#{element_name.to_s}"
18
- else
19
- parent_proxy
20
- end
21
- end
22
-
23
- end
1
+ module Sevendigital
2
+ class ProxyPolice
3
+
4
+ def ProxyPolice.ensure_is_proxy(xml_or_proxy, element_name)
5
+ if xml_or_proxy.kind_of? Peachy::Proxy then
6
+ return xml_or_proxy
7
+ else
8
+ return ProxyPolice.create_release_proxy(xml_or_proxy, element_name)
9
+ end
10
+ end
11
+
12
+ def ProxyPolice.create_release_proxy(xml, element_name)
13
+ #TODO don't use eval
14
+ parent_proxy = Peachy::Proxy.new(xml)
15
+ if element_name
16
+ # parent_proxy.send(element_name)
17
+ eval "parent_proxy.#{element_name.to_s}"
18
+ else
19
+ parent_proxy
20
+ end
21
+ end
22
+
23
+ end
24
24
  end
@@ -1,47 +1,48 @@
1
- require "spec"
2
- require 'sevendigital'
3
- require 'ostruct'
4
-
5
- describe "ApiOperatorCached" do
6
-
7
- before do
8
- @client = stub(Sevendigital::Client)
9
- @cache = stub(Hash)
10
- @cached_operator = Sevendigital::ApiOperatorCached.new(@client, @cache)
11
- end
12
-
13
- it "should not make an http request if response already in cache " do
14
- @cached_operator.stub(:create_request_uri).and_return("key")
15
- @cache.stub!(:get).with("key").and_return(:something)
16
- @cached_operator.should_not_receive(:make_http_request_and_digest)
17
- @cached_operator.call_api(@stub_api_request)
18
- end
19
-
20
- it "should make an http request if response not yet in cache and return the result " do
21
- api_response = fake_api_response()
22
-
23
- @cached_operator.stub(:create_request_uri).and_return("key")
24
- @cache.stub!(:get).with("key").and_return(nil)
25
- @cache.stub!(:set).and_return(nil)
26
- @cached_operator.should_receive(:make_http_request_and_digest).with("key").and_return(api_response)
27
-
28
- response = @cached_operator.call_api(@stub_api_request)
29
- response.should == api_response
30
- end
31
-
32
- it "should cache uncached api response" do
33
- api_response = fake_api_response()
34
-
35
- @cached_operator.stub(:create_request_uri).and_return("key")
36
- @cache.stub!(:get).with("key").and_return(nil)
37
- @cached_operator.stub!(:make_http_request_and_digest).and_return(api_response)
38
-
39
- @cache.should_receive(:set).with("key", api_response).and_return(nil)
40
- response = @cached_operator.call_api(@stub_api_request)
41
- end
42
-
43
- def fake_api_response
44
- return Net::HTTP.new("1.1", 200, "response_body")
45
- end
46
-
1
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
2
+ require 'ostruct'
3
+
4
+ describe "ApiOperatorCached" do
5
+
6
+ before do
7
+ @client = stub(Sevendigital::Client)
8
+ @client.stub!(:verbose?).and_return(false)
9
+ @client.stub!(:very_verbose?).and_return(false)
10
+ @cache = stub(Hash)
11
+ @cached_operator = Sevendigital::ApiOperatorCached.new(@client, @cache)
12
+ end
13
+
14
+ it "should not make an http request if response already in cache " do
15
+ @cached_operator.stub(:create_request_uri).and_return("key")
16
+ @cache.stub!(:get).with("key").and_return(:something)
17
+ @cached_operator.should_not_receive(:make_http_request_and_digest)
18
+ @cached_operator.call_api(@stub_api_request)
19
+ end
20
+
21
+ it "should make an http request if response not yet in cache and return the result " do
22
+ api_response = fake_api_response()
23
+
24
+ @cached_operator.stub(:create_request_uri).and_return("key")
25
+ @cache.stub!(:get).with("key").and_return(nil)
26
+ @cache.stub!(:set).and_return(nil)
27
+ @cached_operator.should_receive(:make_http_request_and_digest).with("key").and_return(api_response)
28
+
29
+ response = @cached_operator.call_api(@stub_api_request)
30
+ response.should == api_response
31
+ end
32
+
33
+ it "should cache uncached api response" do
34
+ api_response = fake_api_response()
35
+
36
+ @cached_operator.stub(:create_request_uri).and_return("key")
37
+ @cache.stub!(:get).with("key").and_return(nil)
38
+ @cached_operator.stub!(:make_http_request_and_digest).and_return(api_response)
39
+
40
+ @cache.should_receive(:set).with("key", api_response).and_return(nil)
41
+ response = @cached_operator.call_api(@stub_api_request)
42
+ end
43
+
44
+ def fake_api_response
45
+ return Net::HTTP.new("1.1", 200, "response_body")
46
+ end
47
+
47
48
  end
@@ -1,108 +1,115 @@
1
- require "spec"
2
- require 'sevendigital'
3
- require 'ostruct'
4
-
5
- describe "ApiOperator" do
6
-
7
- before do
8
- response_digestor = stub(Sevendigital::ApiResponseDigestor)
9
- response_digestor.stub!(:from_http_response).and_return(fake_digested_response)
10
-
11
- stub_api_client(test_configuration, response_digestor)
12
-
13
- Net::HTTP.stub!(:get_response).and_return(fake_api_response)
14
-
15
- @api_operator = Sevendigital::ApiOperator.new(@client)
16
-
17
- @stub_api_request = stub_api_request()
18
-
19
- end
20
-
21
- it "should create request URI based on api method and client configuration" do
22
-
23
- api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
24
-
25
- uri = @api_operator.create_request_uri(api_request)
26
-
27
- uri.kind_of?(URI).should == true
28
- uri.to_s.should == "http://base.api.url/version/api/method?oauth_consumer_key=oauth_consumer_key&param1=value&paramTwo=2&country=sk"
29
-
30
- end
31
-
32
- it "should make sure country is set before making request" do
33
- @client.stub!(:country).and_return("sk")
34
-
35
- @stub_api_request.should_receive(:ensure_country_is_set).with("sk")
36
-
37
- @api_operator.call_api(@stub_api_request)
38
-
39
- end
40
-
41
- it "should make HTTP request and get response" do
42
-
43
- Net::HTTP.should_receive(:get_response).with(@api_operator.create_request_uri(@stub_api_request))
44
-
45
- @api_operator.call_api(@stub_api_request)
46
-
47
- end
48
-
49
- it "should digest the HTTP response and get it out" do
50
-
51
- http_response = fake_api_response
52
-
53
- Net::HTTP.stub!(:get_response).and_return(http_response)
54
-
55
- @client.api_response_digestor.should_receive(:from_http_response).with(http_response).and_return(fake_digested_response)
56
-
57
- response = @api_operator.call_api(@stub_api_request)
58
-
59
- response.kind_of?(Peachy::Proxy).should == true
60
- response.to_s.should == fake_digested_response.to_s
61
-
62
- end
63
-
64
- it "should throw an exception if response is not ok" do
65
-
66
- Net::HTTP.stub(:get_response).and_return(fake_api_response)
67
- failed_response = fake_digested_response(false)
68
- @client.api_response_digestor.stub!(:from_http_response).and_return(failed_response)
69
-
70
- running { @api_operator.call_api(@stub_api_request) }.should raise_error Sevendigital::SevendigitalError
71
-
72
- end
73
-
74
- def test_configuration
75
- configuration = OpenStruct.new
76
- configuration.api_url = "base.api.url"
77
- configuration.api_version = "version"
78
- configuration.oauth_consumer_key = "oauth_consumer_key"
79
- return configuration
80
- end
81
-
82
- def fake_api_response(code = 200, body = "response_body")
83
- return Net::HTTP.new("1.1", code, body)
84
- end
85
-
86
- def fake_digested_response(is_ok = true)
87
- proxy = Peachy::Proxy.new('<response status="ok"><content>test</content></response>')
88
- proxy.stub!(:ok?).and_return(is_ok)
89
- proxy
90
- end
91
-
92
- def stub_api_client(configuration, response_digestor)
93
- @client = stub(Sevendigital::Client)
94
- @client.stub!(:configuration).and_return(configuration)
95
- @client.stub!(:api_response_digestor).and_return(response_digestor)
96
- @client.stub!(:country).and_return("sk")
97
- end
98
-
99
- def stub_api_request
100
- api_request = stub(Sevendigital::ApiRequest)
101
-
102
- api_request.stub!(:parameters).and_return({})
103
- api_request.stub!(:api_method).and_return("m")
104
- api_request.stub!(:ensure_country_is_set)
105
- return api_request
106
- end
107
-
1
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
2
+ require 'ostruct'
3
+
4
+ describe "ApiOperator" do
5
+
6
+ before do
7
+ response_digestor = stub(Sevendigital::ApiResponseDigestor)
8
+ response_digestor.stub!(:from_http_response). and_return(fake_digested_response)
9
+
10
+ stub_api_client(test_configuration, response_digestor)
11
+
12
+ Net::HTTP.stub!(:get_response).and_return(fake_api_response)
13
+
14
+ @api_operator = Sevendigital::ApiOperator.new(@client)
15
+
16
+ @stub_api_request = stub_api_request()
17
+
18
+ end
19
+
20
+ it "should create request URI based on api method and client configuration" do
21
+
22
+ api_request = Sevendigital::ApiRequest.new("api/method", {:param1 => "value", :paramTwo => 2})
23
+
24
+ uri = @api_operator.create_request_uri(api_request)
25
+
26
+ uri.kind_of?(URI).should == true
27
+
28
+ uri.to_s.should =~ /http:\/\/base.api.url\/version\/api\/method\?oauth_consumer_key=oauth_consumer_key/
29
+ uri.to_s.should =~ /\&param1=value/
30
+ uri.to_s.should =~ /\&paramTwo=2/
31
+
32
+ end
33
+
34
+ it "should make sure country is set before making request" do
35
+ @client.stub!(:country).and_return("sk")
36
+
37
+ @stub_api_request.should_receive(:ensure_country_is_set).with("sk")
38
+
39
+ @api_operator.call_api(@stub_api_request)
40
+
41
+ end
42
+
43
+ it "should make HTTP request and get response" do
44
+
45
+ Net::HTTP.should_receive(:get_response).with(@api_operator.create_request_uri(@stub_api_request))
46
+
47
+ @api_operator.call_api(@stub_api_request)
48
+
49
+ end
50
+
51
+ it "should digest the HTTP response and get it out" do
52
+
53
+ http_response = fake_api_response
54
+ digested_response = fake_digested_response
55
+
56
+ Net::HTTP.stub!(:get_response).and_return(http_response)
57
+
58
+ @client.api_response_digestor.should_receive(:from_http_response).with(http_response).and_return(digested_response)
59
+
60
+ response = @api_operator.call_api(@stub_api_request)
61
+
62
+ response.should == digested_response
63
+
64
+ end
65
+
66
+ it "should throw an exception if response is not ok" do
67
+
68
+ Net::HTTP.stub(:get_response).and_return(fake_api_response)
69
+ failed_response = fake_digested_response(false)
70
+ failed_response.stub!(:error_code).and_return("4000")
71
+ failed_response.stub!(:error_message).and_return("error")
72
+ @client.api_response_digestor.stub!(:from_http_response).and_return(failed_response)
73
+
74
+ running { @api_operator.call_api(@stub_api_request) }.should raise_error(Sevendigital::SevendigitalError)
75
+
76
+ end
77
+
78
+ def test_configuration
79
+ configuration = OpenStruct.new
80
+ configuration.api_url = "base.api.url"
81
+ configuration.api_version = "version"
82
+ configuration.oauth_consumer_key = "oauth_consumer_key"
83
+ return configuration
84
+ end
85
+
86
+ def fake_api_response(code = 200, body = "response_body")
87
+ return Net::HTTP.new("1.1", code, body)
88
+ end
89
+
90
+ def fake_digested_response(is_ok = true)
91
+ proxy = stub(Peachy::Proxy)#.new('<response status="ok"><content>test</content></response>')
92
+ proxy.stub!(:ok?).and_return(is_ok)
93
+ proxy
94
+ end
95
+
96
+ def stub_api_client(configuration, response_digestor)
97
+ @client = stub(Sevendigital::Client)
98
+ @client.stub!(:configuration).and_return(configuration)
99
+ @client.stub!(:api_response_digestor).and_return(response_digestor)
100
+ @client.stub!(:country).and_return("sk")
101
+ @client.stub!(:verbose?).and_return(false)
102
+ @client.stub!(:very_verbose?).and_return(false)
103
+
104
+ end
105
+
106
+ def stub_api_request
107
+ api_request = stub(Sevendigital::ApiRequest)
108
+
109
+ api_request.stub!(:parameters).and_return({})
110
+ api_request.stub!(:api_method).and_return("m")
111
+ api_request.stub!(:ensure_country_is_set)
112
+ return api_request
113
+ end
114
+
108
115
  end
@@ -1,27 +1,26 @@
1
- require 'spec'
2
- require File.join(File.dirname(__FILE__), %w[spec_helper])
3
-
4
- describe "ApiRequest" do
5
-
6
- it "should merge method parameters and options with parameters taking preference" do
7
-
8
- parameters = {:trackId => 123, :releaseId => 456, :country => "CU"}
9
- options = {:page => 1, :country => "US", :trackId => "SS"}
10
- request = Sevendigital::ApiRequest.new('method', parameters, options)
11
- request.parameters[:trackId].should == 123
12
- request.parameters[:releaseId].should == 456
13
- request.parameters[:country].should == "CU"
14
- request.parameters[:page].should == 1
15
- request.parameters.keys.size.should == 4 # page_size == null
16
-
17
- end
18
-
19
- it "should provide paging parameters in 7digital API format" do
20
-
21
- request = Sevendigital::ApiRequest.new('method', {}, {:page => 5, :per_page => 3 })
22
- request.parameters[:page].should == 5
23
- request.parameters[:pageSize].should == 3
24
-
25
- end
26
-
27
- end
1
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
2
+
3
+ describe "ApiRequest" do
4
+
5
+ it "should merge method parameters and options with parameters taking preference" do
6
+
7
+ parameters = {:trackId => 123, :releaseId => 456, :country => "CU"}
8
+ options = {:page => 1, :country => "US", :trackId => "SS"}
9
+ request = Sevendigital::ApiRequest.new('method', parameters, options)
10
+ request.parameters[:trackId].should == 123
11
+ request.parameters[:releaseId].should == 456
12
+ request.parameters[:country].should == "CU"
13
+ request.parameters[:page].should == 1
14
+ request.parameters.keys.size.should == 4 # page_size == null
15
+
16
+ end
17
+
18
+ it "should provide paging parameters in 7digital API format" do
19
+
20
+ request = Sevendigital::ApiRequest.new('method', {}, {:page => 5, :per_page => 3 })
21
+ request.parameters[:page].should == 5
22
+ request.parameters[:pageSize].should == 3
23
+
24
+ end
25
+
26
+ end
@@ -1,46 +1,76 @@
1
- require "spec"
2
- require File.join(File.dirname(__FILE__), %w[spec_helper])
3
- require 'sevendigital'
4
-
5
- describe "Client" do
6
-
7
- it "should load default configuration" do
8
- client = Sevendigital::Client.new
9
- client.configuration.api_url.should == 'api.7digital.com'
10
- end
11
-
12
- it "should override default configuration with configuration hash" do
13
- client = Sevendigital::Client.new(:api_url => "test-hash.7digital.com")
14
- client.configuration.api_url.should == 'test-hash.7digital.com'
15
- end
16
-
17
- it "should override default configuration with configuration class" do
18
- client = Sevendigital::Client.new(OpenStruct.new(:api_url => "test-openstruct.7digital.com"))
19
- client.configuration.api_url.should == 'test-openstruct.7digital.com'
20
- end
21
-
22
- it "should use simple configuration file" do
23
- client = Sevendigital::Client.new(File.join(File.dirname(__FILE__),"data", "configuration_override.yml"))
24
- client.configuration.api_url.should == 'test-yml-simple.7digital.com'
25
- end
26
-
27
- it "should use environment specific configuration file" do
28
- client = Sevendigital::Client.new(File.join(File.dirname(__FILE__),"data", "configuration_env_override.yml"))
29
- client.configuration.api_url.should == 'test-yml-common.7digital.com'
30
- end
31
-
32
- it "should use environment specific configuration file with environment specific settings" do
33
- Object.const_set(:RAILS_ENV, "development")
34
- client = Sevendigital::Client.new(File.join(File.dirname(__FILE__),"data", "configuration_env_override.yml"))
35
- client.configuration.api_url.should == 'test-yml-development.7digital.com'
36
- Object.instance_eval{ remove_const :RAILS_ENV }
37
- end
38
-
39
- it "should use rails/config/sevendigital configuration as default rails settings" do
40
- Object.const_set(:RAILS_ROOT, File.join(File.dirname(__FILE__),"data"))
41
- client = Sevendigital::Client.new()
42
- client.configuration.api_url.should == 'test-yml-rails-common.7digital.com'
43
- Object.instance_eval{ remove_const :RAILS_ROOT }
44
- end
45
-
1
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
2
+
3
+ describe "Client" do
4
+
5
+ it "should load default configuration" do
6
+ client = Sevendigital::Client.new
7
+ client.configuration.api_url.should == 'api.7digital.com'
8
+ end
9
+
10
+ it "should override default configuration with configuration hash" do
11
+ client = Sevendigital::Client.new(:api_url => "test-hash.7digital.com")
12
+ client.configuration.api_url.should == 'test-hash.7digital.com'
13
+ end
14
+
15
+ it "should override default configuration with configuration class" do
16
+ client = Sevendigital::Client.new(OpenStruct.new(:api_url => "test-openstruct.7digital.com"))
17
+ client.configuration.api_url.should == 'test-openstruct.7digital.com'
18
+ end
19
+
20
+ it "should use simple configuration file" do
21
+ client = Sevendigital::Client.new(File.join(File.dirname(__FILE__),"data", "configuration_override.yml"))
22
+ client.configuration.api_url.should == 'test-yml-simple.7digital.com'
23
+ end
24
+
25
+ it "should use environment specific configuration file" do
26
+ client = Sevendigital::Client.new(File.join(File.dirname(__FILE__),"data", "configuration_env_override.yml"))
27
+ client.configuration.api_url.should == 'test-yml-common.7digital.com'
28
+ end
29
+
30
+ it "should use environment specific configuration file with environment specific settings" do
31
+ Object.const_set(:RAILS_ENV, "development")
32
+ client = Sevendigital::Client.new(File.join(File.dirname(__FILE__),"data", "configuration_env_override.yml"))
33
+ client.configuration.api_url.should == 'test-yml-development.7digital.com'
34
+ Object.instance_eval{ remove_const :RAILS_ENV }
35
+ end
36
+
37
+ it "should use rails/config/sevendigital configuration as default rails settings" do
38
+ Object.const_set(:RAILS_ROOT, File.join(File.dirname(__FILE__),"data"))
39
+ client = Sevendigital::Client.new()
40
+ client.configuration.api_url.should == 'test-yml-rails-common.7digital.com'
41
+ Object.instance_eval{ remove_const :RAILS_ROOT }
42
+ end
43
+
44
+ it "should not be verbose if not told to so" do
45
+ configuration = OpenStruct.new
46
+ client = Sevendigital::Client.new(configuration)
47
+ client.verbose?.should == false
48
+ client.very_verbose?.should == false
49
+ end
50
+
51
+ it "should be verbose if told to be verbose in configuration" do
52
+ configuration = OpenStruct.new
53
+ configuration.verbose = true
54
+ client = Sevendigital::Client.new(configuration)
55
+ client.verbose?.should == true
56
+ client.very_verbose?.should == false
57
+ end
58
+
59
+ it "should be very verbose if told to be very verbose in configruation" do
60
+ configuration = OpenStruct.new
61
+ configuration.verbose = :very_verbose
62
+ client = Sevendigital::Client.new(configuration)
63
+ client.verbose?.should == true
64
+ client.very_verbose?.should == true
65
+ end
66
+
67
+ it "should be verbose if told so" do
68
+ configuration = OpenStruct.new
69
+ configuration.verbose = false
70
+ client = Sevendigital::Client.new(configuration)
71
+ client.verbose = true
72
+ client.verbose?.should == true
73
+ client.very_verbose?.should == false
74
+ end
75
+
46
76
  end