From 96e66cd9bbf6b5caa511a92d51c0d7ea853882d7 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Thu, 18 Jul 2013 14:26:27 +0100 Subject: [PATCH] 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. --- app/controllers/photos_controller.rb | 3 ++- app/views/photos/new.html.haml | 5 +++- spec/controllers/photos_controller_spec.rb | 7 ++++- spec/views/photos/new.html.haml_spec.rb | 31 +++++++++++++++++----- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index ac88a7ce3..8b2d6e561 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -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 diff --git a/app/views/photos/new.html.haml b/app/views/photos/new.html.haml index ac9bee2bf..dd9c899c0 100644 --- a/app/views/photos/new.html.haml +++ b/app/views/photos/new.html.haml @@ -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' diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 983ed1e0c..9618c5b45 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -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 diff --git a/spec/views/photos/new.html.haml_spec.rb b/spec/views/photos/new.html.haml_spec.rb index a9f5dc290..5ab726a49 100644 --- a/spec/views/photos/new.html.haml_spec.rb +++ b/spec/views/photos/new.html.haml_spec.rb @@ -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