diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 024bd1578..2014f5e11 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -37,3 +37,4 @@ submit the change with your pull request. - Gary Traffanstedt / [blimey85](https://github.com/blimey85) - Yaw Boakye / [yawboakye](https://github.com/yawboakye) - Ryan Clark / [IAMRYO](https://github.com/IAMRYO) +- Marty Hines / [martyhines](https://github.com/martyhines) diff --git a/app/controllers/gardens_controller.rb b/app/controllers/gardens_controller.rb index 8eb5608a6..a349f9326 100644 --- a/app/controllers/gardens_controller.rb +++ b/app/controllers/gardens_controller.rb @@ -3,7 +3,11 @@ class GardensController < ApplicationController # GET /gardens # GET /gardens.json def index - @gardens = Garden.all + @gardens = Garden.paginate(:page => params[:page]) + @owner = Member.find_by_slug(params[:owner]) + if @owner + @gardens = @owner.gardens.paginate(:page => params[:page]) + end respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/plantings_controller.rb b/app/controllers/plantings_controller.rb index 9d4b3f0b9..27721349f 100644 --- a/app/controllers/plantings_controller.rb +++ b/app/controllers/plantings_controller.rb @@ -7,6 +7,10 @@ class PlantingsController < ApplicationController # GET /plantings.json def index @plantings = Planting.paginate(:page => params[:page]) + @owner = Member.find_by_slug(params[:owner]) + if @owner + @plantings = @owner.plantings.paginate(:page => params[:page]) + end respond_to do |format| format.html # index.html.erb diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 4003d546a..c7abf48fd 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -8,6 +8,10 @@ class PostsController < ApplicationController def index @posts = Post.paginate(:page => params[:page]) + @author = Member.find_by_slug(params[:author]) + if @author + @posts = @author.posts.paginate(:page => params[:page]) + end respond_to do |format| format.html # index.html.haml diff --git a/app/controllers/seeds_controller.rb b/app/controllers/seeds_controller.rb index 1920ebe11..82411c87b 100644 --- a/app/controllers/seeds_controller.rb +++ b/app/controllers/seeds_controller.rb @@ -3,10 +3,10 @@ class SeedsController < ApplicationController # GET /seeds # GET /seeds.json def index - @seeds = Seed.all - @owner = Member.find_by_id(params[:owner_id]) + @seeds = Seed.paginate(:page => params[:page]) + @owner = Member.find_by_slug(params[:owner]) if @owner - @seeds = @owner.seeds.all + @seeds = @owner.seeds.paginate(:page => params[:page]) end respond_to do |format| diff --git a/app/models/seed.rb b/app/models/seed.rb index cff7f348d..d1aecbfac 100644 --- a/app/models/seed.rb +++ b/app/models/seed.rb @@ -8,6 +8,8 @@ class Seed < ActiveRecord::Base belongs_to :crop belongs_to :owner, :class_name => 'Member', :foreign_key => 'owner_id' + default_scope order("created_at desc") + validates :quantity, :numericality => { :only_integer => true }, :allow_nil => true diff --git a/app/views/crops/_find_seeds.html.haml b/app/views/crops/_find_seeds.html.haml new file mode 100644 index 000000000..02d56b856 --- /dev/null +++ b/app/views/crops/_find_seeds.html.haml @@ -0,0 +1,19 @@ +%h4 Find seeds +- if crop.seeds.empty? + %p + There are no seeds available to trade. +- else + %ul + - crop.seeds.tradable.each do |seed| + %li + = link_to seed.owner, seed.owner + - if seed.owner.location + in #{seed.owner.location} + - else + (location unknown) + will trade #{seed.tradable_to}. + = link_to "View details.", seed_path(seed) +- if current_member + = link_to "List your seeds to trade.", new_seed_path() +- else + = render :partial => 'shared/signin_signup', :locals => { :to => 'list your seeds to trade' } diff --git a/app/views/crops/_photos.html.haml b/app/views/crops/_photos.html.haml new file mode 100644 index 000000000..664911723 --- /dev/null +++ b/app/views/crops/_photos.html.haml @@ -0,0 +1,6 @@ +- if !crop.photos.empty? + %ul.thumbnails + .row + - crop.photos.first(4).each do |p| + %li.span2 + = render :partial => "photos/thumbnail", :locals => { :photo => p } diff --git a/app/views/crops/_planting_advice.html.haml b/app/views/crops/_planting_advice.html.haml new file mode 100644 index 000000000..4a44502e7 --- /dev/null +++ b/app/views/crops/_planting_advice.html.haml @@ -0,0 +1,10 @@ +- if crop.planted_from.length > 0 + %p + Plant from: + - planted_from = crop.planted_from.sort_by {|s, freq| freq }.reverse + = planted_from.map {|s, freq| "#{s} (#{freq})" }.join(", ") +- if crop.sunniness.length > 0 + %p + Plant in: + - sunniness = crop.sunniness.sort_by {|s, freq| freq }.reverse + = sunniness.map {|s, freq| "#{s} (#{freq})" }.join(", ") diff --git a/app/views/crops/_varieties.html.haml b/app/views/crops/_varieties.html.haml new file mode 100644 index 000000000..e268ac7b4 --- /dev/null +++ b/app/views/crops/_varieties.html.haml @@ -0,0 +1,12 @@ +- if crop.parent + %p + = crop.system_name + is a variety of + = succeed "." do + = link_to crop.parent, crop.parent +- if crop.varieties.count > 0 + %p + Varieties of + = succeed ":" do + = crop.system_name + != crop.varieties.map{ |c| link_to c, c }.join(", ") diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index c46485f3e..253ec758f 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -2,28 +2,11 @@ .row .span9 - - if @crop.parent - %p - = @crop.system_name - is a variety of - = succeed "." do - = link_to @crop.parent, @crop.parent - - if @crop.varieties.count > 0 - %p - Varieties of - = succeed ":" do - = @crop.system_name - != @crop.varieties.map{ |c| link_to c, c }.join(", ") - - if @crop.planted_from.length > 0 - %p - Plant from: - - planted_from = @crop.planted_from.sort_by {|s, freq| freq }.reverse - = planted_from.map {|s, freq| "#{s} (#{freq})" }.join(", ") - - if @crop.sunniness.length > 0 - %p - Plant in: - - sunniness = @crop.sunniness.sort_by {|s, freq| freq }.reverse - = sunniness.map {|s, freq| "#{s} (#{freq})" }.join(", ") + = render :partial => 'photos', :locals => { :crop => @crop } + + = render :partial => 'varieties', :locals => { :crop => @crop } + + = render :partial => 'planting_advice', :locals => { :crop => @crop } %p - if @crop.plantings_count > 0 @@ -71,26 +54,9 @@ %p - if can? :edit, @crop = link_to 'Add', new_scientific_name_path( :crop_id => @crop.id ), { :class => 'btn btn-mini' } + %h4 More information %ul %li= link_to 'Wikipedia (English)', @crop.en_wikipedia_url - %h4 Find seeds - - if @crop.seeds.empty? - %p - There are no seeds available to trade. - - else - %ul - - @crop.seeds.tradable.each do |seed| - %li - = link_to seed.owner, seed.owner - - if seed.owner.location - in #{seed.owner.location} - - else - (location unknown) - will trade #{seed.tradable_to}. - = link_to "View details.", seed_path(seed) - - if current_member - = link_to "List your seeds to trade.", new_seed_path() - - else - = render :partial => 'shared/signin_signup', :locals => { :to => 'list your seeds to trade' } + = render :partial => 'find_seeds', :locals => { :crop => @crop } diff --git a/app/views/gardens/index.html.haml b/app/views/gardens/index.html.haml index a020b9a8e..bc42de466 100644 --- a/app/views/gardens/index.html.haml +++ b/app/views/gardens/index.html.haml @@ -1,23 +1,59 @@ -%h1 Listing gardens +- content_for :title, @owner ? "#{@owner}'s gardens" : "Everyone's gardens" -- if can? :create, Garden - %p= link_to 'New Garden', new_garden_path, :class => 'btn btn-primary' +%p + - if can? :create, Garden + - if @owner + %p + - if @owner == current_member + = link_to 'Add a garden', new_garden_path, :class => 'btn btn-primary' + = link_to "View everyone's gardens", gardens_path, :class => 'btn' + - else # everyone's gardens + = link_to 'Add a garden', new_garden_path, :class => 'btn btn-primary' + - if current_member + = link_to 'View your gardens', gardens_by_owner_path(:owner => current_member.slug), :class => 'btn' + - else + = render :partial => 'shared/signin_signup', :locals => { :to => 'add a new garden' } -%table - %tr - %th Name - %th User - %th Slug - %th - %th +- if @gardens.length > 0 - - @gardens.each do |garden| + %div.pagination + = page_entries_info @gardens, :model => "gardens" + = will_paginate @gardens + + %table.table.table-striped %tr - %td= link_to garden.name, garden - %td= garden.owner - %td= garden.slug - - if can? :edit, garden - %td= link_to 'Edit', edit_garden_path(garden), :class => 'btn btn-mini' - - if can? :destroy, garden - %td= link_to 'Delete', garden, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-mini' + - unless @owner + %th Owner + %th Garden name + %th Description + %th Plantings + %th + + - @gardens.each do |garden| + %tr + - unless @owner + %td= link_to garden.owner.login_name, garden.owner + %td= link_to garden.name, garden + %td= garden.description + %td + - if garden.plantings.empty? + None + - else + %ul + - garden.plantings.each do |p| + %li + = p.quantity + = link_to p.crop.system_name, p + - if p.planted_at + planted on + = p.planted_at + + %td= link_to 'Details', garden, :class => 'btn btn-mini' + + %div.pagination + = page_entries_info @gardens, :model => "gardens" + = will_paginate @gardens + +- else + %p There are no gardens to display. diff --git a/app/views/gardens/show.html.haml b/app/views/gardens/show.html.haml index 8cfe8f2a3..c57f215fc 100644 --- a/app/views/gardens/show.html.haml +++ b/app/views/gardens/show.html.haml @@ -19,7 +19,7 @@ .span9 %div :markdown - #{@garden.description} + #{strip_tags @garden.description} - if can? :edit, @garden = link_to 'Edit garden', edit_garden_path(@garden), :class => 'btn btn-mini' - if can? :destroy, @garden diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index ac93bdd86..c2f3712bf 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -28,7 +28,7 @@ %p %b Your seed stash: - = link_to pluralize(current_member.seeds.count, "variety"), seeds_path(:owner_id => current_member.id) + = link_to pluralize(current_member.seeds.count, "variety"), seeds_by_owner_path(:owner => current_member.slug) = link_to 'Add', new_seed_path, :class => 'btn btn-mini' .span4 diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index 9f6bf78f9..07c664a35 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -9,30 +9,46 @@ .nav-collapse.collapse %ul.nav %li= link_to "Crops", crops_path - %li= link_to "Members", members_path - %li= link_to "Posts", posts_path - %li= link_to "Forums", forums_path - %li= link_to "Shop", shop_path - -if member_signed_in? and current_member.has_role?(:admin) - %li= link_to "Admin", admin_path - %li.divider-vertical + %li= link_to "Seeds", seeds_path + %li.dropdown< + %a.dropdown-toggle{'data-toggle' => 'dropdown', :href => members_path} + Community + %b.caret + %ul.dropdown-menu + %li= link_to "Members", members_path + %li= link_to "Posts", posts_path + %li= link_to "Forums", forums_path + + %li.divider-vertical + - if member_signed_in? %li.dropdown< - %a.dropdown-toggle{'data-toggle' => 'dropdown', :href => member_path(current_member)} - = current_member.login_name + %a.dropdown-toggle{'data-toggle' => 'dropdown', :href => root_path} + - if current_member.notifications.unread_count > 0 + Your Stuff (#{current_member.notifications.unread_count}) + - else + Your Stuff %b.caret - %ul.dropdown-menu - %li= link_to "Profile", member_path(current_member) - %li= link_to "Settings", edit_member_registration_path - %li= link_to "Account", orders_path - %li= link_to "Sign out", destroy_member_session_path, :method => :delete - %li - - if current_member.notifications.unread_count > 0 - = link_to("Inbox (#{current_member.notifications.unread_count})", notifications_path) - - else - = link_to("Inbox", notifications_path) + %ul.dropdown-menu + %li= link_to "Profile", member_path(current_member) + %li= link_to "Gardens", gardens_by_owner_path(:owner => current_member.slug) + %li= link_to "Plantings", plantings_by_owner_path(:owner => current_member.slug) + %li= link_to "Seeds", seeds_by_owner_path(:owner => current_member.slug) + %li= link_to "Posts", posts_by_author_path(:author => current_member.slug) + %li= link_to "Account", orders_path + %li + - if current_member.notifications.unread_count > 0 + = link_to("Inbox (#{current_member.notifications.unread_count})", notifications_path) + - else + = link_to("Inbox", notifications_path) + + %li= link_to "Shop", shop_path + - if current_member.has_role?(:admin) + %li= link_to "Admin", admin_path + + %li= link_to "Sign out", destroy_member_session_path, :method => :delete - else - %li.pull-right= link_to 'Sign in', new_member_session_path - %li.pull-right= link_to 'Sign up', new_member_registration_path + %li= link_to 'Sign in', new_member_session_path + %li= link_to 'Sign up', new_member_registration_path diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index cc67cedee..9f2a55272 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -7,7 +7,7 @@ .container .row .span12 - - if content_for?(:title) + - if content_for?(:title) %h1= yield(:title) - if notice .alert.alert-success diff --git a/app/views/photos/_thumbnail.html.haml b/app/views/photos/_thumbnail.html.haml new file mode 100644 index 000000000..e0526d8cd --- /dev/null +++ b/app/views/photos/_thumbnail.html.haml @@ -0,0 +1,9 @@ +.thumbnail(style='height: 220px') + = link_to image_tag(photo.thumbnail_url, :alt => photo.title, :class => 'img-rounded'), photo + %p + = link_to photo.title, photo + %br/ + %small + %i + by + = link_to photo.owner, photo.owner diff --git a/app/views/plantings/index.html.haml b/app/views/plantings/index.html.haml index 6e98960ad..434669cb9 100644 --- a/app/views/plantings/index.html.haml +++ b/app/views/plantings/index.html.haml @@ -1,14 +1,53 @@ -=content_for :title, "What's been planted recently?" +- content_for :title, @owner ? "#{@owner}'s plantings" : "Everyone's plantings" -%p Here are the latest things planted by #{Growstuff::Application.config.site_name} members. +%p + - if can? :create, Planting + - if @owner + %p + - if @owner == current_member + = link_to 'Plant something', new_planting_path, :class => 'btn btn-primary' + = link_to "View everyone's plantings", plantings_path, :class => 'btn' + - else # everyone's plantings + = link_to 'Plant something', new_planting_path, :class => 'btn btn-primary' + - if current_member + = link_to 'View your plantings', plantings_by_owner_path(:owner => current_member.slug), :class => 'btn' + - else + = render :partial => 'shared/signin_signup', :locals => { :to => "track what you've planted" } -%div.pagination - = page_entries_info @plantings, :model => "plantings" - = will_paginate @plantings + %div.pagination + = page_entries_info @plantings, :model => "plantings" + = will_paginate @plantings -- @plantings.each do |p| - = render :partial => "plantings/thumbnail", :locals => { :planting => p } +- if @plantings.length > 0 -%div.pagination - = page_entries_info @plantings, :model => "plantings" - = will_paginate @plantings + %table.table.table-striped + %tr + - unless @owner + %th Owner + %th Crop + %th Garden + %th Description + %th Quantity + %th Planted on + %th Sun/shade? + %th Planted from + %th + + - @plantings.each do |planting| + %tr + - unless @owner + %td= link_to planting.owner.login_name, planting.owner + %td= link_to planting.crop.system_name, planting.crop + %td= link_to planting.garden.name, planting.garden + %td + :markdown + #{ strip_tags planting.description } + %td= planting.quantity + %td= planting.planted_at + %td= planting.sunniness + %td= planting.planted_from + %td= link_to 'Details', planting, :class => 'btn btn-mini' + + %div.pagination + = page_entries_info @plantings, :model => "plantings" + = will_paginate @plantings diff --git a/app/views/plantings/index.rss.haml b/app/views/plantings/index.rss.haml index d6ed95542..59cdd5e43 100644 --- a/app/views/plantings/index.rss.haml +++ b/app/views/plantings/index.rss.haml @@ -1,7 +1,8 @@ %rss{:version => 2.0} %channel - %title #{Growstuff::Application.config.site_name} - Recent plantings from all members + %title + #{Growstuff::Application.config.site_name} - Recent plantings from #{ @owner ? @owner : 'all members' } %link= plantings_url - @plantings.each do |planting| %item diff --git a/app/views/plantings/show.html.haml b/app/views/plantings/show.html.haml index a2d0c8870..91d6282a7 100644 --- a/app/views/plantings/show.html.haml +++ b/app/views/plantings/show.html.haml @@ -54,12 +54,7 @@ - @planting.photos.each do |p| - c += 1 %li.span2 - .thumbnail(style='height: 220px') - = link_to image_tag(p.thumbnail_url, :alt => p.title, :class => 'img-rounded'), p - %p - = link_to p.title, p - by - = link_to p.owner, p.owner + = render :partial => 'photos/thumbnail', :locals => { :photo => p } - if (c % 6) == 0 .row - if can? :create, Photo and can? :edit, @planting diff --git a/app/views/posts/index.html.haml b/app/views/posts/index.html.haml index 8d321f5ea..e691f7b6f 100644 --- a/app/views/posts/index.html.haml +++ b/app/views/posts/index.html.haml @@ -1,14 +1,27 @@ -= content_for :title, "Recent #{Growstuff::Application.config.site_name} member posts" +- content_for :title, @author ? "#{@author}'s posts" : "Everyone's posts" -%p= link_to 'Post something', new_post_path, :class => 'btn btn-primary' +%p + - if can? :create, Post + - if @author + %p + - if @author == current_member + = link_to 'Post something', new_post_path, :class => 'btn btn-primary' + = link_to "View everyone's posts", posts_path, :class => 'btn' + - else # everyone's posts + = link_to 'Post something', new_post_path, :class => 'btn btn-primary' + - if current_member + = link_to 'View your posts', posts_by_author_path(:author => current_member.slug), :class => 'btn' + - else + = render :partial => 'shared/signin_signup', :locals => { :to => 'write a post' } %div.pagination = page_entries_info @posts, :model => "posts" = will_paginate @posts -- @posts.each do |post| - = render :partial => "single", :locals => { :post => post, :subject => true } +- unless @posts.empty? + - @posts.each do |post| + = render :partial => "single", :locals => { :post => post, :subject => true } -%div.pagination - = page_entries_info @posts, :model => "posts" - = will_paginate @posts + %div.pagination + = page_entries_info @posts, :model => "posts" + = will_paginate @posts diff --git a/app/views/posts/index.rss.haml b/app/views/posts/index.rss.haml index 12402d0cf..4056a6099 100644 --- a/app/views/posts/index.rss.haml +++ b/app/views/posts/index.rss.haml @@ -1,7 +1,8 @@ %rss{:version => 2.0} %channel - %title #{Growstuff::Application.config.site_name} - Recent posts from all members + %title + #{Growstuff::Application.config.site_name} - Recent posts from #{ @author ? @author : 'all members' } %link= posts_url - @posts.each do |post| %item diff --git a/app/views/seeds/index.html.haml b/app/views/seeds/index.html.haml index 84a0de1d5..b22edee0e 100644 --- a/app/views/seeds/index.html.haml +++ b/app/views/seeds/index.html.haml @@ -10,14 +10,20 @@ - else # everyone's seeds = link_to 'Add seeds', new_seed_path, :class => 'btn btn-primary' - if current_member - = link_to 'View your seeds', seeds_path(:owner_id => current_member.id), :class => 'btn' + = link_to 'View your seeds', seeds_by_owner_path(:owner => current_member.slug), :class => 'btn' - else = render :partial => 'shared/signin_signup', :locals => { :to => 'add seeds to your stash' } +%div.pagination + = page_entries_info @seeds, :model => "seeds" + = will_paginate @seeds + - if @seeds.length > 0 + %table.table.table-striped %tr - %th Owner + - unless @owner + %th Owner %th Crop %th Description %th Quantity @@ -28,7 +34,8 @@ - @seeds.each do |seed| %tr - %td= link_to seed.owner.login_name, seed.owner + - unless @owner + %td= link_to seed.owner.login_name, seed.owner %td= link_to seed.crop.system_name, seed.crop %td= seed.description %td= seed.quantity @@ -38,5 +45,7 @@ - if seed.tradable? = seed.owner.location.blank? ? "unspecified" : seed.owner.location %td= link_to 'Details', seed, :class => 'btn btn-mini' -- else - %p There are no seeds to display. + + %div.pagination + = page_entries_info @seeds, :model => "seeds" + = will_paginate @seeds diff --git a/config/routes.rb b/config/routes.rb index 23e7af55c..5c29f3feb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,12 +4,21 @@ Growstuff::Application.routes.draw do resources :members resources :photos - resources :seeds resources :authentications + resources :plantings + match '/plantings/owner/:owner' => 'plantings#index', :as => 'plantings_by_owner' + resources :gardens + match '/gardens/owner/:owner' => 'gardens#index', :as => 'gardens_by_owner' + + resources :seeds + match '/seeds/owner/:owner' => 'seeds#index', :as => 'seeds_by_owner' + resources :posts + match '/posts/author/:author' => 'posts#index', :as => 'posts_by_author' + resources :scientific_names resources :crops resources :comments diff --git a/spec/controllers/plantings_controller_spec.rb b/spec/controllers/plantings_controller_spec.rb index dff4e2909..2bc3367ec 100644 --- a/spec/controllers/plantings_controller_spec.rb +++ b/spec/controllers/plantings_controller_spec.rb @@ -11,6 +11,14 @@ describe PlantingsController do } end + describe "GET index" do + it "picks up owner from params" do + owner = FactoryGirl.create(:member) + get :index, {:owner => owner.slug} + assigns(:owner).should eq(owner) + end + end + describe "GET new" do it "picks up crop from params" do diff --git a/spec/controllers/seeds_controller_spec.rb b/spec/controllers/seeds_controller_spec.rb index 8023deb69..d41fe7c3b 100644 --- a/spec/controllers/seeds_controller_spec.rb +++ b/spec/controllers/seeds_controller_spec.rb @@ -4,7 +4,7 @@ describe SeedsController do describe "GET index" do it "picks up owner from params" do owner = FactoryGirl.create(:member) - get :index, {:owner_id => owner.id} + get :index, {:owner => owner.slug} assigns(:owner).should eq(owner) end end diff --git a/spec/views/crops/show.html.haml_spec.rb b/spec/views/crops/show.html.haml_spec.rb index 281806091..dd79a443a 100644 --- a/spec/views/crops/show.html.haml_spec.rb +++ b/spec/views/crops/show.html.haml_spec.rb @@ -9,6 +9,30 @@ describe "crops/show" do assign(:crop, @crop) end + context 'photos' do + before(:each) do + @planting = FactoryGirl.create(:planting, :crop => @crop) + @photo1 = FactoryGirl.create(:photo) + @photo2 = FactoryGirl.create(:photo) + @photo3 = FactoryGirl.create(:photo) + @photo4 = FactoryGirl.create(:photo) + @planting.photos << [@photo1, @photo2, @photo3, @photo4] + render + end + + it 'shows 4 photos across the top of the page' do + assert_select "div.thumbnail>a>img", :count => 4 + end + + it 'links to the photo detail page' do + assert_select "a[href=#{photo_path(@photo1)}]" + end + + it 'links to the photo owner' do + assert_select "a[href=#{member_path(@photo1.owner)}]" + end + end + it "shows the wikipedia URL" do render assert_select("a[href=#{@crop.en_wikipedia_url}]", 'Wikipedia (English)') diff --git a/spec/views/gardens/index.html.haml_spec.rb b/spec/views/gardens/index.html.haml_spec.rb index 7a72b854a..17fcb5363 100644 --- a/spec/views/gardens/index.html.haml_spec.rb +++ b/spec/views/gardens/index.html.haml_spec.rb @@ -4,10 +4,16 @@ describe "gardens/index" do before(:each) do controller.stub(:current_user) { nil } @owner = FactoryGirl.create(:member) - assign(:gardens, [ - FactoryGirl.create(:garden, :owner => @owner), - FactoryGirl.create(:garden, :owner => @owner) - ]) + page = 1 + per_page = 2 + total_entries = 2 + gardens = WillPaginate::Collection.create(page, per_page, total_entries) do |pager| + pager.replace([ + FactoryGirl.create(:garden, :owner => @owner), + FactoryGirl.create(:garden, :owner => @owner) + ]) + end + assign(:gardens, gardens) end it "renders a list of gardens" do diff --git a/spec/views/layouts/_header_spec.rb b/spec/views/layouts/_header_spec.rb new file mode 100644 index 000000000..0c287aa8a --- /dev/null +++ b/spec/views/layouts/_header_spec.rb @@ -0,0 +1,90 @@ +require 'spec_helper' + +describe 'layouts/_header.html.haml', :type => "view" do + context "when not logged in" do + before(:each) do + controller.stub(:current_user) { nil } + render + end + + it 'shows the title' do + rendered.should contain Growstuff::Application.config.site_name + end + + it 'should have signup/signin links' do + rendered.should contain 'Sign up' + rendered.should contain 'Sign in' + end + + it 'has a Crops link' do + rendered.should contain "Crops" + end + + it 'has a Seeds link' do + rendered.should contain "Seeds" + end + + it 'has a Community section' do + rendered.should contain "Community" + end + + it 'links to members' do + assert_select("a[href=#{members_path}]", 'Members') + end + + it 'links to posts' do + assert_select("a[href=#{posts_path}]", 'Posts') + end + + it 'links to forums' do + assert_select("a[href=#{forums_path}]", 'Forums') + end + + end + + context "logged in" do + + before(:each) do + @member = FactoryGirl.create(:member) + sign_in @member + controller.stub(:current_user) { @member } + render + end + + context "your stuff" do + it 'should have a Your Stuff section' do + rendered.should contain "Your Stuff" + end + it "should show link to member's gardens" do + assert_select("a[href=#{gardens_by_owner_path(:owner => @member.slug)}]", "Gardens") + end + it "should show link to member's plantings" do + assert_select("a[href=#{plantings_by_owner_path(:owner => @member.slug)}]", "Plantings") + end + it "should show link to member's seeds" do + assert_select("a[href=#{seeds_by_owner_path(:owner => @member.slug)}]", "Seeds") + end + it "should show link to member's posts" do + assert_select("a[href=#{posts_by_author_path(:author => @member.slug)}]", "Posts") + end + end + + it 'should show signout link' do + rendered.should contain 'Sign out' + end + + it 'should show inbox link' do + rendered.should contain 'Inbox' + rendered.should_not match(/Inbox \(\d+\)/) + end + + context 'has notifications' do + it 'should show inbox count' do + FactoryGirl.create(:notification, :recipient => @member) + render + rendered.should contain 'Inbox (1)' + end + end + + end +end diff --git a/spec/views/layouts/application_spec.rb b/spec/views/layouts/application_spec.rb index 0637faf80..0c7bd8b50 100644 --- a/spec/views/layouts/application_spec.rb +++ b/spec/views/layouts/application_spec.rb @@ -1,72 +1,15 @@ require 'spec_helper' describe 'layouts/application.html.haml', :type => "view" do - context "when not logged in" do - - before(:each) do - controller.stub(:current_user) { nil } - render - end - - it 'shows the title' do - rendered.should contain Growstuff::Application.config.site_name - end - - it 'should have signup/login links' do - rendered.should contain 'Sign up' - rendered.should contain 'Sign in' - end - + before(:each) do + controller.stub(:current_user) { nil } end - context "logged in" do - - before(:each) do - @member = FactoryGirl.create(:member) - sign_in @member - controller.stub(:current_user) { @member } - render - end - - it 'should show login name' do - rendered.should contain /member\d+/ - end - - it "should show member's name" do - assert_select("a[href=/members/#{@member.login_name}]", "Profile") - end - - it "should show settings link" do - assert_select "a[href=/members/edit]", "Settings" - end - - it "should show settings link" do - assert_select "a[href=#{orders_path}]", "Account" - end - - it 'should show logout link' do - rendered.should contain 'Sign out' - end - - it 'should show inbox link' do - rendered.should contain 'Inbox' - rendered.should_not match(/Inbox \(\d+\)/) - end - - context 'has notifications' do - it 'should show inbox count' do - FactoryGirl.create(:notification, :recipient => @member) - render - rendered.should contain 'Inbox (1)' - end - end - - it 'includes the analytics code' do - Growstuff::Application.config.analytics_code = '' - render - assert_select "script", :text => 'alert("foo!")' - rendered.should_not contain 'script' - end - + it 'includes the analytics code' do + Growstuff::Application.config.analytics_code = '' + render + assert_select "script", :text => 'alert("foo!")' + rendered.should_not contain 'script' end + end diff --git a/spec/views/plantings/index.html.haml_spec.rb b/spec/views/plantings/index.html.haml_spec.rb index 16339f665..b660fe2a1 100644 --- a/spec/views/plantings/index.html.haml_spec.rb +++ b/spec/views/plantings/index.html.haml_spec.rb @@ -31,7 +31,8 @@ describe "plantings/index" do it "renders a list of plantings" do rendered.should contain 'Tomato' rendered.should contain 'Maize' - rendered.should contain /member\d+'s Springfield Community Garden/ + rendered.should contain @member.login_name + rendered.should contain @garden.name end it "shows descriptions where they exist" do @@ -42,8 +43,4 @@ describe "plantings/index" do rendered.should contain 'January 13, 2013' end - it "renders markdown in the description" do - assert_select "em", "really" - end - end diff --git a/spec/views/posts/index.rss.haml_spec.rb b/spec/views/posts/index.rss.haml_spec.rb index cd5f74c4d..1b32096d3 100644 --- a/spec/views/posts/index.rss.haml_spec.rb +++ b/spec/views/posts/index.rss.haml_spec.rb @@ -3,10 +3,10 @@ require 'spec_helper' describe 'posts/index.rss.haml', :type => "view" do before(:each) do controller.stub(:current_user) { nil } - @author = FactoryGirl.create(:member) + author = FactoryGirl.create(:member) assign(:posts, [ - FactoryGirl.build(:post, :id => 1, :author => @author), - FactoryGirl.build(:post, :id => 2, :author => @author) + FactoryGirl.build(:post, :id => 1, :author => author), + FactoryGirl.build(:post, :id => 2, :author => author) ]) render end diff --git a/spec/views/seeds/index.html.haml_spec.rb b/spec/views/seeds/index.html.haml_spec.rb index a2902a08f..b1b9a9173 100644 --- a/spec/views/seeds/index.html.haml_spec.rb +++ b/spec/views/seeds/index.html.haml_spec.rb @@ -6,7 +6,13 @@ describe "seeds/index" do sign_in @member controller.stub(:current_user) { @member } @seed1 = FactoryGirl.create(:seed, :owner => @member) - assign(:seeds, [@seed1, @seed1]) + @page = 1 + @per_page = 2 + @total_entries = 2 + seeds = WillPaginate::Collection.create(@page, @per_page, @total_entries) do |pager| + pager.replace([ @seed1, @seed1 ]) + end + assign(:seeds, seeds) end it "renders a list of seeds" do @@ -20,7 +26,10 @@ describe "seeds/index" do before(:each) do @owner = FactoryGirl.create(:london_member) @seed1 = FactoryGirl.create(:tradable_seed, :owner => @owner) - assign(:seeds, [@seed1, @seed1]) + seeds = WillPaginate::Collection.create(@page, @per_page, @total_entries) do |pager| + pager.replace([ @seed1, @seed1 ]) + end + assign(:seeds, seeds) render end