Merge pull request #17 from iloveitaly/spree-1.1
Spree 1.1 Compatibility
This commit is contained in:
commit
3b9ae9c297
17 files changed
+58
-48
No files matched your search
@@ -1,8 +1,6 @@
|
|||||||
source 'http://rubygems.org'
|
source 'http://rubygems.org'
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
# without ffaker in test it wont init
|
|
||||||
# https://github.com/spree/spree/pull/833
|
|
||||||
gem 'ffaker'
|
gem 'ffaker'
|
||||||
gem 'shoulda-matchers'
|
gem 'shoulda-matchers'
|
||||||
gem 'guard-rspec'
|
gem 'guard-rspec'
|
||||||
@@ -13,4 +11,6 @@ group :test do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
gem 'spree', '~> 1.1.1'
|
||||||
|
|
||||||
gemspec
|
gemspec
|
||||||
@@ -4,6 +4,8 @@ This is a spree extension to enable downloadable products. The design goal is to
|
|||||||
|
|
||||||
NOTE: This is still under development, but since things were falling into place, I thought I'd publish it.
|
NOTE: This is still under development, but since things were falling into place, I thought I'd publish it.
|
||||||
|
|
||||||
|
The master branch may work with spree 1.0, but the latest confirmed working version if referenced in the Versionfile.
|
||||||
|
|
||||||
The idea is simple. You attach a file to a Product (or a Variant of this Product) and when people buy it, they will receive a link via email where they can download it once. There are a few assumptions that spree_digital (currently) makes and it's important to be aware of them. These might change, but since I programmed digital_spree over night, this is what you get ;)
|
The idea is simple. You attach a file to a Product (or a Variant of this Product) and when people buy it, they will receive a link via email where they can download it once. There are a few assumptions that spree_digital (currently) makes and it's important to be aware of them. These might change, but since I programmed digital_spree over night, this is what you get ;)
|
||||||
|
|
||||||
* The table structure of spree_core is not touched. Spree_digital lives parallel to spree_core and does not do any changes to your existing database, except adding two new tables.
|
* The table structure of spree_core is not touched. Spree_digital lives parallel to spree_core and does not do any changes to your existing database, except adding two new tables.
|
||||||
|
|||||||
+2
-1
@@ -1,2 +1,3 @@
|
|||||||
"0.7.x" => { :ref => "eddaea63959586d123007cbca3be5bf9c5edb1a7" }
|
"0.7.x" => { :ref => "eddaea63959586d123007cbca3be5bf9c5edb1a7" }
|
||||||
"1.0.x" => { :branch => "master" }
|
"1.0.x" => { :ref => "a8c27750ef1cf9d0ad1a2a6ebe33307da900a5c1" }
|
||||||
|
"1.1.x" => { :branch => "master" }
|
||||||
@@ -6,6 +6,8 @@ module Spree
|
|||||||
has_attached_file :attachment, :path => ":rails_root/private/digitals/:id/:basename.:extension"
|
has_attached_file :attachment, :path => ":rails_root/private/digitals/:id/:basename.:extension"
|
||||||
|
|
||||||
# TODO: Limit the attachment to one single file. Paperclip supports many by default :/
|
# TODO: Limit the attachment to one single file. Paperclip supports many by default :/
|
||||||
|
|
||||||
|
attr_accessible :variant_id, :attachment
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -27,6 +27,8 @@ module Spree
|
|||||||
self.secret = SecureRandom.hex(15)
|
self.secret = SecureRandom.hex(15)
|
||||||
self.access_counter = 0
|
self.access_counter = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attr_accessible :digital, :line_item, :secret
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -20,10 +20,9 @@ Deface::Override.new(:virtual_path => "spree/checkout/_delivery",
|
|||||||
<%== t 'digital_shipping', :email => @order.email %> (<%= number_to_currency @order.digital_shipping_method[:cost] %>)
|
<%== t 'digital_shipping', :email => @order.email %> (<%= number_to_currency @order.digital_shipping_method[:cost] %>)
|
||||||
</label>
|
</label>
|
||||||
<% else %>
|
<% else %>
|
||||||
<% filtered_rate_hash = @order.rate_hash.select { |m| !(@order.digital_shipping_method && shipping_method[:id] == @order.digital_shipping_method[:id]) } %>
|
<% filtered_rate_hash = @order.rate_hash.select { |m| !(@order.digital_shipping_method && m[:id] == @order.digital_shipping_method[:id]) } %>
|
||||||
<% if filtered_rate_hash.count > 0 %>
|
<% if filtered_rate_hash.count > 0 %>
|
||||||
<% filtered_rate_hash.each do |shipping_method| %>
|
<% filtered_rate_hash.each do |shipping_method| %>
|
||||||
<% next if @order.digital_shipping_method && shipping_method[:id] == @order.digital_shipping_method[:id] %>
|
|
||||||
<label>
|
<label>
|
||||||
<%= radio_button(:order, :shipping_method_id, shipping_method[:id]) %>
|
<%= radio_button(:order, :shipping_method_id, shipping_method[:id]) %>
|
||||||
<% if Spree::Config[:shipment_inc_vat] %>
|
<% if Spree::Config[:shipment_inc_vat] %>
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<% if digital.attachment_file_name.present? %>
|
||||||
|
<%= digital.attachment_file_name %> (<%= number_to_human_size(digital.attachment_file_size) %>)
|
||||||
|
<% else %>
|
||||||
|
<%=t 'broken_file' %>
|
||||||
|
<% end %>
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
require 'factory_girl'
|
|
||||||
|
|
||||||
Dir["#{File.dirname(__FILE__)}/factories/**"].each do |f|
|
|
||||||
fp = File.expand_path(f)
|
|
||||||
require fp
|
|
||||||
end
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
Factory.define :digital, :class => Spree::Digital do |f|
|
FactoryGirl.define do
|
||||||
f.variant { |p| p.association(:variant) }
|
factory :digital, :class => Spree::Digital do |f|
|
||||||
|
f.variant { |p| p.association(:variant) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
Factory.define :digital_link, :class => Spree::DigitalLink do |f|
|
FactoryGirl.define do
|
||||||
f.digital { |p| p.association(:digital) }
|
factory :digital_link, :class => Spree::DigitalLink do |f|
|
||||||
f.line_item { |p| p.association(:line_item) }
|
f.digital { |p| p.association(:digital) }
|
||||||
|
f.line_item { |p| p.association(:line_item) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -10,29 +10,29 @@ describe Spree::DigitalLink do
|
|||||||
|
|
||||||
context "#create" do
|
context "#create" do
|
||||||
it "should have an appropriately long secret" do
|
it "should have an appropriately long secret" do
|
||||||
Factory(:digital_link).secret.length.should == 30
|
FactoryGirl.create(:digital_link).secret.length.should == 30
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have the access counter being an Integer on zero" do
|
it "should have the access counter being an Integer on zero" do
|
||||||
Factory(:digital_link).access_counter.should == 0
|
FactoryGirl.create(:digital_link).access_counter.should == 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#update" do
|
context "#update" do
|
||||||
it "should not change the secret when updated" do
|
it "should not change the secret when updated" do
|
||||||
digital_link = Factory(:digital_link)
|
digital_link = FactoryGirl.create(:digital_link)
|
||||||
secret = digital_link.secret
|
secret = digital_link.secret
|
||||||
digital_link.increment(:access_counter).save
|
digital_link.increment(:access_counter).save
|
||||||
digital_link.secret.should == secret
|
digital_link.secret.should == secret
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should enforce to have an associated digital" do
|
it "should enforce to have an associated digital" do
|
||||||
link = Factory(:digital_link)
|
link = FactoryGirl.create(:digital_link)
|
||||||
lambda { link.update_attributes!(:digital => nil) }.should raise_error(ActiveRecord::RecordInvalid)
|
lambda { link.update_attributes!(:digital => nil) }.should raise_error(ActiveRecord::RecordInvalid)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not allow an empty or too short secret" do
|
it "should not allow an empty or too short secret" do
|
||||||
link = Factory(:digital_link)
|
link = FactoryGirl.create(:digital_link)
|
||||||
lambda { link.update_attributes!(:secret => nil) }.should raise_error(ActiveRecord::RecordInvalid)
|
lambda { link.update_attributes!(:secret => nil) }.should raise_error(ActiveRecord::RecordInvalid)
|
||||||
lambda { link.update_attributes!(:secret => 'x' * 25) }.should raise_error(ActiveRecord::RecordInvalid)
|
lambda { link.update_attributes!(:secret => 'x' * 25) }.should raise_error(ActiveRecord::RecordInvalid)
|
||||||
end
|
end
|
||||||
@@ -40,14 +40,14 @@ describe Spree::DigitalLink do
|
|||||||
|
|
||||||
context "authorization" do
|
context "authorization" do
|
||||||
it "should increment the counter using #authorize!" do
|
it "should increment the counter using #authorize!" do
|
||||||
link = Factory(:digital_link)
|
link = FactoryGirl.create(:digital_link)
|
||||||
link.access_counter.should == 0
|
link.access_counter.should == 0
|
||||||
link.authorize!
|
link.authorize!
|
||||||
link.access_counter.should == 1
|
link.access_counter.should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should not be #authorized? when the access_counter is too high" do
|
it "should not be #authorized? when the access_counter is too high" do
|
||||||
link = Factory(:digital_link)
|
link = FactoryGirl.create(:digital_link)
|
||||||
link.stub(:access_counter => Spree::DigitalConfiguration[:authorized_clicks] - 1)
|
link.stub(:access_counter => Spree::DigitalConfiguration[:authorized_clicks] - 1)
|
||||||
link.authorizable?.should be_true
|
link.authorizable?.should be_true
|
||||||
link.stub(:access_counter => Spree::DigitalConfiguration[:authorized_clicks])
|
link.stub(:access_counter => Spree::DigitalConfiguration[:authorized_clicks])
|
||||||
@@ -55,7 +55,7 @@ describe Spree::DigitalLink do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should not be #authorize! when the created_at date is too far in the past" do
|
it "should not be #authorize! when the created_at date is too far in the past" do
|
||||||
link = Factory(:digital_link)
|
link = FactoryGirl.create(:digital_link)
|
||||||
link.authorize!.should be_true
|
link.authorize!.should be_true
|
||||||
link.stub(:created_at => (Spree::DigitalConfiguration[:authorized_days] * 24 - 1).hours.ago)
|
link.stub(:created_at => (Spree::DigitalConfiguration[:authorized_days] * 24 - 1).hours.ago)
|
||||||
link.authorize!.should be_true
|
link.authorize!.should be_true
|
||||||
@@ -64,7 +64,7 @@ describe Spree::DigitalLink do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should not be #authorized? when both access_counter and created_at are invalid" do
|
it "should not be #authorized? when both access_counter and created_at are invalid" do
|
||||||
link = Factory(:digital_link)
|
link = FactoryGirl.create(:digital_link)
|
||||||
link.authorizable?.should be_true
|
link.authorizable?.should be_true
|
||||||
link.stub(:access_counter => Spree::DigitalConfiguration[:authorized_clicks], :created_at => (Spree::DigitalConfiguration[:authorized_days] * 24 + 1).hours.ago)
|
link.stub(:access_counter => Spree::DigitalConfiguration[:authorized_clicks], :created_at => (Spree::DigitalConfiguration[:authorized_days] * 24 + 1).hours.ago)
|
||||||
link.authorizable?.should be_false
|
link.authorizable?.should be_false
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ describe Spree::Digital do
|
|||||||
|
|
||||||
context "#destroy" do
|
context "#destroy" do
|
||||||
#it "should destroy associated digital_links" do
|
#it "should destroy associated digital_links" do
|
||||||
# digital = Factory(:digital)
|
# digital = FactoryGirl.create(:digital)
|
||||||
# 3.times { digital.digital_links.create! :order => Factory(:order) }
|
# 3.times { digital.digital_links.create! :order => FactoryGirl.create(:order) }
|
||||||
# DigitalLink.count.should == 3
|
# DigitalLink.count.should == 3
|
||||||
# digital.destroy
|
# digital.destroy
|
||||||
# DigitalLink.count.should == 0
|
# DigitalLink.count.should == 0
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ describe Spree::LineItem do
|
|||||||
|
|
||||||
context "#save" do
|
context "#save" do
|
||||||
it "should create one link for a single digital Variant" do
|
it "should create one link for a single digital Variant" do
|
||||||
digital_variant = Factory(:variant, :digital => Factory(:digital))
|
digital_variant = FactoryGirl.create(:variant, :digital => FactoryGirl.create(:digital))
|
||||||
line_item = Factory(:line_item, :variant => digital_variant)
|
line_item = FactoryGirl.create(:line_item, :variant => digital_variant)
|
||||||
links = digital_variant.digital.digital_links
|
links = digital_variant.digital.digital_links
|
||||||
links.all.size.should == 1
|
links.all.size.should == 1
|
||||||
links.first.line_item.should == line_item
|
links.first.line_item.should == line_item
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should create a link for each quantity of a digital Variant, even when quantity changes later" do
|
it "should create a link for each quantity of a digital Variant, even when quantity changes later" do
|
||||||
digital_variant = Factory(:variant, :digital => Factory(:digital))
|
digital_variant = FactoryGirl.create(:variant, :digital => FactoryGirl.create(:digital))
|
||||||
line_item = Factory(:line_item, :variant => digital_variant, :quantity => 5)
|
line_item = FactoryGirl.create(:line_item, :variant => digital_variant, :quantity => 5)
|
||||||
links = digital_variant.digital.digital_links
|
links = digital_variant.digital.digital_links
|
||||||
links.all.size.should == 5
|
links.all.size.should == 5
|
||||||
links.each { |link| link.line_item.should == line_item }
|
links.each { |link| link.line_item.should == line_item }
|
||||||
|
|||||||
+13
-13
@@ -8,18 +8,18 @@ describe Spree::Order do
|
|||||||
|
|
||||||
context "#add_variant" do
|
context "#add_variant" do
|
||||||
it "should add digital Variants of quantity 1 to an order" do
|
it "should add digital Variants of quantity 1 to an order" do
|
||||||
order = Factory(:order)
|
order = FactoryGirl.create(:order)
|
||||||
order.add_variant variant1 = Factory(:variant, :digital => Factory(:digital))
|
order.add_variant variant1 = FactoryGirl.create(:variant, :digital => FactoryGirl.create(:digital))
|
||||||
order.add_variant variant2 = Factory(:variant, :digital => Factory(:digital))
|
order.add_variant variant2 = FactoryGirl.create(:variant, :digital => FactoryGirl.create(:digital))
|
||||||
order.add_variant variant3 = Factory(:variant, :digital => Factory(:digital))
|
order.add_variant variant3 = FactoryGirl.create(:variant, :digital => FactoryGirl.create(:digital))
|
||||||
order.line_items.first.variant.should == variant1
|
order.line_items.first.variant.should == variant1
|
||||||
order.line_items.second.variant.should == variant2
|
order.line_items.second.variant.should == variant2
|
||||||
order.line_items.third.variant.should == variant3
|
order.line_items.third.variant.should == variant3
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should handle quantity higher than 1 when adding one specific digital Variant" do
|
it "should handle quantity higher than 1 when adding one specific digital Variant" do
|
||||||
order = Factory(:order)
|
order = FactoryGirl.create(:order)
|
||||||
digital_variant = Factory(:variant, :digital => Factory(:digital))
|
digital_variant = FactoryGirl.create(:variant, :digital => FactoryGirl.create(:digital))
|
||||||
order.add_variant digital_variant, 3
|
order.add_variant digital_variant, 3
|
||||||
order.line_items.first.quantity.should == 3
|
order.line_items.first.quantity.should == 3
|
||||||
order.add_variant digital_variant, 2
|
order.add_variant digital_variant, 2
|
||||||
@@ -29,23 +29,23 @@ describe Spree::Order do
|
|||||||
|
|
||||||
context "line_item analysis" do
|
context "line_item analysis" do
|
||||||
it "should understand that all products are digital" do
|
it "should understand that all products are digital" do
|
||||||
order = Factory(:order)
|
order = FactoryGirl.create(:order)
|
||||||
3.times do
|
3.times do
|
||||||
order.add_variant Factory(:variant, :digital => Factory(:digital))
|
order.add_variant FactoryGirl.create(:variant, :digital => FactoryGirl.create(:digital))
|
||||||
end
|
end
|
||||||
order.digital?.should be_true
|
order.digital?.should be_true
|
||||||
order.add_variant Factory(:variant, :digital => Factory(:digital)), 4
|
order.add_variant FactoryGirl.create(:variant, :digital => FactoryGirl.create(:digital)), 4
|
||||||
order.digital?.should be_true
|
order.digital?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should understand that not all products are digital" do
|
it "should understand that not all products are digital" do
|
||||||
order = Factory(:order)
|
order = FactoryGirl.create(:order)
|
||||||
3.times do
|
3.times do
|
||||||
order.add_variant Factory(:variant, :digital => Factory(:digital))
|
order.add_variant FactoryGirl.create(:variant, :digital => FactoryGirl.create(:digital))
|
||||||
end
|
end
|
||||||
order.add_variant Factory(:variant) # this is the analog product
|
order.add_variant FactoryGirl.create(:variant) # this is the analog product
|
||||||
order.digital?.should be_false
|
order.digital?.should be_false
|
||||||
order.add_variant Factory(:variant, :digital => Factory(:digital)), 4
|
order.add_variant FactoryGirl.create(:variant, :digital => FactoryGirl.create(:digital)), 4
|
||||||
order.digital?.should be_false
|
order.digital?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+2
-2
@@ -31,11 +31,11 @@ RSpec.configure do |config|
|
|||||||
config.use_transactional_fixtures = true
|
config.use_transactional_fixtures = true
|
||||||
end
|
end
|
||||||
|
|
||||||
require File.expand_path("../factories", __FILE__)
|
Dir[File.join(File.dirname(__FILE__), "factories/*.rb")].each {|f| require f }
|
||||||
|
|
||||||
# not sure if this really adds anything, but this existed in the intial version of the spree_digital rspec testing
|
# 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|
|
RSpec::Matchers.define :have_valid_factory do |factory_name|
|
||||||
match do |model|
|
match do |model|
|
||||||
Factory(factory_name).new_record?.should be_false
|
FactoryGirl.create(factory_name).new_record?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|||||||
s.require_path = 'lib'
|
s.require_path = 'lib'
|
||||||
s.requirements << 'none'
|
s.requirements << 'none'
|
||||||
s.required_ruby_version = '>= 1.8.7'
|
s.required_ruby_version = '>= 1.8.7'
|
||||||
s.add_dependency('spree_core', '~> 1.0.0')
|
s.add_dependency('spree_core', '>= 1.0.0')
|
||||||
|
|
||||||
# test suite
|
# test suite
|
||||||
s.add_development_dependency 'shoulda-matchers'
|
s.add_development_dependency 'shoulda-matchers'
|
||||||
|
|||||||
Reference in new issue
Block a user