Stability improvements, new release
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require "ostruct"
|
||||
require "spec_helper"
|
||||
|
||||
describe MusicBrainz::ClientModules::CachingProxy do
|
||||
let(:old_cache_path){ File.join(File.dirname(__FILE__), '..', '..', 'tmp', 'spec_cache') }
|
||||
let(:tmp_cache_path){ File.join(File.dirname(__FILE__), '..', '..', 'tmp', 'cache_module_spec_cache') }
|
||||
let(:test_mbid){ "69b39eab-6577-46a4-a9f5-817839092033" }
|
||||
let(:test_cache_file){ "#{tmp_cache_path}/03/48/ec/6c2bee685d9a96f95ed46378f624714e7a4650b0d44c1a8eee5bac2480.xml" }
|
||||
let(:test_response_file){ File.join(File.dirname(__FILE__), "../fixtures/kasabian.xml") }
|
||||
let(:test_response){ File.open(test_response_file).read }
|
||||
|
||||
before(:all) do
|
||||
MusicBrainz.config.cache_path = tmp_cache_path
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
MusicBrainz.config.cache_path = old_cache_path
|
||||
MusicBrainz.config.perform_caching = true
|
||||
MusicBrainz.config.query_interval = 1.5
|
||||
end
|
||||
|
||||
context "with cache enabled" do
|
||||
it "calls http only once when requesting the resource twice" do
|
||||
MusicBrainz.config.perform_caching = true
|
||||
File.exist?(test_cache_file).should be_false
|
||||
|
||||
# Stubbing
|
||||
MusicBrainz.client.http.stub(:get).and_return(OpenStruct.new(status: 200, body: test_response))
|
||||
MusicBrainz.client.http.should_receive(:get).once
|
||||
|
||||
2.times do
|
||||
artist = MusicBrainz::Artist.find(test_mbid)
|
||||
artist.should be_a_kind_of(MusicBrainz::Artist)
|
||||
File.exist?(test_cache_file).should be_true
|
||||
end
|
||||
|
||||
MusicBrainz.client.clear_cache
|
||||
end
|
||||
end
|
||||
|
||||
context "with cache disabled" do
|
||||
it "calls http twice when requesting the resource twice" do
|
||||
MusicBrainz.config.perform_caching = false
|
||||
File.exist?(test_cache_file).should be_false
|
||||
|
||||
# Hacking for test performance purposes
|
||||
MusicBrainz.config.query_interval = 0.0
|
||||
|
||||
# Stubbing
|
||||
MusicBrainz.client.http.stub(:get).and_return(OpenStruct.new(status: 200, body: test_response))
|
||||
MusicBrainz.client.http.should_receive(:get).twice
|
||||
|
||||
2.times do
|
||||
artist = MusicBrainz::Artist.find(test_mbid)
|
||||
artist.should be_a_kind_of(MusicBrainz::Artist)
|
||||
File.exist?(test_cache_file).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -55,6 +55,6 @@ describe MusicBrainz::Artist do
|
||||
release_groups.first.id.should == "533cbc5f-ec7e-32ab-95f3-8d1f804a5176"
|
||||
release_groups.first.type.should == "Single"
|
||||
release_groups.first.title.should == "Club Foot"
|
||||
release_groups.first.first_release_date.should == Time.utc(2004, 5, 10)
|
||||
release_groups.first.first_release_date.should == Date.new(2004, 5, 10)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,7 +19,7 @@ describe MusicBrainz::ReleaseGroup do
|
||||
release_group.id.should == "6f33e0f0-cde2-38f9-9aee-2c60af8d1a61"
|
||||
release_group.type.should == "Album"
|
||||
release_group.title.should == "Empire"
|
||||
release_group.first_release_date.should == Time.utc(2006, 8, 28)
|
||||
release_group.first_release_date.should == Date.new(2006, 8, 28)
|
||||
end
|
||||
|
||||
it "gets correct release group's releases" do
|
||||
@@ -28,7 +28,7 @@ describe MusicBrainz::ReleaseGroup do
|
||||
releases.first.id.should == "2225dd4c-ae9a-403b-8ea0-9e05014c778f"
|
||||
releases.first.status.should == "Official"
|
||||
releases.first.title.should == "Empire"
|
||||
releases.first.date.should == Time.utc(2006, 8, 28)
|
||||
releases.first.date.should == Date.new(2006, 8, 28)
|
||||
releases.first.country.should == "GB"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,7 +19,7 @@ describe MusicBrainz::Release do
|
||||
release.id.should == "2225dd4c-ae9a-403b-8ea0-9e05014c778f"
|
||||
release.title.should == "Empire"
|
||||
release.status.should == "Official"
|
||||
release.date.should == Time.utc(2006, 8, 28)
|
||||
release.date.should == Date.new(2006, 8, 28)
|
||||
release.country.should == "GB"
|
||||
end
|
||||
|
||||
|
||||
+7
-5
@@ -2,16 +2,18 @@ require "rubygems"
|
||||
require "bundler/setup"
|
||||
require "musicbrainz"
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.order = 'random'
|
||||
end
|
||||
|
||||
MusicBrainz.configure do |c|
|
||||
test_email = %x{ git config --global --get user.email }.gsub(/\n/, "")
|
||||
test_email = `git config user.email`.chomp
|
||||
test_email = "magnolia_fan@me.com" if test_email.empty?
|
||||
|
||||
c.app_name = "MusicBrainzGemTestSuite"
|
||||
c.app_version = MusicBrainz::VERSION
|
||||
c.contact = test_email
|
||||
|
||||
c.cache_path = File.join(File.dirname(__FILE__), '..', 'tmp', 'spec_cache')
|
||||
c.perform_caching = true
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
# Configuration is not currently necessary
|
||||
end
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require "ostruct"
|
||||
require "spec_helper"
|
||||
|
||||
describe MusicBrainz::Tools::Cache do
|
||||
before(:all) do
|
||||
@old_cache_path = MusicBrainz::Tools::Cache.cache_path
|
||||
@tmp_cache_path = File.join(File.dirname(__FILE__), "../../tmp/cache/test")
|
||||
@test_mbid = "69b39eab-6577-46a4-a9f5-817839092033"
|
||||
@test_cache_file = "#{@tmp_cache_path}/03/48/ec6c2bee685d9a96f95ed46378f624714e7a4650b0d44c1a8eee5bac2480.xml"
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
MusicBrainz.config.cache_path = @old_cache_path
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
file_path = File.join(File.dirname(__FILE__), "../fixtures/kasabian.xml")
|
||||
@test_response = File.open(file_path).read
|
||||
end
|
||||
|
||||
context "with cache enabled" do
|
||||
it "calls http only once when requesting the resource twice" do
|
||||
MusicBrainz.config.cache_path = @tmp_cache_path
|
||||
File.exist?(@test_cache_file).should be_false
|
||||
|
||||
# Stubbing
|
||||
MusicBrainz::Client.http.stub(:get).and_return(OpenStruct.new(status: 200, body: @test_response))
|
||||
MusicBrainz::Client.http.should_receive(:get).once
|
||||
|
||||
2.times do
|
||||
artist = MusicBrainz::Artist.find(@test_mbid)
|
||||
artist.should be_a_kind_of(MusicBrainz::Artist)
|
||||
File.exist?(@test_cache_file).should be_true
|
||||
end
|
||||
|
||||
MusicBrainz::Client.clear_cache
|
||||
end
|
||||
end
|
||||
|
||||
context "with cache disabled" do
|
||||
it "calls http twice when requesting the resource twice" do
|
||||
MusicBrainz.config.perform_caching = false
|
||||
File.exist?(@test_cache_file).should be_false
|
||||
|
||||
# Hacking for test performance purposes
|
||||
MusicBrainz.config.query_interval = 0.0
|
||||
|
||||
# Stubbing
|
||||
MusicBrainz::Client.http.stub(:get).and_return(OpenStruct.new(status: 200, body: @test_response))
|
||||
MusicBrainz::Client.http.should_receive(:get).twice
|
||||
|
||||
2.times do
|
||||
artist = MusicBrainz::Artist.find(@test_mbid)
|
||||
artist.should be_a_kind_of(MusicBrainz::Artist)
|
||||
File.exist?(@test_cache_file).should be_false
|
||||
end
|
||||
|
||||
MusicBrainz.config.perform_caching = true
|
||||
MusicBrainz.config.query_interval = 1.5
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user