Skip to content

Commit

Permalink
Merge pull request rubyforgood#168 from jaysonesmith/valid_image_tweak
Browse files Browse the repository at this point in the history
Rspec syntax mod for valid_image check
  • Loading branch information
mxygem authored Oct 25, 2017
2 parents cc280de + 8393b8b commit bfb9c88
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/views/items/_item.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<%= hidden_field_tag 'image_height', item.image_height %>

<td>
<% if item.has_valid_image? %>
<% if item.valid_image? %>
<%= image_tag item.image_url, width: item.image_width,
height: item.image_height %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion lib/amazon_product_api/search_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def valid?
price != "$0.00"
end

def has_valid_image?
def valid_image?
image.valid?
end

Expand Down
20 changes: 10 additions & 10 deletions spec/lib/amazon_product_api/search_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
end

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

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

0 comments on commit bfb9c88

Please sign in to comment.