spec/adyen-admin/skin_spec.rb in adyen-admin-0.0.16 vs spec/adyen-admin/skin_spec.rb in adyen-admin-0.0.17
- old
+ new
@@ -4,24 +4,31 @@
require "adyen-admin/skin"
module Adyen::Admin
describe Skin, :vcr do
let(:skin_fixtures) { File.expand_path 'spec/fixtures/skins' }
- let(:skin_code) { "7hFAQnmt" }
+ let(:skin_code) { $adyen[:test_skin_code] }
+ let(:path) { "#{skin_fixtures}/#{skin_code}" }
let(:skin) { Skin.new(:code => skin_code, :name => "example") }
+ let(:other_skins) do
+ $adyen[:other_skin_codes].map do |code|
+ Skin.new(:code => code, :name => "example")
+ end
+ end
+
describe ".all" do
it 'returns all local skins' do
Skin.all.should == Skin.all_local
end
end
context "authenticated" do
before(:all) do
VCR.use_cassette("login") do
Adyen::Admin.client.cookie_jar.clear!
- Adyen::Admin.login("SoundCloud", "skinadmin", "12312311")
+ Adyen::Admin.login($adyen[:account], $adyen[:user], $adyen[:password])
end
end
before do
Adyen::Admin::Skin.purge_cache
@@ -29,42 +36,40 @@
describe ".all_remote" do
it 'returns the skins' do
Skin.all_remote.should =~ [
skin,
- Skin.new(:code => "Kx9axnRf", :name => "demo"),
- Skin.new(:code => "vQW0fEo8", :name => "test"),
- ]
+ ] + other_skins
end
it 'sets local path' do
Adyen::Admin::Skin.default_path = skin_fixtures
- Skin.all_remote.first.path.should == "#{skin_fixtures}/example-7hFAQnmt"
+ Skin.find(skin_code).path.should == "#{skin_fixtures}/example-#{skin_code}"
end
end
describe ".all_local" do
it 'returns the skins' do
Skin.all_local.should =~ [
Skin.new(:code => "base"),
- skin,
Skin.new(:code => "DV3tf95f"),
Skin.new(:code => "JH0815"),
+ Skin.new(:code => "7hFAQnmt"),
+ skin,
]
end
end
describe ".all" do
it 'returns the skins' do
Skin.all.should =~ [
- skin,
- Skin.new(:code => "Kx9axnRf", :name => "demo"),
- Skin.new(:code => "vQW0fEo8", :name => "test"),
Skin.new(:code => "base"),
Skin.new(:code => "DV3tf95f"),
- Skin.new(:code => "JH0815")
- ]
+ Skin.new(:code => "JH0815"),
+ Skin.new(:code => "7hFAQnmt"),
+ skin,
+ ] + other_skins
end
it 'freezes local skins' do
Skin.all.last.should be_frozen
end
@@ -79,11 +84,11 @@
Skin.find("dummy code").should == nil
end
end
describe "#new" do
- let(:path) { "#{skin_fixtures}/example-7hFAQnmt" }
+ let(:path) { "#{skin_fixtures}/example-#{skin_code}" }
it "sets code attribute" do
Skin.new(:code => skin_code).code.should == skin_code
end
@@ -94,11 +99,11 @@
it "sets path attribute" do
Skin.new(:path => path).path.should == path
end
it "auto sets code from path" do
- Skin.new(:path => path).code.should == "7hFAQnmt"
+ Skin.new(:path => path).code.should == skin_code
end
it "auto sets name from path" do
Skin.new(:path => path).name.should == "example"
end
@@ -114,11 +119,11 @@
Skin.new
end.to raise_error
end
context "slash in name" do
- let(:path) { "#{skin_fixtures}/example-test-7hFAQnmt" }
+ let(:path) { "#{skin_fixtures}/example-test-#{skin_code}" }
it "sets name" do
Skin.stub(:is_skin_path?).and_return(true)
Skin.new(:path => path).name.should == "example-test"
end
@@ -165,11 +170,11 @@
end
end
end
describe "#update" do
- let(:path) { "#{skin_fixtures}/example-7hFAQnmt" }
+ let(:path) { "#{skin_fixtures}/example-#{skin_code}" }
before do
skin.path = path
end
@@ -220,66 +225,50 @@
skin.download
File.should be_exists(zip_filename)
end
it "is a zipfile" do
- Zip::ZipFile.open(skin.download) do |zipfile|
+ Zip::File.open(skin.download) do |zipfile|
zipfile.find_entry(File.join(skin_code, "inc", "cheader.txt")).should be_true
end
end
end
describe "#decompile" do
+ subject { skin.decompile(zip_filename) }
+
let(:skin_code) { "DV3tf95f" }
- let(:skin) { Skin.new(:path => "#{skin_fixtures}/#{skin_code}") }
+ let(:skin) { Skin.new(:path => path) }
after do
`rm -rf #{zip_filename}`
end
context "existing skin" do
let(:backup_filename) { File.join(skin.path, '.backup.zip') }
let!(:zip_filename) { skin.compress(nil) }
before do
- `cp -r #{skin_fixtures}/#{skin_code} #{skin_fixtures}/_backup`
+ `cp -r #{path} #{skin_fixtures}/_backup`
end
after do
- `rm -rf #{backup_filename} #{skin_fixtures}/#{skin_code}`
- `mv #{skin_fixtures}/_backup #{skin_fixtures}/#{skin_code}`
+ `rm -rf #{backup_filename} #{path}`
+ `mv #{skin_fixtures}/_backup #{path}`
end
it "creates backup" do
- skin.decompile(zip_filename)
-
+ subject
File.should be_exists(backup_filename)
end
it "unzips files" do
`rm -rf #{skin.path}`
- expect do
- skin.decompile(zip_filename)
- end.to change { File.exists?(File.join(skin.path, 'inc', 'order_data.txt')) }
+ expect { subject }.to change { File.exists?(File.join(skin.path, 'inc', 'order_data.txt')) }
end
end
-
- context "new remote skin" do
- let(:skin) { Skin.new(:name => "test", :code => "vQW0fEo8") }
- let!(:zip_filename) { skin.download }
-
- after do
- `rm -rf #{skin.path}`
- end
-
- it "downloads and decompiles skin" do
- expect do
- skin.decompile(zip_filename)
- end.to change { skin.path }
- end
- end
end
describe "#compile" do
let(:skin_code) { "JH0815" }
let(:skin) { Skin.new(:path => File.join(skin_fixtures, skin_code)) }
@@ -292,34 +281,34 @@
after do
FileUtils.rm_rf( skin.path + '/inc')
end
it 'writes cheader' do
- File.read( skin.path + '/inc/cheader.txt').should == "<!-- ### inc/cheader_[locale].txt or inc/cheader.txt (fallback) ### -->"
+ File.read(skin.path + '/inc/cheader.txt').should == "<!-- ### inc/cheader_[locale].txt or inc/cheader.txt (fallback) ### -->"
end
it 'writes pmheader' do
- File.read( skin.path + '/inc/pmheader.txt').should == "<!-- ### inc/pmheader_[locale].txt or inc/pmheader.txt (fallback) ### -->"
+ File.read(skin.path + '/inc/pmheader.txt').should == "<!-- ### inc/pmheader_[locale].txt or inc/pmheader.txt (fallback) ### -->"
end
it 'writes pmfooter' do
- File.read( skin.path + '/inc/pmfooter.txt').should == "<!-- ### inc/pmfooter_[locale].txt or inc/pmfooter.txt (fallback) ### -->\n\n <!-- ### inc/customfields_[locale].txt or inc/customfields.txt (fallback) ### -->"
+ File.read(skin.path + '/inc/pmfooter.txt').should == "<!-- ### inc/pmfooter_[locale].txt or inc/pmfooter.txt (fallback) ### -->\n\n <!-- ### inc/customfields_[locale].txt or inc/customfields.txt (fallback) ### -->"
end
it 'writes cfooter' do
- File.read( skin.path + '/inc/cfooter.txt').should == "<!-- ### inc/cfooter_[locale].txt or inc/cfooter.txt (fallback) ### -->"
+ File.read(skin.path + '/inc/cfooter.txt').should == "<!-- ### inc/cfooter_[locale].txt or inc/cfooter.txt (fallback) ### -->"
end
end
describe "#compress" do
+ subject(:zip_filename){ skin.compress }
+
let(:skin_code) { "DV3tf95f" }
- let(:path) { "#{skin_fixtures}/#{skin_code}" }
let(:skin) { Skin.new(:path => path) }
- let(:zip_filename) { skin.compress }
def zip_contains(file)
- Zip::ZipFile.open(zip_filename) do |zipfile|
+ Zip::File.open(zip_filename) do |zipfile|
return true if zipfile.find_entry(File.join(skin.code, file))
end
false
end
@@ -399,25 +388,27 @@
zip_contains("skin.html.erb").should be_true
end
end
context "with parent_skin" do
- let(:skin_code) { "JH0815" }
+ let(:parent_skin_code) { $adyen[:test_skin_code] }
before do
- skin.stub(:parent_skin).and_return("example-7hFAQnmt")
+ skin.stub(:parent_skin).and_return("example-#{parent_skin_code}")
end
it "excludes meta file" do
zip_contains("img/bg.gif").should be_true
end
end
end
describe "#upload" do
- let(:path) { "#{skin_fixtures}/example-7hFAQnmt" }
+ subject { skin.upload }
+ let(:path) { "#{skin_fixtures}/example-#{skin_code}" }
+
after do
`rm -f #{skin_code}.zip`
`rm -f #{path}/skin.yml`
end
@@ -425,43 +416,24 @@
before do
skin.path = path
end
it "increases version" do
- expect do
- skin.upload
- end.to change { skin.send(:remote_version) }.by(1)
+ expect { subject }.to change { skin.send(:remote_version) }.by(1)
end
it "updates skin data" do
skin.should_receive(:update)
- skin.upload
+ subject
end
end
end
- describe "#remote_version" do
- let(:skin) { Skin.new(:code => "Kx9axnRf", :name => "demo") }
- let(:version) { 17 }
-
- it "returns uploaded value" do
- skin.send(:remote_version).should == version
- end
-
- it "returns test value" do
- skin.send(:remote_version, :test).should == version
- end
-
- it "returns live value" do
- skin.send(:remote_version, :live).should == 0
- end
- end
-
describe "#test_url" do
- it "returns url to test" do
- skin.test_url.to_s.should include("https://test.adyen.com/hpp/select.shtml")
- end
+ subject { skin.test_url.to_s }
+
+ it { should include("https://test.adyen.com/hpp/pay.shtml") }
#todo test with options
end
end
end
end