From 8f7becfa78dab5c7ea777c0bc3aae962f6363478 Mon Sep 17 00:00:00 2001 From: Skud Date: Wed, 21 Aug 2013 21:24:22 +1000 Subject: [PATCH] added a basic crop wrangler homepage --- app/controllers/crops_controller.rb | 9 +++++ app/models/ability.rb | 1 + app/views/crops/wrangle.html.haml | 38 ++++++++++++++++++++++ app/views/layouts/_header.html.haml | 2 ++ config/routes.rb | 3 ++ spec/controllers/crops_controller_spec.rb | 8 +++++ spec/views/crops/wrangle.html.haml_spec.rb | 35 ++++++++++++++++++++ 7 files changed, 96 insertions(+) create mode 100644 app/views/crops/wrangle.html.haml create mode 100644 spec/views/crops/wrangle.html.haml_spec.rb diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index b258ea119..6ce582322 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -15,6 +15,15 @@ class CropsController < ApplicationController end end + # GET /wrangle + def wrangle + @crops = Crop.recent.paginate(:page => params[:page]) + + respond_to do |format| + format.html + end + end + # GET /crops/1 # GET /crops/1.json def show diff --git a/app/models/ability.rb b/app/models/ability.rb index ece3e809f..b5fafd8ec 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -37,6 +37,7 @@ class Ability # only crop wranglers can create/edit/destroy crops if member.has_role? :crop_wrangler + can :wrangle, Crop can :manage, Crop can :manage, ScientificName end diff --git a/app/views/crops/wrangle.html.haml b/app/views/crops/wrangle.html.haml new file mode 100644 index 000000000..a52107f2d --- /dev/null +++ b/app/views/crops/wrangle.html.haml @@ -0,0 +1,38 @@ +- content_for :title, "Crop Wrangling" + + +%ul + %li= link_to "Requests for new crops", 'http://growstuff.org/posts/skud-20130319-requests-for-new-crops' + %li= link_to "Crop wrangler guidelines", "http://wiki.growstuff.org/index.php/Crop_wrangling" + %li= link_to "crop-wranglers mailing list", "http://lists.growstuff.org/listinfo/crop-wranglers" + %li= link_to "Add Crop", new_crop_path + +%h2 Recently added crops + +%div.pagination + = page_entries_info @crops, :model => "crops" + = will_paginate @crops + +%table.table.table-striped + %tr + %th System name + %th English Wikipedia URL + %th Scientific names + %th Added by + %th When + - @crops.each do |c| + %tr + %td= link_to c.system_name, c + %td= link_to c.en_wikipedia_url, c.en_wikipedia_url + %td + - c.scientific_names.each do |s| + = link_to s.scientific_name, s + %br/ + %td= link_to c.creator, c.creator + %td + = distance_of_time_in_words(c.created_at, Time.zone.now) + ago. + +%div.pagination + = page_entries_info @crops, :model => "crops" + = will_paginate @crops diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index 07c664a35..cdc2e60b1 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -43,6 +43,8 @@ = link_to("Inbox", notifications_path) %li= link_to "Shop", shop_path + - if current_member.has_role?(:crop_wrangler) + %li= link_to "Crop Wrangling", wrangle_crops_path - if current_member.has_role?(:admin) %li= link_to "Admin", admin_path diff --git a/config/routes.rb b/config/routes.rb index 5c29f3feb..341aacec8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,10 @@ Growstuff::Application.routes.draw do match '/posts/author/:author' => 'posts#index', :as => 'posts_by_author' resources :scientific_names + + match 'crops/wrangle' => 'crops#wrangle', :as => 'wrangle_crops' resources :crops + resources :comments resources :roles resources :forums diff --git a/spec/controllers/crops_controller_spec.rb b/spec/controllers/crops_controller_spec.rb index 281882e29..27901bc06 100644 --- a/spec/controllers/crops_controller_spec.rb +++ b/spec/controllers/crops_controller_spec.rb @@ -11,6 +11,14 @@ describe CropsController do } end + describe "GET crop wrangler homepage" do + it 'fetches the crop wrangler homepage' do + get :wrangle + response.should be_success + response.should render_template("crops/wrangle") + end + end + describe "GET RSS feed" do it "returns an RSS feed" do get :index, :format => "rss" diff --git a/spec/views/crops/wrangle.html.haml_spec.rb b/spec/views/crops/wrangle.html.haml_spec.rb new file mode 100644 index 000000000..100beb01b --- /dev/null +++ b/spec/views/crops/wrangle.html.haml_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe "crops/wrangle" do + before(:each) do + @member = FactoryGirl.create(:crop_wrangling_member) + controller.stub(:current_user) { @member } + page = 1 + per_page = 2 + total_entries = 2 + @tomato = FactoryGirl.create(:tomato) + @maize = FactoryGirl.create(:maize) + crops = WillPaginate::Collection.create(page, per_page, total_entries) do |pager| + pager.replace([ @tomato, @maize ]) + end + assign(:crops, crops) + end + + it 'contains handy links for wranglers' do + render + rendered.should contain "Crop wrangler guidelines" + rendered.should contain "mailing list" + end + + it 'has a link to add a crop' do + render + assert_select "a", :href => new_crop_path + end + + it "renders a list of crops" do + render + assert_select "a", :text => "Maize" + assert_select "a", :text => "Tomato" + end + +end