Merge branch 'delete-protection' into funkensturm/master
* delete-protection: Added config to optionally disable deleting digitals on variant deletion Revert "Remove delete digitals on soft delete of variant" Adding failing variant spec Fixed broken Digital#destroy spec Remove delete digitals on soft delete of variant
This commit is contained in:
@@ -20,6 +20,5 @@ describe Spree::Digital do
|
||||
Spree::DigitalLink.count.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
+33
-13
@@ -1,18 +1,38 @@
|
||||
require 'spec_helper'
|
||||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe Spree::Variant do
|
||||
before do
|
||||
@product = FactoryGirl.create :product
|
||||
@digital = FactoryGirl.create :digital, :variant => @product.master
|
||||
end
|
||||
context "#destroy" do
|
||||
before do
|
||||
@variant = FactoryGirl.create :variant
|
||||
@digital = FactoryGirl.create :digital, :variant => @variant
|
||||
end
|
||||
|
||||
let(:variant) { @product.master }
|
||||
let(:variant) { @variant }
|
||||
let(:digital) { @digital }
|
||||
|
||||
it "should delete all digitals on variant#destroy" do
|
||||
digital_id = variant.digitals.first.id
|
||||
Spree::Digital.find(digital_id).should_not be_nil
|
||||
variant.digitals.count.should == 1
|
||||
variant.destroy
|
||||
expect { Spree::Digital.find(digital_id) }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
it "should destroy associated digitals by default" do
|
||||
# default is false
|
||||
Spree::DigitalConfiguration[:keep_digitals] = false
|
||||
|
||||
Spree::Digital.count.should == 1
|
||||
variant.digitals.present?.should be_true
|
||||
variant.deleted_at = Time.now
|
||||
variant.deleted?.should be_true
|
||||
variant.save!
|
||||
expect { digital.reload.present? }.to raise_error
|
||||
Spree::Digital.count.should == 0
|
||||
end
|
||||
|
||||
it "should conditionally keep associated digitals" do
|
||||
Spree::DigitalConfiguration[:keep_digitals] = true
|
||||
|
||||
Spree::Digital.count.should == 1
|
||||
variant.digitals.present?.should be_true
|
||||
variant.deleted_at = Time.now
|
||||
variant.save!
|
||||
variant.deleted?.should be_true
|
||||
expect { digital.reload.present? }.to_not raise_error
|
||||
Spree::Digital.count.should == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
+25
-3
@@ -1,6 +1,7 @@
|
||||
ENV["RAILS_ENV"] = "test"
|
||||
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
||||
require 'rspec/rails'
|
||||
require 'database_cleaner'
|
||||
|
||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||
# in spec/support/ and its subdirectories.
|
||||
@@ -11,17 +12,38 @@ require 'spree/core/testing_support/env'
|
||||
require 'spree/core/testing_support/controller_requests'
|
||||
require 'spree/core/url_helpers'
|
||||
|
||||
Dir[File.join(File.dirname(__FILE__), "factories/*.rb")].each {|f| require f }
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.mock_with :rspec
|
||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
config.use_transactional_fixtures = true
|
||||
|
||||
config.include Spree::Core::UrlHelpers
|
||||
config.include Spree::Core::TestingSupport::ControllerRequests
|
||||
config.include Devise::TestHelpers, :type => :controller
|
||||
end
|
||||
|
||||
Dir[File.join(File.dirname(__FILE__), "factories/*.rb")].each {|f| require f }
|
||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||
# examples within a transaction, remove the following line or assign false
|
||||
# instead of true.
|
||||
config.use_transactional_fixtures = false
|
||||
|
||||
config.before(:each) do
|
||||
if example.metadata[:js]
|
||||
DatabaseCleaner.strategy = :truncation, { :except => ['spree_countries', 'spree_zones', 'spree_zone_members', 'spree_states', 'spree_roles'] }
|
||||
else
|
||||
DatabaseCleaner.strategy = :transaction
|
||||
end
|
||||
end
|
||||
|
||||
config.before(:each) do
|
||||
DatabaseCleaner.start
|
||||
# reset_spree_preferences
|
||||
end
|
||||
|
||||
config.after(:each) do
|
||||
DatabaseCleaner.clean
|
||||
end
|
||||
end
|
||||
|
||||
# not sure if this really adds anything, but this existed in the intial version of the spree_digital rspec testing
|
||||
RSpec::Matchers.define :have_valid_factory do |factory_name|
|
||||
|
||||
Reference in New Issue
Block a user