From c997f03bc188b502a1b6a3f7434277a5448bded4 Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Tue, 7 Aug 2012 10:48:36 -0400 Subject: [PATCH 1/4] Adding initial controller specs. Both failing --- Gemfile | 2 +- spec/controllers/digitals_controller_spec.rb | 43 ++++++++++++++++++++ spec/models/order_spec.rb | 1 - spec/spec_helper.rb | 24 ++++------- 4 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 spec/controllers/digitals_controller_spec.rb diff --git a/Gemfile b/Gemfile index 4e3bea9..ff9e196 100644 --- a/Gemfile +++ b/Gemfile @@ -11,6 +11,6 @@ group :test do end end -gem 'spree', '~> 1.1.2' +gem 'spree', '~> 1.1.3' gemspec diff --git a/spec/controllers/digitals_controller_spec.rb b/spec/controllers/digitals_controller_spec.rb new file mode 100644 index 0000000..93f30b4 --- /dev/null +++ b/spec/controllers/digitals_controller_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe Spree::Admin::DigitalsController do + before do + @product = FactoryGirl.create :product + + controller.stub :authorize! => true + end + + let(:product) { @product } + + context "with variants" do + before do + # TODO add variants with digital + end + + it "should display an empty page when no digitals exist" do + + end + + it "should display list of digitals when they exist" do + + end + end + + context "without variants" do + render_views + + it "should display an empty page when no digitals exist" do + spree_get :index, "product_id" => product.permalink + response.code.should == "200" + response.body.should include("This product has no variants") + end + + it "should display list of digitals when they exist" do + @digital = FactoryGirl.create :digital, :variant => product.master + spree_get :index, :product_id => product.permalink + response.code.should == "200" + + end + + end +end \ No newline at end of file diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index 554409d..8314c82 100644 --- a/spec/models/order_spec.rb +++ b/spec/models/order_spec.rb @@ -81,7 +81,6 @@ describe Spree::Order do order.rate_hash.count.should == 1 order.rate_hash.first.shipping_method.calculator.class.should_not == Spree::Calculator::DigitalDelivery - puts "SHIPP #{order.rate_hash.first}" order.rate_hash.first.cost.should == 10.0 end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index aa638f7..1b4db0a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,34 +1,24 @@ -# Configure Rails Environment ENV["RAILS_ENV"] = "test" - require File.expand_path("../dummy/config/environment.rb", __FILE__) - require 'rspec/rails' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f } -# Requires factories defined in spree_core require 'spree/core/testing_support/factories' +require 'spree/core/testing_support/env' +require 'spree/core/testing_support/controller_requests' +require 'spree/core/url_helpers' RSpec.configure do |config| - # == Mock Framework - # - # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: - # - # config.mock_with :mocha - # config.mock_with :flexmock - # config.mock_with :rr config.mock_with :rspec - - # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" - - # 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 = 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 } From ae106dd280162bbbb8290a5d2218be5b695b3461 Mon Sep 17 00:00:00 2001 From: Chris Lindensmith Date: Sat, 14 Jul 2012 21:22:18 -0700 Subject: [PATCH 2/4] fix admin display of digital products copied from funkensturm's fix. --- app/views/spree/admin/digitals/index.html.erb | 4 ++-- config/locales/en.yml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/spree/admin/digitals/index.html.erb b/app/views/spree/admin/digitals/index.html.erb index a7d7004..a746a58 100644 --- a/app/views/spree/admin/digitals/index.html.erb +++ b/app/views/spree/admin/digitals/index.html.erb @@ -10,9 +10,9 @@ <% else %> This product has no variants. - <% if @product.master.digital? %> + <% if @product.master.digital? %> A digital version of this product currently exists: - <%= render @product.master.digital %> + <%= render @product.master.digitals %> <% end %> <%= render 'form', :variant => @product.master %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 05f1758..cf62fd6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -12,5 +12,6 @@ en: mp3: Audio MP3 mobi: Kindle eBook epub: ePub eBook + pdf: pdf eBook spree_digital: upload: Upload \ No newline at end of file From 78392380267dfb198a1b1615c8fb18f96d7051f6 Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Tue, 7 Aug 2012 10:55:05 -0400 Subject: [PATCH 3/4] Controller tests passing --- app/views/spree/admin/digitals/_form.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/spree/admin/digitals/_form.html.erb b/app/views/spree/admin/digitals/_form.html.erb index 7ac9233..4c982ce 100644 --- a/app/views/spree/admin/digitals/_form.html.erb +++ b/app/views/spree/admin/digitals/_form.html.erb @@ -1,6 +1,6 @@
- <%= form_for(:digital, :url => { :controller => 'digitals', :action => 'create' }, :html => { :multipart => true }) do |f| %> + <%= form_for(:digital, :url => admin_product_digitals_path(@product), :method => :create, :multipart => true ) do |f| %>
<%= Spree::Variant.model_name.human %> "<%= variant.options_text %>" @@ -11,7 +11,7 @@ <% variant.digitals.each do |digital| %>
  • <%= render digital %>   - <%= link_to t("delete_file"), admin_product_digital_url(:id => variant.digitals.first.id), :confirm => t('delete_file_cofirmation', :filename => variant.digitals.first.attachment_file_name), :method => :delete %> + <%= link_to t("delete_file"), admin_product_digital_url(@product, digital), :confirm => t('delete_file_cofirmation', :filename => digital.attachment_file_name), :method => :delete %>
  • <% end %> From 156f54e9090829168134e970b2f5afcc7d315812 Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Tue, 7 Aug 2012 11:16:24 -0400 Subject: [PATCH 4/4] Adding specs for deletion/destroy on Digital and DigitalLink --- spec/models/digital_spec.rb | 16 ++++++++-------- spec/models/variant_spec.rb | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 spec/models/variant_spec.rb diff --git a/spec/models/digital_spec.rb b/spec/models/digital_spec.rb index 5ea6acf..7ff1882 100644 --- a/spec/models/digital_spec.rb +++ b/spec/models/digital_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' describe Spree::Digital do @@ -12,13 +12,13 @@ describe Spree::Digital do end context "#destroy" do - #it "should destroy associated digital_links" do - # digital = FactoryGirl.create(:digital) - # 3.times { digital.digital_links.create! :order => FactoryGirl.create(:order) } - # DigitalLink.count.should == 3 - # digital.destroy - # DigitalLink.count.should == 0 - #end + it "should destroy associated digital_links" do + digital = FactoryGirl.create(:digital) + 3.times { digital.digital_links.create!({ :line_item => FactoryGirl.create(:line_item) }, :without_protection => true) } + Spree::DigitalLink.count.should == 3 + digital.destroy + Spree::DigitalLink.count.should == 0 + end end end diff --git a/spec/models/variant_spec.rb b/spec/models/variant_spec.rb new file mode 100644 index 0000000..6b30874 --- /dev/null +++ b/spec/models/variant_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe Spree::Variant do + before do + @product = FactoryGirl.create :product + @digital = FactoryGirl.create :digital, :variant => @product.master + end + + let(:variant) { @product.master } + + 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) + end +end \ No newline at end of file