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

Move "thinking cat" fixture to lib folder #3824

Merged
merged 4 commits into from
Nov 4, 2020
Merged
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
11 changes: 10 additions & 1 deletion api/lib/spree/api/testing_support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ def current_api_user
end

def image(filename)
File.open(Spree::Api::Engine.root + "spec/fixtures" + filename)
File.open(
File.join(
Spree::Core::Engine.root,
"lib",
"spree",
"testing_support",
"fixtures",
filename
)
)
end

def upload_image(filename)
Expand Down
Binary file removed api/spec/fixtures/thinking-cat.jpg
Binary file not shown.
8 changes: 4 additions & 4 deletions api/spec/requests/spree/api/images_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Spree
expect do
post spree.api_product_images_path(product.id), params: {
image: {
attachment: upload_image('thinking-cat.jpg'),
attachment: upload_image('blank.jpg'),
viewable_type: 'Spree::Variant',
viewable_id: product.master.to_param
},
Expand All @@ -33,7 +33,7 @@ module Spree
end

context "working with an existing product image" do
let!(:product_image) { product.master.images.create!(attachment: image('thinking-cat.jpg')) }
let!(:product_image) { product.master.images.create!(attachment: image('blank.jpg')) }

it "can get a single product image" do
get spree.api_product_image_path(product.id, product_image)
Expand Down Expand Up @@ -77,7 +77,7 @@ module Spree
end

context 'when image belongs to another product' do
let!(:product_image) { another_product.master.images.create!(attachment: image('thinking-cat.jpg')) }
let!(:product_image) { another_product.master.images.create!(attachment: image("blank.jpg")) }
let(:another_product) { create(:product) }

it "cannot get an image of another product" do
Expand All @@ -102,7 +102,7 @@ module Spree
end

context "as a non-admin" do
let(:product_image) { product.master.images.create!(attachment: image('thinking-cat.jpg')) }
let(:product_image) { product.master.images.create!(attachment: image("blank.jpg")) }

it "cannot create an image" do
post spree.api_product_images_path(product.id)
Expand Down
2 changes: 1 addition & 1 deletion api/spec/requests/spree/api/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ module Spree
end

it "can list its line items with images" do
order.line_items.first.variant.images.create!(attachment: image("thinking-cat.jpg"))
order.line_items.first.variant.images.create!(attachment: image("blank.jpg"))

get spree.api_order_path(order)

Expand Down
4 changes: 2 additions & 2 deletions api/spec/requests/spree/api/products_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ module Spree
end

it "gets a single product" do
product.master.images.create!(attachment: image("thinking-cat.jpg"))
product.master.images.create!(attachment: image("blank.jpg"))
product.variants.create!
product.variants.first.images.create!(attachment: image("thinking-cat.jpg"))
product.variants.first.images.create!(attachment: image("blank.jpg"))
product.set_property("spree", "rocks")
product.taxons << create(:taxon)

Expand Down
4 changes: 2 additions & 2 deletions api/spec/requests/spree/api/variants_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module Spree
end

it "variants returned contain images data" do
variant.images.create!(attachment: image("thinking-cat.jpg"))
variant.images.create!(attachment: image("blank.jpg"))

get spree.api_variants_path

Expand Down Expand Up @@ -210,7 +210,7 @@ module Spree
end

it "can see a single variant with images" do
variant.images.create!(attachment: image("thinking-cat.jpg"))
variant.images.create!(attachment: image("blank.jpg"))

subject

Expand Down
2 changes: 1 addition & 1 deletion core/lib/spree/testing_support/factories/image_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

FactoryBot.define do
factory :image, class: 'Spree::Image' do
attachment { Spree::Core::Engine.root.join('spec', 'fixtures', 'thinking-cat.jpg').open }
attachment { Spree::Core::Engine.root.join('lib', 'spree', 'testing_support', 'fixtures', 'blank.jpg').open }
end
end
2 changes: 1 addition & 1 deletion core/lib/spree/testing_support/factories/taxon_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
parent_id { nil }

trait :with_icon do
icon { Spree::Core::Engine.root.join('spec', 'fixtures', 'thinking-cat.jpg').open }
icon { Spree::Core::Engine.root.join('lib', 'spree', 'testing_support', 'fixtures', 'blank.jpg').open }
end
end
end
Binary file added core/lib/spree/testing_support/fixtures/blank.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed core/spec/fixtures/thinking-cat.jpg
Binary file not shown.
10 changes: 5 additions & 5 deletions core/spec/models/spree/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@
end

describe 'attachment details' do
let(:image_file) { File.open(File.join('spec', 'fixtures', 'thinking-cat.jpg')) }
let(:image_file) { File.open(File.join('lib', 'spree', 'testing_support', 'fixtures', 'blank.jpg')) }
subject { create(:image, attachment: image_file) }

it 'returns if attachment is present' do
expect(subject.attachment_present?).to be_truthy
end

it 'returns attachment filename' do
expect(subject.filename).to end_with('thinking-cat.jpg')
expect(subject.filename).to end_with('blank.jpg')
end

it 'returns attachment url' do
expect(subject.url(:product)).to include('thinking-cat.jpg')
expect(subject.url(:product)).to include('blank.jpg')
end

it 'computes attachment width' do
expect(subject.attachment_width).to eq(489)
expect(subject.attachment_width).to eq(1)
end

it 'computes attachment height' do
expect(subject.attachment_height).to eq(490)
expect(subject.attachment_height).to eq(1)
end
end
end
2 changes: 1 addition & 1 deletion core/spec/models/spree/product_duplicator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Spree
let(:product) { create(:product, properties: [create(:property, name: "MyProperty")]) }
let!(:duplicator) { Spree::ProductDuplicator.new(product) }

let(:image) { File.open(File.expand_path('../../fixtures/thinking-cat.jpg', __dir__)) }
let(:image) { File.open(Spree::Core::Engine.root.join('lib', 'spree', 'testing_support', 'fixtures', 'blank.jpg')) }
let(:params) { { viewable_id: product.master.id, viewable_type: 'Spree::Variant', attachment: image, alt: "position 1", position: 1 } }

before do
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ class Extension < Spree::Base

context "#images" do
let(:product) { create(:product) }
let(:image) { File.open(File.expand_path('../../fixtures/thinking-cat.jpg', __dir__)) }
let(:image) { File.open(Spree::Core::Engine.root.join('lib', 'spree', 'testing_support', 'fixtures', 'blank.jpg')) }
let(:params) { { viewable_id: product.master.id, viewable_type: 'Spree::Variant', attachment: image, alt: "position 2", position: 2 } }

before do
Expand Down
2 changes: 1 addition & 1 deletion core/spec/support/shared_examples/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
before do
subject.send(
:"#{attachment_name}=",
File.open(File.join('spec', 'fixtures', 'thinking-cat.jpg'))
File.open(File.join('lib', 'spree', 'testing_support', 'fixtures', 'blank.jpg'))
)
end

Expand Down
10 changes: 7 additions & 3 deletions frontend/spec/features/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@

before do
# Need to have two images to trigger the error
image = File.open(File.expand_path('../fixtures/thinking-cat.jpg', __dir__))
image = File.open(
File.join(Spree::Core::Engine.root, "lib", "spree", "testing_support", "fixtures", "blank.jpg")
)
product.images.create!(attachment: image)
product.images.create!(attachment: image)

Expand Down Expand Up @@ -184,7 +186,9 @@
let(:product) { Spree::Product.find_by(name: "Ruby on Rails Baseball Jersey") }

before do
image = File.open(File.expand_path('../fixtures/thinking-cat.jpg', __dir__))
image = File.open(
File.join(Spree::Core::Engine.root, "lib", "spree", "testing_support", "fixtures", "blank.jpg")
)
v1 = product.variants.create!(price: 9.99)
v2 = product.variants.create!(price: 10.99)
v1.images.create!(attachment: image)
Expand All @@ -193,7 +197,7 @@

it "should not display no image available" do
visit spree.root_path
expect(page).to have_xpath("//img[contains(@src,'thinking-cat')]")
expect(page).to have_xpath("//img[contains(@src,'blank')]")
end
end

Expand Down
Binary file removed frontend/spec/fixtures/thinking-cat.jpg
Binary file not shown.