Photo#show for signed in and not signed in, and other members

This commit is contained in:
Brenda Wallace
2017-04-17 14:20:44 +12:00
committed by Shiny
parent bbdc54cb69
commit cff1d8bfb9

View File

@@ -13,26 +13,17 @@
require 'rails_helper'
describe "photos/show" do
before(:each) do
@member = FactoryGirl.create(:member)
controller.stub(:current_user) { @member }
end
let(:photo) { FactoryGirl.create :photo, owner: member }
before { @photo = photo }
let(:harvest) { FactoryGirl.create :harvest, owner: @member }
let(:planting) { FactoryGirl.create :planting, owner: @member }
let(:seed) { FactoryGirl.create :seed, owner: @member }
let(:garden) { FactoryGirl.create :garden, owner: @member }
let(:member) { FactoryGirl.create :member }
context "CC-licensed photo" do
before(:each) do
@photo = assign(:photo, FactoryGirl.create(:photo, owner: @member))
@photo.harvests << harvest
@photo.plantings << planting
@photo.seeds << seed
@photo.gardens << garden
render
end
let(:harvest) { FactoryGirl.create :harvest, owner: member }
let(:planting) { FactoryGirl.create :planting, owner: member }
let(:seed) { FactoryGirl.create :seed, owner: member }
let(:garden) { FactoryGirl.create :garden, owner: member }
shared_examples "photo data renders" do
it "shows the image" do
assert_select "img[src='#{@photo.fullsize_url}']"
end
@@ -41,19 +32,10 @@ describe "photos/show" do
assert_select "a", href: @photo.owner
end
it "links to the CC license" do
assert_select "a", href: @photo.license_url,
text: @photo.license_name
end
it "shows a link to the original image" do
assert_select "a", href: @photo.link_url, text: "View on Flickr"
end
it "has a delete button" do
assert_select "a[href='#{photo_path(@photo)}']"
end
it "links to harvest" do
assert_select "a", href: harvest_path(harvest)
end
@@ -68,8 +50,61 @@ describe "photos/show" do
end
end
shared_examples "No links to change data" do
it "does not have a delete button" do
assert_select "a[href='#{photo_path(@photo)}']", false
end
end
context "signed in as owner" do
before(:each) do
controller.stub(:current_user) { member }
render
end
include_examples "photo data renders"
it "has a delete button" do
assert_select "a[href='#{photo_path(@photo)}']"
end
end
context "signed in as another member" do
before(:each) do
controller.stub(:current_user) { FactoryGirl.create :member }
render
end
include_examples "photo data renders"
include_examples "No links to change data"
end
context "not signed in" do
before(:each) do
controller.stub(:current_user) { nil }
render
end
include_examples "photo data renders"
include_examples "No links to change data"
end
context "CC-licensed photo" do
before(:each) do
controller.stub(:current_user) { nil }
# @photo = assign(:photo, FactoryGirl.create(:photo, owner: @member))
@photo.harvests << harvest
@photo.plantings << planting
@photo.seeds << seed
@photo.gardens << garden
render
end
it "links to the CC license" do
assert_select "a", href: @photo.license_url,
text: @photo.license_name
end
end
context "unlicensed photo" do
before(:each) do
controller.stub(:current_user) { nil }
@photo = assign(:photo, FactoryGirl.create(:unlicensed_photo))
render
end