diff --git a/app/controllers/spree/admin/digitals_controller.rb b/app/controllers/spree/admin/digitals_controller.rb index 23914958..29509c6e 100644 --- a/app/controllers/spree/admin/digitals_controller.rb +++ b/app/controllers/spree/admin/digitals_controller.rb @@ -3,6 +3,19 @@ module Admin class DigitalsController < ResourceController belongs_to "spree/product", :find_by => :slug + def create + invoke_callbacks(:create, :before) + @object.attributes = permitted_resource_params + + if @object.valid? + super + else + invoke_callbacks(:create, :fails) + flash[:error] = @object.errors.full_messages.join(", ") + redirect_to location_after_save + end + end + protected def location_after_save spree.admin_product_digitals_path(@product) @@ -17,4 +30,4 @@ def permitted_digital_attributes end end end -end +end \ No newline at end of file diff --git a/app/models/spree/digital.rb b/app/models/spree/digital.rb index ff59eecd..6ba4bac9 100644 --- a/app/models/spree/digital.rb +++ b/app/models/spree/digital.rb @@ -5,6 +5,7 @@ class Digital < ActiveRecord::Base has_attached_file :attachment, path: ":rails_root/private/digitals/:id/:basename.:extension" do_not_validate_attachment_file_type :attachment + validates_attachment_presence :attachment if Paperclip::Attachment.default_options[:storage] == :s3 attachment_definitions[:attachment][:s3_permissions] = :private diff --git a/readme.md b/readme.md index cfcea2d4..7a0839fb 100644 --- a/readme.md +++ b/readme.md @@ -1,16 +1,15 @@ -[![Compatibility](https://img.shields.io/badge/spree%20compatibility-3.0-pink.svg)](https://github.com/halo/spree_digital/blob/master/Versionfile) -[![Build Status](https://travis-ci.org/halo/spree_digital.png?branch=master)](https://travis-ci.org/halo/spree_digital) -[![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://github.com/halo/spree_digital/blob/master/LICENSE.md) -[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/halo/spree_digital) +[![Compatibility](https://img.shields.io/badge/spree%20compatibility-3.0-pink.svg)](https://github.com/spree-contrib/spree_digital/blob/3-0-stable/Versionfile) +[![Build Status](https://travis-ci.org/spree-contrib/spree_digital.png?branch=3-0-stable)](https://travis-ci.org/spree-contrib/spree_digital) +[![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://github.com/spree-contrib/spree_digital/blob/3-0-stable/LICENSE.md) +[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/spree-contrib/spree_digital) # Spree Digital This is a spree extension to enable downloadable products (ebooks, MP3s, videos, etc). -In the [Versionfile](https://github.com/halo/spree_digital/blob/master/Versionfile) you can see which -[spree_digital branch](https://github.com/halo/spree_digital/branches/all?query=stable) supports which +In the [Versionfile](https://github.com/spree-contrib/spree_digital/blob/3-0-stable/Versionfile) you can see which +[spree_digital branch](https://github.com/spree-contrib/spree_digital/branches/all?query=stable) supports which [Spree version](https://github.com/spree/spree/branches/all?query=stable). -The master branch is not considered stable and corresponds to the [spree master branch](https://github.com/spree/spree). This documentation is not complete and possibly out of date in some cases. There are features that have been implemented that are not documented here, please look at the source for complete documentation. diff --git a/spec/controllers/admin/digitals_controller_spec.rb b/spec/controllers/admin/digitals_controller_spec.rb index 51e8ff58..b62f974f 100644 --- a/spec/controllers/admin/digitals_controller_spec.rb +++ b/spec/controllers/admin/digitals_controller_spec.rb @@ -57,6 +57,16 @@ }.to change(Spree::Digital, :count).by(1) end end + + context 'for an invalid object' do + it 'redirects to the index page' do + expect { + spree_post :create, product_id: product.slug, digital: { variant_id: product.master.id } # fail validation by not passing attachment + expect(flash[:error]).to eq "Attachment can't be blank" + expect(response).to redirect_to(spree.admin_product_digitals_path(product)) + }.to change(Spree::Digital, :count).by(0) + end + end end context '#destroy' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b5b12e3b..38c17ca1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,6 +20,13 @@ require 'ffaker' require 'shoulda-matchers' +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end +end + Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f } require 'spree/testing_support/factories' diff --git a/spree_digital.gemspec b/spree_digital.gemspec index 10b21c40..06182f2f 100644 --- a/spree_digital.gemspec +++ b/spree_digital.gemspec @@ -24,8 +24,8 @@ Gem::Specification.new do |s| s.add_development_dependency 'coffee-script' s.add_development_dependency 'factory_girl_rails', '~> 4.5.0' s.add_development_dependency 'rspec-rails', '~> 3.0' - s.add_development_dependency 'rspec-activemodel-mocks', '1.0.0' - s.add_development_dependency 'sass-rails', '~> 4.0.2' + s.add_development_dependency 'rspec-activemodel-mocks', '~> 1.0.0' + s.add_development_dependency 'sass-rails', '~> 5.0.4' s.add_development_dependency 'sqlite3' s.add_development_dependency 'ffaker' s.add_development_dependency 'database_cleaner', '1.0.1'