Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #185 from spree-contrib/fix/store_paperclip_attach…
Browse files Browse the repository at this point in the history
…ment

Fix problem with Spree::Store logo attachment
  • Loading branch information
damianlegawiec authored Nov 5, 2018
2 parents 3816c18 + ab035a9 commit aa973b8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
9 changes: 3 additions & 6 deletions app/models/spree/store_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ module Spree
has_attached_file :logo,
styles: { mini: '48x48>', small: '100x100>', medium: '250x250>' },
default_style: :medium,
url: 'stores/:id/:style/:basename.:extension',
path: 'stores/:id/:style/:basename.:extension',
url: '/stores/:id/:style/:filename',
path: ':rails_root/public/stores/:id/:style/:filename',
convert_options: { all: '-strip -auto-orient' }

if respond_to? :logo_file_name
validates_attachment_file_name :logo, matches: [/png\Z/i, /jpe?g\Z/i]
end

validates_attachment_file_name :logo, matches: [/png\Z/i, /jpe?g\Z/i], if: -> { logo.present? }
end
end
2 changes: 1 addition & 1 deletion app/views/spree/admin/stores/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

<div data-hook="admin_store_form_fields_right" class="col-md-6">
<div data-hook="logo">
<%= image_tag @store.logo %>
<%= image_tag @store.logo.url %>
<%= f.field_container :logo, class: ['form-group'] do %>
<%= f.label :logo, Spree.t(:logo) %><br />
<%= f.file_field :logo %>
Expand Down
12 changes: 12 additions & 0 deletions spec/controllers/spree/admin/stores_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@
describe Spree::Admin::StoresController do
stub_authorization!

let!(:store) { FactoryBot.create(:store) }
let(:image_file) { Rack::Test::UploadedFile.new(SpreeMultiDomain::Engine.root.join('spec', 'fixtures', 'thinking-cat.jpg')) }
let(:store_with_logo) { FactoryBot.create(:store, logo: image_file) }

describe "on :index" do
it "renders index" do
spree_get :index
response.should be_success
end
end

context 'update' do
it 'can update logo' do
spree_put :update, id: store.to_param, store: { logo: image_file }

expect(store.reload.logo_file_name).to eq image_file.original_filename
end
end
end
Binary file added spec/fixtures/thinking-cat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit aa973b8

Please sign in to comment.