scene7-wrapper 0.1.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 (39) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +19 -0
  5. data/Gemfile.lock +64 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.rdoc +24 -0
  8. data/Rakefile +28 -0
  9. data/VERSION +1 -0
  10. data/lib/scene7/asset.rb +104 -0
  11. data/lib/scene7/client.rb +56 -0
  12. data/lib/scene7/company.rb +29 -0
  13. data/lib/scene7/config.rb +33 -0
  14. data/lib/scene7/crop.rb +24 -0
  15. data/lib/scene7/folder.rb +60 -0
  16. data/lib/scene7-wrapper.rb +9 -0
  17. data/scene7-wrapper.gemspec +119 -0
  18. data/spec/file_fixtures/fpo.jpg +0 -0
  19. data/spec/fixtures/create_folder/folder.xml +8 -0
  20. data/spec/fixtures/delete_asset/success.xml +1 -0
  21. data/spec/fixtures/delete_folder/empty_response.xml +6 -0
  22. data/spec/fixtures/get_assets/all_assets.xml +1 -0
  23. data/spec/fixtures/get_assets_by_name/hat_asset.xml +4 -0
  24. data/spec/fixtures/get_assets_by_name/jacket_asset.xml +1 -0
  25. data/spec/fixtures/get_assets_by_name/zero_found.xml +1 -0
  26. data/spec/fixtures/get_company_info/company.xml +13 -0
  27. data/spec/fixtures/get_company_info/test_request.xml +1 -0
  28. data/spec/fixtures/get_folders/folders.xml +26 -0
  29. data/spec/fixtures/rename_asset/failure.xml +1 -0
  30. data/spec/fixtures/rename_asset/success.xml +1 -0
  31. data/spec/fixtures/submit_job/upload_urls_job_response.xml +7 -0
  32. data/spec/scene7/asset_spec.rb +195 -0
  33. data/spec/scene7/client_spec.rb +91 -0
  34. data/spec/scene7/company_spec.rb +63 -0
  35. data/spec/scene7/config_spec.rb +77 -0
  36. data/spec/scene7/crop_spec.rb +62 -0
  37. data/spec/scene7/folder_spec.rb +115 -0
  38. data/spec/spec_helper.rb +16 -0
  39. metadata +283 -0
@@ -0,0 +1,13 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soapenv:Body>
4
+ <getCompanyInfoReturn xmlns="http://www.scene7.com/IpsApi/xsd/2010-01-31">
5
+ <companyInfo>
6
+ <companyHandle>111</companyHandle>
7
+ <name>Example.com</name>
8
+ <rootPath>Example.com/</rootPath>
9
+ <expires>2100-12-31T23:00:00.000-06:00</expires>
10
+ </companyInfo>
11
+ </getCompanyInfoReturn>
12
+ </soapenv:Body>
13
+ </soapenv:Envelope>
@@ -0,0 +1 @@
1
+ <myxml />
@@ -0,0 +1,26 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soapenv:Body>
4
+ <getFoldersReturn xmlns="http://www.scene7.com/IpsApi/xsd/2010-01-31">
5
+ <folderArray>
6
+
7
+ <items>
8
+ <folderHandle>handle-1</folderHandle>
9
+ <path>folder-path-1</path>
10
+ <lastModified>20080726T08:36:19.19305:00</lastModified>
11
+ <childLastModified>20110308T18:43:20.92706:00</childLastModified>
12
+ <hasSubfolders>true</hasSubfolders>
13
+ </items>
14
+
15
+ <items>
16
+ <folderHandle>handle-2</folderHandle>
17
+ <path>folder-path-2</path>
18
+ <lastModified>20110225T13:45:53.55306:00</lastModified>
19
+ <childLastModified>20110309T21:49:58.21606:00</childLastModified>
20
+ <hasSubfolders>false</hasSubfolders>
21
+ </items>
22
+
23
+ </folderArray>
24
+ </getFoldersReturn>
25
+ </soapenv:Body>
26
+ </soapenv:Envelope>
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server</faultcode><faultstring>ipsApiFault</faultstring><detail><tns:ipsApiFault xmlns:tns="http://www.scene7.com/IpsApi/xsd"><tns:code>30000</tns:code><tns:reason>Asset ID 'katlynf' is already in use.</tns:reason></tns:ipsApiFault></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><renameAssetReturn xmlns="http://www.scene7.com/IpsApi/xsd/2010-01-31" /></soapenv:Body></soapenv:Envelope>
@@ -0,0 +1,7 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <soapenv:Body><submitJobReturn xmlns="http://www.scene7.com/IpsApi/xsd/2010-01-31">
4
+ <jobHandle>j|110|katlyn||</jobHandle>
5
+ </submitJobReturn>
6
+ </soapenv:Body>
7
+ </soapenv:Envelope>
@@ -0,0 +1,195 @@
1
+ require 'spec_helper'
2
+
3
+ describe Scene7::Asset do
4
+ subject { Scene7::Asset }
5
+ let(:valid_config) { {:subdomain => 'test-instance', :user => 'test@example.com', :password => 'password', :app_name => 'MyAppName', :app_version => '1.2' } }
6
+
7
+ describe "class methods" do
8
+ before do
9
+ Scene7::Client.configure(valid_config)
10
+ Scene7::Client.stubs(:company_handle).returns('111')
11
+ Scene7::Client.stubs(:header).returns({
12
+ :auth_header => {
13
+ :user => 'test@example.com',
14
+ :password => 'password',
15
+ :app_name => 'Example.com',
16
+ :app_version => '1.0'
17
+ },
18
+ :attributes! => { :auth_header => { :xmlns => "http://www.scene7.com/IpsApi/xsd" } }
19
+ })
20
+ end
21
+
22
+ describe ".find_by_name" do
23
+ context 'when xml contains one asset' do
24
+ before do
25
+ savon.expects(:get_assets_by_name).with(:company_handle => '111', :name_array => {:items => 'Jacket'}, :order! => [:company_handle, :name_array]).returns(:jacket_asset)
26
+ end
27
+
28
+ it "finds an asset" do
29
+ asset = subject.find_by_name('Jacket')
30
+ asset.should be_a(Scene7::Asset)
31
+ asset.name.should == "Jacket"
32
+ end
33
+ end
34
+
35
+ context 'when xml contains more than one asset' do
36
+ before do
37
+ savon.expects(:get_assets_by_name).with(:company_handle => '111', :name_array => {:items => 'Hat'}, :order! => [:company_handle, :name_array]).returns(:hat_asset)
38
+ end
39
+
40
+ it "finds an asset" do
41
+ asset = subject.find_by_name('Hat')
42
+ asset.should be_a(Scene7::Asset)
43
+ asset.handle.should == "a|1234"
44
+ end
45
+ end
46
+ end
47
+
48
+ describe ".find_all_by_name" do
49
+ context 'when xml contains zero assets' do
50
+ before do
51
+ savon.expects(:get_assets_by_name).with(:company_handle => '111', :name_array => {:items => 'Does not exist'}, :order! => [:company_handle, :name_array]).returns(:zero_found)
52
+ end
53
+
54
+ it "finds a collection containing that asset" do
55
+ collection = subject.find_all_by_name('Does not exist')
56
+ collection.length.should == 0
57
+ end
58
+ end
59
+
60
+ context 'when xml contains one asset' do
61
+ before do
62
+ savon.expects(:get_assets_by_name).with(:company_handle => '111', :name_array => {:items => 'Jacket'}, :order! => [:company_handle, :name_array]).returns(:jacket_asset)
63
+ end
64
+
65
+ it "finds a collection containing that asset" do
66
+ collection = subject.find_all_by_name('Jacket')
67
+ collection.length.should == 1
68
+ collection.first.name.should == "Jacket"
69
+ end
70
+ end
71
+
72
+ context 'when xml contains more than one asset' do
73
+ before do
74
+ savon.expects(:get_assets_by_name).with(:company_handle => '111', :name_array => {:items => 'Hat'}, :order! => [:company_handle, :name_array]).returns(:hat_asset)
75
+ end
76
+
77
+ it "finds a collection containing the assets" do
78
+ collection = subject.find_all_by_name('Hat')
79
+ collection.length.should == 2
80
+ collection.first.handle.should == "a|1234"
81
+ collection.second.handle.should == "a|1235"
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '.create' do
87
+ before do
88
+ subject.stubs(:job_name).returns("12345678901234567890")
89
+
90
+ savon.expects(:submit_job).with({
91
+ :company_handle => '111',
92
+ :job_name => '12345678901234567890',
93
+ :upload_urls_job => {
94
+ :url_array => {
95
+ :items => {
96
+ :source_url => "http://example.com/image.jpg",
97
+ :dest_path => "SomeRoot/SomeDirectory/image.jpg",
98
+ :order! => [:source_url, :dest_path]
99
+ }
100
+ },
101
+ :overwrite => false,
102
+ :ready_for_publish => false,
103
+ :create_mask => false,
104
+ :email_setting => "None",
105
+ :order! => [:url_array, :overwrite, :ready_for_publish, :create_mask, :email_setting]
106
+ },
107
+ :order! => [:company_handle, :job_name, :upload_urls_job]
108
+ }).returns(:upload_urls_job_response)
109
+ end
110
+
111
+ it "returns once the image object exists" do
112
+ asset_mock = mock()
113
+ Scene7::Asset.stubs(:find_by_name).with("image").returns(nil, asset_mock)
114
+ asset = subject.create(:source_url => "http://example.com/image.jpg", :dest_path => "SomeRoot/SomeDirectory/image.jpg")
115
+ asset.should == asset_mock
116
+ end
117
+
118
+ it "gives up and assumes an error after 20 seconds" do
119
+ asset_mock = mock()
120
+ Scene7::Asset.stubs(:find_by_name).with("image").returns(nil)
121
+
122
+ expect { subject.create(:source_url => "http://example.com/image.jpg", :dest_path => "SomeRoot/SomeDirectory/image.jpg") }.to raise_error("Could not create asset")
123
+ end
124
+ end
125
+
126
+ describe ".job_name" do
127
+ it "returns a 20-char hash of the name and current time" do
128
+ Timecop.freeze do
129
+ require 'digest/sha1'
130
+ name = Digest::SHA1.hexdigest("test#{Time.now.usec}")[0..20]
131
+
132
+ subject.job_name("test").should == name
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ describe "initialization" do
139
+ let(:attributes) { {:a => 7, :b => 11, :name => "MY_hero", :asset_handle => "...asset handle..." } }
140
+ subject { Scene7::Asset.new(attributes) }
141
+
142
+ its(:attributes) { should == attributes }
143
+ its(:name) { should == "MY_hero" }
144
+ its(:handle) { should == "...asset handle..." }
145
+ end
146
+
147
+ describe "#rename" do
148
+ let(:attributes) { {:a => 7, :b => 11, :name => "MY_hero", :asset_handle => "222" } }
149
+ subject { Scene7::Asset.new(attributes) }
150
+
151
+ before do
152
+ Scene7::Client.configure(valid_config)
153
+ Scene7::Client.stubs(:company_handle).returns('111')
154
+ end
155
+
156
+ it "renames the object" do
157
+ savon.expects(:rename_asset).with({
158
+ :company_handle => "111",
159
+ :asset_handle => "222",
160
+ :new_name => "new name",
161
+ :validate_name => true,
162
+ :rename_files => true,
163
+ :order! => [:company_handle, :asset_handle, :new_name, :validate_name, :rename_files]
164
+ }).returns(:success)
165
+
166
+ subject.rename("new name").should be_true
167
+ subject.name.should == "new name"
168
+ end
169
+
170
+ it "does not rename the asset if there is a conflict" do
171
+ savon.expects(:rename_asset).with({
172
+ :company_handle => "111",
173
+ :asset_handle => "222",
174
+ :new_name => "new name",
175
+ :validate_name => true,
176
+ :rename_files => true,
177
+ :order! => [:company_handle, :asset_handle, :new_name, :validate_name, :rename_files]
178
+ }).returns(:failure)
179
+
180
+ expect { subject.rename("new name") }.to raise_error("Could not rename the file -- name already taken.")
181
+ end
182
+ end
183
+
184
+ describe "#destroy" do
185
+ before { Scene7::Client.configure(valid_config) }
186
+ let(:attributes) { {:a => 7, :b => 11, :name => "MY_hero", :asset_handle => "222" } }
187
+ subject { Scene7::Asset.new(attributes) }
188
+
189
+ it "deletes the asset" do
190
+ Scene7::Client.expects(:company_handle).returns("111")
191
+ savon.expects(:delete_asset).with(:company_handle => "111", :asset_handle => "222", :order! => [:company_handle, :asset_handle]).returns(:success)
192
+ subject.destroy.should be_true
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe Scene7::Client do
4
+ subject { Scene7::Client }
5
+ let(:valid_config_params) { ['test-instance', 'test@example.com', 'password', 'MyAppName', '1.2'] }
6
+ let(:valid_config_hash) { {:subdomain => 'test-instance', :user => 'test@example.com', :password => 'password', :app_name => 'MyAppName', :app_version => '1.2' } }
7
+
8
+ describe ".configure" do
9
+ it "sets the configuration" do
10
+ Scene7::Config.expects(:new).with(*valid_config_params).returns('my config')
11
+ subject.configure(valid_config_hash)
12
+
13
+ subject.configuration.should == 'my config'
14
+ end
15
+
16
+ it "returns the Scene7::Client class" do
17
+ subject.configure(valid_config_hash).should == Scene7::Client
18
+ end
19
+ end
20
+
21
+ describe '.reset_configuration' do
22
+ it "resets the configuration by setting it to nil" do
23
+ Scene7::Config.expects(:new).with(*valid_config_params).returns('my config')
24
+ subject.configure(valid_config_hash)
25
+
26
+ subject.reset_configuration
27
+
28
+ subject.configuration.should be_nil
29
+ end
30
+ end
31
+
32
+ describe '.header' do
33
+ it "delegates to the configuration" do
34
+ subject.configure(valid_config_hash)
35
+ subject.configuration.expects(:header).returns('the header')
36
+ subject.header.should == 'the header'
37
+ end
38
+
39
+ it 'blows up if there is no configuration' do
40
+ expect { subject.header }.to raise_error('Call Scene7::Client.configure with your configuration first.')
41
+ end
42
+ end
43
+
44
+ describe '.perform_request' do
45
+ before { subject.configure(valid_config_hash) }
46
+ it 'performs a SOAP call through the Savon client' do
47
+ savon.expects(:get_company_info).with(:company_name => 'test').returns(:test_request)
48
+
49
+ subject.perform_request(:get_company_info, :company_name => 'test').to_xml.chomp.should == "<myxml />"
50
+ end
51
+ end
52
+
53
+ describe ".client" do
54
+ let(:scene7_client) { Scene7::Client.configure(valid_config_hash) }
55
+ subject { scene7_client.client }
56
+
57
+ it "is a Savon::Client object" do
58
+ subject.should be_a(Savon::Client)
59
+ end
60
+
61
+ it "has the appropriate namespace" do
62
+ subject.wsdl.namespace.should == "http://www.scene7.com/IpsApi/xsd/2010-01-31"
63
+ end
64
+
65
+ it "has the appropriate endpoint" do
66
+ subject.wsdl.endpoint.should == "https://test-instance.scene7.com/scene7/services/IpsApiService"
67
+ end
68
+ end
69
+
70
+ describe '.input_for_action' do
71
+ subject { Scene7::Client }
72
+
73
+ it "camel-cases and appends 'Param' to the action name" do
74
+ subject.input_for_action(:get_foo).should == 'getFooParam'
75
+ end
76
+ end
77
+
78
+ describe '.company_handle' do
79
+ subject { Scene7::Client }
80
+
81
+ before do
82
+ Scene7::Client.configure(valid_config_hash)
83
+ end
84
+
85
+ it "retrieves the company and returns its handle" do
86
+ Scene7::Company.expects(:find_by_name).with(valid_config_hash[:app_name]).returns(mock(:handle => 'c|11'))
87
+ subject.company_handle.should == 'c|11'
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Scene7::Company do
4
+ describe "initialization" do
5
+ it "stores attributes" do
6
+ attributes = {:a => 7, :b => 11}
7
+
8
+ Scene7::Company.new(attributes).attributes == attributes
9
+ end
10
+ end
11
+
12
+ describe "#name" do
13
+ it "pulls its data from stored attributes" do
14
+ attributes = {:name => "Example.com"}
15
+
16
+ Scene7::Company.new(attributes).name.should == "Example.com"
17
+ end
18
+ end
19
+
20
+ describe "#handle" do
21
+ it "pulls its data from stored attributes" do
22
+ attributes = {:company_handle => "...company handle..."}
23
+
24
+ Scene7::Company.new(attributes).handle.should == "...company handle..."
25
+ end
26
+ end
27
+
28
+ describe "#root_path" do
29
+ it "pulls its data from stored attributes" do
30
+ attributes = {:root_path => "Example.com/"}
31
+
32
+ Scene7::Company.new(attributes).root_path.should == "Example.com/"
33
+ end
34
+ end
35
+
36
+ describe ".find_by_name" do
37
+ subject { Scene7::Company }
38
+ let(:valid_config) { {:subdomain => 'test-instance', :user => 'test@example.com', :password => 'password', :app_name => 'MyAppName', :app_version => '1.2' } }
39
+
40
+ before do
41
+ Scene7::Client.configure(valid_config)
42
+ Scene7::Client.stubs(:header).returns({
43
+ :auth_header => {
44
+ :user => 'test@example.com',
45
+ :password => 'password',
46
+ :app_name => 'Example.com',
47
+ :app_version => '1.0'
48
+ },
49
+ :attributes! => { :auth_header => { :xmlns => "http://www.scene7.com/IpsApi/xsd" } }
50
+ })
51
+
52
+ savon.expects(:get_company_info).with(:company_name => "Example.com").returns(:company)
53
+ end
54
+
55
+ it "finds a company" do
56
+ subject.find_by_name('Example.com').should be_a(Scene7::Company)
57
+ end
58
+
59
+ it "has the right handle" do
60
+ subject.find_by_name('Example.com').handle.should == "111"
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe Scene7::Config do
4
+ subject { Scene7::Config }
5
+ let(:valid_options) { ['test-instance', 'test@example.com', 'password', 'MyAppName', '1.2'] }
6
+
7
+ describe ".new" do
8
+ it "configures a subdomain" do
9
+ config = subject.new(*valid_options)
10
+ config.subdomain.should == 'test-instance'
11
+ end
12
+
13
+ it "configures a user" do
14
+ config = subject.new(*valid_options)
15
+ config.user.should == "test@example.com"
16
+ end
17
+
18
+ it "configures a password" do
19
+ config = subject.new(*valid_options)
20
+ config.password.should == "password"
21
+ end
22
+
23
+ it "configures an app name" do
24
+ config = subject.new(*valid_options)
25
+ config.app_name.should == "MyAppName"
26
+ end
27
+
28
+ it "configures an app_version" do
29
+ config = subject.new(*valid_options)
30
+ config.app_version.should == "1.2"
31
+ end
32
+
33
+ describe 'app_version' do
34
+ it "is cast to a string" do
35
+ config = subject.new(*valid_options)
36
+ config.app_version.should == "1.2"
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '#endpoint' do
42
+ subject { Scene7::Config.new(*valid_options) }
43
+
44
+ it 'returns the endpoint containing the subdomain' do
45
+ subject.endpoint.should == 'https://test-instance.scene7.com/scene7/services/IpsApiService'
46
+ end
47
+ end
48
+
49
+ describe 'AUTH_NAMESPACE' do
50
+ Scene7::Config::AUTH_NAMESPACE.should == "http://www.scene7.com/IpsApi/xsd"
51
+ end
52
+
53
+ describe '#header' do
54
+ subject { Scene7::Config.new(*valid_options) }
55
+
56
+ it "returns a hash containing the auth info" do
57
+ subject.expects(:user).returns('test@example.com')
58
+ subject.expects(:password).returns('mypassword')
59
+ subject.expects(:app_name).returns('Example.com')
60
+ subject.expects(:app_version).returns('1.0')
61
+
62
+ header = subject.header
63
+
64
+ header[:auth_header].should == {
65
+ :user => 'test@example.com',
66
+ :password => 'mypassword',
67
+ :app_name => 'Example.com',
68
+ :app_version => '1.0'
69
+ }
70
+
71
+ header[:attributes!].should == {
72
+ :auth_header => { :xmlns => "http://www.scene7.com/IpsApi/xsd" }
73
+ }
74
+
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Scene7::Crop do
4
+ subject { Scene7::Crop }
5
+
6
+ describe '.format_url_params' do
7
+ let(:params) { {
8
+ :scale_factor => 0.5,
9
+ :x => 50.0,
10
+ :y => 100.1,
11
+ :height => 149.8,
12
+ :width => 250.2
13
+ } }
14
+
15
+ it 'includes the scale and scale factor' do
16
+ subject.format_url_params(params).should == "scl=0.5&crop=50,100,250,150"
17
+ end
18
+ end
19
+
20
+ describe "conversion methods" do
21
+ let(:params) { {
22
+ :scale_factor => '2.0',
23
+ :x => '100',
24
+ :y => '250',
25
+ :height => '300',
26
+ :width => '450'
27
+ } }
28
+
29
+ describe ".convert_from_scale_first_and_format" do
30
+ it "converts, then formats" do
31
+ subject.convert_from_scale_first_and_format(params).should == "scl=0.5&crop=50,125,225,150"
32
+ end
33
+ end
34
+
35
+ describe '.convert_params_from_scale_first' do
36
+ before do
37
+ @result = subject.convert_params_from_scale_first(params)
38
+ end
39
+
40
+ it "converts the scale factor from the scale-first style" do
41
+ @result[:scale_factor].should == 0.5
42
+ end
43
+
44
+ it "converts the height from the scale-first style" do
45
+ @result[:height].should == 150
46
+ end
47
+
48
+ it "converts the width from the scale-first style" do
49
+ @result[:width].should == 225
50
+ end
51
+
52
+ it "converts the left coordinate from the scale-first style" do
53
+
54
+ @result[:x].should == 50
55
+ end
56
+
57
+ it "converts the top coordinate from the scale-first style" do
58
+ @result[:y].should == 125
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+
3
+ describe Scene7::Folder do
4
+ subject { Scene7::Folder }
5
+ let(:valid_config) { {:subdomain => 'test-instance', :user => 'test@example.com', :password => 'password', :app_name => 'MyAppName', :app_version => '1.2' } }
6
+
7
+ describe "public API" do
8
+ before do
9
+ Scene7::Client.configure(valid_config)
10
+ Scene7::Client.stubs(:company_handle).returns('111')
11
+ Scene7::Client.stubs(:header).returns({
12
+ :auth_header => {
13
+ :user => 'test@example.com',
14
+ :password => 'password',
15
+ :app_name => 'Example.com',
16
+ :app_version => '1.0'
17
+ },
18
+ :attributes! => { :auth_header => { :xmlns => "http://www.scene7.com/IpsApi/xsd" } }
19
+ })
20
+ end
21
+
22
+ describe ".all" do
23
+ it "retrieves all folders" do
24
+ savon.expects(:get_folders).with(:company_handle => "111").returns(:folders)
25
+
26
+ subject.all
27
+ end
28
+
29
+ it "retrives a collection of Folders" do
30
+ savon.stubs(:get_folders).with(:company_handle => "111").returns(:folders)
31
+
32
+ folders = subject.all
33
+
34
+ folders.all? { |f| f.is_a?(subject) }.should be_true
35
+ end
36
+
37
+ it "returns folders that are properly initialized" do
38
+ savon.stubs(:get_folders).with(:company_handle => "111").returns(:folders)
39
+
40
+ folders = subject.all
41
+
42
+ folder = folders.first
43
+
44
+ folder.handle.should == "handle-1"
45
+ folder.path.should == "folder-path-1"
46
+ folder.last_modified.should == "20080726T08:36:19.19305:00"
47
+ folder.has_subfolders.should == true
48
+ end
49
+ end
50
+
51
+ describe ".find_by_file_handle" do
52
+ it "should return a single folder instance" do
53
+ savon.stubs(:get_folders).with(:company_handle => "111").returns(:folders)
54
+
55
+ folder = Scene7::Folder.find_by_handle("handle-2")
56
+
57
+ folder.handle.should == "handle-2"
58
+ folder.path.should == "folder-path-2"
59
+ end
60
+
61
+ it "should return nil if the file does not exist" do
62
+ savon.stubs(:get_folders).with(:company_handle => "111").returns(:folders)
63
+
64
+ Scene7::Folder.find_by_handle("non-existant-handle").should be_nil
65
+ end
66
+ end
67
+
68
+ describe ".create" do
69
+ pending "it handles errors"
70
+ # already exists
71
+ # bad path
72
+
73
+ it "creates a folder" do
74
+ savon.expects(:create_folder).with(:company_handle => "111", :folder_path => "SomeRoot/SomeFolder", :order! => [:company_handle, :folder_path]).returns(:folder)
75
+
76
+ subject.create(:folder_path => "SomeRoot/SomeFolder")
77
+ end
78
+
79
+ it "should return a folder that knows its handle" do
80
+ savon.stubs(:create_folder).with(:company_handle => "111", :folder_path => "SomeRoot/SomeFolder").returns(:folder)
81
+
82
+ response = subject.create(:folder_path => "SomeRoot/SomeFolder")
83
+
84
+ response.handle.should == "exampleFolderHandle"
85
+ end
86
+
87
+ it "should raise an error if folder path is not set" do
88
+ savon.stubs(:create_folder)
89
+
90
+ expect { subject.create(:bogus_param => "bogus!") }.should raise_error(RuntimeError, ":folder_path is required to create a folder")
91
+ end
92
+ end
93
+
94
+ describe "#destroy" do
95
+ it "should destroy a folder" do
96
+ folder = Scene7::Folder.new(:folder_handle => "folder-handle-1")
97
+
98
+ savon.expects(:delete_folder).with(:company_handle => "111", :folder_handle => "folder-handle-1", :order! => [:company_handle, :folder_handle]).returns(:empty_response)
99
+
100
+ folder.destroy
101
+ end
102
+
103
+ it "should return true if the deletion is successful" do
104
+ folder = Scene7::Folder.new(:folder_handle => "folder-handle-1")
105
+
106
+ savon.stubs(:delete_folder).with(:company_handle => "111", :folder_handle => "folder-handle-1").returns(:empty_response)
107
+
108
+ folder.destroy.should be_true
109
+ end
110
+
111
+ pending "error handling"
112
+ end
113
+
114
+ end
115
+ end
@@ -0,0 +1,16 @@
1
+ require 'scene7-wrapper'
2
+ require 'savon_spec'
3
+ require 'timecop'
4
+
5
+ RSpec.configure do |config|
6
+ config.include Savon::Spec::Macros
7
+
8
+ config.before(:each) do
9
+ Scene7::Client.reset_configuration
10
+ end
11
+ end
12
+
13
+ Savon::Spec::Fixture.path = File.join(File.dirname(__FILE__), 'fixtures')
14
+ Savon.configure do |config|
15
+ config.log = false
16
+ end