New photo: show an h2 with the name of the current set

Also don't show a sets dropdown if the user has no sets.
This commit is contained in:
Miles Gould
2013-07-18 14:26:27 +01:00
parent 2b863cd62e
commit 96e66cd9bb
4 changed files with 37 additions and 9 deletions

View File

@@ -31,9 +31,10 @@ class PhotosController < ApplicationController
page = params[:page] || 1
@flickr_auth = current_member.auth('flickr')
@current_set = params[:set]
if @flickr_auth
@sets = current_member.flickr_sets
photos, total = current_member.flickr_photos(page, params[:set])
photos, total = current_member.flickr_photos(page, @current_set)
@photos = WillPaginate::Collection.create(page, 30, total) do |pager|
pager.replace photos

View File

@@ -7,7 +7,10 @@
= link_to @flickr_auth.name, "http://flickr.com/photos/#{@flickr_auth.uid}"
Please select a photo from your recent uploads.
- if @sets
- if @sets and @current_set
%h2= @sets.key(@current_set)
- if @sets and @sets.length > 0
%p
= form_tag(new_photo_path, :method => :get, :class => 'form-inline') do
= label_tag :set, "Choose a photo set:", :class => 'control-label'

View File

@@ -27,7 +27,7 @@ describe PhotosController do
@member = FactoryGirl.create(:member)
sign_in @member
@member.stub(:flickr_photos) { [[], 0] }
@member.stub(:flickr_sets) { [] }
@member.stub(:flickr_sets) { { "foo" => "bar" } }
controller.stub(:current_member) { @member }
end
@@ -42,6 +42,11 @@ describe PhotosController do
assigns(:planting_id).should eq "5"
end
it "assigns the current set as @current_set" do
get :new, { :set => 'foo' }
assigns(:current_set).should eq "foo"
end
end
describe "POST create" do

View File

@@ -11,16 +11,35 @@ describe "photos/new" do
pager.replace([])
end
assign(:photos, photos)
assign(:sets, {"foo" => "bar"})
assign(:flickr_auth, FactoryGirl.create(:flickr_authentication, :member => @member))
render
end
it "shows a dropdown with sets from Flickr" do
assert_select "select#set"
end
it "shows a list of photos" do
render
assert_select "ul.thumbnails"
end
context "user has no photosets" do
it "doesn't show a dropdown with sets from Flickr" do
assert_select "select#set", false
end
end
context "user has photosets" do
before(:each) do
assign(:sets, {"foo" => "bar"}) # Hash of names => IDs
end
it "shows a dropdown with sets from Flickr" do
render
assert_select "select#set"
end
it "shows the current photoset" do
assign(:current_set, "bar") # the ID of the set
render
assert_select "h2", "foo" # the name of the set
end
end
end