Skip to content

Commit bfb9c88

Browse files
authored
Merge pull request #168 from jaysonesmith/valid_image_tweak
Rspec syntax mod for valid_image check
2 parents cc280de + 8393b8b commit bfb9c88

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

app/views/items/_item.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<%= hidden_field_tag 'image_height', item.image_height %>
1111

1212
<td>
13-
<% if item.has_valid_image? %>
13+
<% if item.valid_image? %>
1414
<%= image_tag item.image_url, width: item.image_width,
1515
height: item.image_height %>
1616
<% end %>

lib/amazon_product_api/search_item.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def valid?
3131
price != "$0.00"
3232
end
3333

34-
def has_valid_image?
34+
def valid_image?
3535
image.valid?
3636
end
3737

spec/lib/amazon_product_api/search_item_spec.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
end
1515

1616
describe "#valid_image?" do
17-
context "when all image attributes are valid" do
18-
subject { AmazonProductAPI::SearchItem.new(image_url: "image url",
19-
image_height: 600,
20-
image_width: 800) }
21-
it { should have_valid_image }
17+
it "returns true for valid data" do
18+
item = AmazonProductAPI::SearchItem.new(image_url: "image url",
19+
image_height: 600,
20+
image_width: 800)
21+
expect(item.valid_image?).to eq true
2222
end
2323

24-
context "when there is no image url" do
25-
subject { AmazonProductAPI::SearchItem.new(image_url: nil,
26-
image_height: 100,
27-
image_width: 100) }
28-
it { should_not have_valid_image }
24+
it "returns false for invalid data" do
25+
item = AmazonProductAPI::SearchItem.new(image_url: nil,
26+
image_height: 600,
27+
image_width: 800)
28+
expect(item.valid_image?).to eq false
2929
end
3030
end
3131
end

0 commit comments

Comments
 (0)