Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure nothing goes wrong #95

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/controllers/spree/admin/digitals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -17,4 +30,4 @@ def permitted_digital_attributes
end
end
end
end
end
1 change: 1 addition & 0 deletions app/models/spree/digital.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 10 additions & 0 deletions spec/controllers/admin/digitals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions spree_digital.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down