Skip to content

Commit 8bc29f1

Browse files
committed
test(image-builder): include tests for shrine case
1 parent e684a1b commit 8bc29f1

1 file changed

Lines changed: 111 additions & 35 deletions

File tree

spec/features/image_builder_spec.rb

Lines changed: 111 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,64 +12,140 @@ def create_photo_invoice
1212
create_invoice(photo: File.new(ENGINE_RAILS_ROOT + 'spec/assets/Rails.png'))
1313
end
1414

15-
context "without options" do
16-
before do
17-
register_index(Invoice) do
18-
image_column :photo
15+
def create_picture_invoice
16+
create_invoice(picture: File.new(ENGINE_RAILS_ROOT + 'spec/assets/Rails.png'))
17+
end
18+
19+
describe '#shrine' do
20+
context "without options" do
21+
before do
22+
register_index(Invoice) do
23+
image_column :picture
24+
end
25+
26+
create_picture_invoice
27+
visit admin_invoices_path
1928
end
2029

21-
create_photo_invoice
22-
visit admin_invoices_path
30+
it "shows the attachent as an image" do
31+
img = page.find('img')
32+
expect(img[:src]).not_to be(nil)
33+
end
2334
end
2435

25-
it "shows the attachent as an image" do
26-
img = page.find('img')
27-
expect(img[:src]).to match(/Rails.png/)
36+
context "passing style option" do
37+
let(:invoice) { create_picture_invoice }
38+
39+
before do
40+
register_index(Invoice) do
41+
image_column :picture, style: :jpg_small
42+
end
43+
44+
invoice.picture_derivatives!
45+
invoice.save!
46+
visit admin_invoices_path
47+
end
48+
49+
it "shows the attachent as an image" do
50+
img = page.find('img')
51+
expect(img[:src]).not_to be(nil)
52+
end
53+
54+
it 'has the derivative' do
55+
expect(invoice.picture_derivatives).to include(:jpg_small)
56+
end
2857
end
29-
end
3058

31-
context "passing style option" do
32-
before do
33-
register_index(Invoice) do
34-
image_column :photo, style: :thumb
59+
context "passing a block" do
60+
before do
61+
register_show(Invoice) do
62+
image_row(:picture, &:picture)
63+
end
64+
65+
visit admin_invoice_path(create_picture_invoice)
3566
end
3667

37-
create_photo_invoice
38-
visit admin_invoices_path
68+
it "shows the attachent as an image" do
69+
img = page.find('img')
70+
expect(img[:src]).not_to be(nil)
71+
end
3972
end
4073

41-
it "shows the attachent as an image" do
42-
img = page.find('img')
43-
expect(img[:src]).to match(%r{thumb/Rails.png})
74+
context "using a label" do
75+
before do
76+
register_show(Invoice) do
77+
image_row("My Picture", :picture)
78+
end
79+
80+
visit admin_invoice_path(create_picture_invoice)
81+
end
82+
83+
it "shows custom label" do
84+
expect(page).to have_content("My Picture")
85+
end
4486
end
4587
end
4688

47-
context "passing a block" do
48-
before do
49-
register_show(Invoice) do
50-
image_row(:photo, &:photo)
89+
describe '#paperclip' do
90+
context "without options" do
91+
before do
92+
register_index(Invoice) do
93+
image_column :photo
94+
end
95+
96+
create_photo_invoice
97+
visit admin_invoices_path
5198
end
5299

53-
visit admin_invoice_path(create_photo_invoice)
100+
it "shows the attachent as an image" do
101+
img = page.find('img')
102+
expect(img[:src]).to match(/Rails.png/)
103+
end
54104
end
55105

56-
it "shows the attachent as an image" do
57-
img = page.find('img')
58-
expect(img[:src]).to match(/Rails.png/)
106+
context "passing style option" do
107+
before do
108+
register_index(Invoice) do
109+
image_column :photo, style: :thumb
110+
end
111+
112+
create_photo_invoice
113+
visit admin_invoices_path
114+
end
115+
116+
it "shows the attachent as an image" do
117+
img = page.find('img')
118+
expect(img[:src]).to match(%r{thumb/Rails.png})
119+
end
59120
end
60-
end
61121

62-
context "using a label" do
63-
before do
64-
register_show(Invoice) do
65-
image_row("Mi foto", :photo)
122+
context "passing a block" do
123+
before do
124+
register_show(Invoice) do
125+
image_row(:photo, &:photo)
126+
end
127+
128+
visit admin_invoice_path(create_photo_invoice)
66129
end
67130

68-
visit admin_invoice_path(create_photo_invoice)
131+
it "shows the attachent as an image" do
132+
img = page.find('img')
133+
expect(img[:src]).to match(/Rails.png/)
134+
end
69135
end
70136

71-
it "shows custom label" do
72-
expect(page).to have_content("Mi Foto")
137+
context "using a label" do
138+
before do
139+
register_show(Invoice) do
140+
image_row("Mi foto", :photo)
141+
end
142+
143+
visit admin_invoice_path(create_photo_invoice)
144+
end
145+
146+
it "shows custom label" do
147+
expect(page).to have_content("Mi Foto")
148+
end
73149
end
74150
end
75151
end

0 commit comments

Comments
 (0)