From 2f67ffd2f881fb3ccd0482a8746b649ded8778ed Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Mon, 2 Feb 2015 00:01:49 +1100 Subject: [PATCH] fix regressions --- app/models/crop.rb | 2 +- app/views/crops/wrangle.html.haml | 45 ++++++++++++---------- spec/controllers/crops_controller_spec.rb | 3 +- spec/factories/crop.rb | 1 + spec/features/crops/crop_wranglers_spec.rb | 2 +- spec/mailers/notifier_spec.rb | 6 +-- spec/models/ability_spec.rb | 5 ++- spec/views/crops/wrangle.html.haml_spec.rb | 2 +- 8 files changed, 37 insertions(+), 29 deletions(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index 325a9b13d..f12e7355d 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -23,7 +23,7 @@ class Crop < ActiveRecord::Base default_scope { order("lower(name) asc") } scope :recent, -> { where(:approval_status => "approved").reorder("created_at desc") } - scope :toplevel, -> { where(approval_status => "approved", :parent_id => nil) } + scope :toplevel, -> { where(:approval_status => "approved", :parent_id => nil) } scope :popular, -> { where(:approval_status => "approved").reorder("plantings_count desc, lower(name) asc") } scope :randomized, -> { where(:approval_status => "approved").reorder('random()') } # ok on sqlite and psql, but not on mysql scope :pending_approval, -> { where(:approval_status => "pending") } diff --git a/app/views/crops/wrangle.html.haml b/app/views/crops/wrangle.html.haml index 5f65e0196..e47f854eb 100644 --- a/app/views/crops/wrangle.html.haml +++ b/app/views/crops/wrangle.html.haml @@ -17,27 +17,30 @@ %h2 Requested crops -%table#requested-crops.table.table-striped - %thead - %tr - %th System name - %th English Wikipedia URL - %th Scientific names - %th Requested by - %th When requested - %tbody - - @pending_approval.each do |c| +- if @pending_approval + %table#requested-crops.table.table-striped + %thead %tr - %td= link_to c.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.requester, c.requester - %td - = distance_of_time_in_words(c.created_at, Time.zone.now) - ago. + %th System name + %th English Wikipedia URL + %th Scientific names + %th Requested by + %th When requested + %tbody + - @pending_approval.each do |c| + %tr + %td= link_to c.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.requester, c.requester + %td + = distance_of_time_in_words(c.created_at, Time.zone.now) + ago. +- else + %p There are no crops pending approval. %h2 Recently added crops @@ -45,7 +48,7 @@ = page_entries_info @recent_crops, :model => "crops" = will_paginate @recent_crops -%table.table.table-striped +%table#recently-added.table.table-striped %tr %th System name %th English Wikipedia URL diff --git a/spec/controllers/crops_controller_spec.rb b/spec/controllers/crops_controller_spec.rb index 5cfe9f4d1..54226c27c 100644 --- a/spec/controllers/crops_controller_spec.rb +++ b/spec/controllers/crops_controller_spec.rb @@ -7,7 +7,8 @@ describe CropsController do def valid_attributes { :name => "Tomato", - :en_wikipedia_url => 'http://en.wikipedia.org/wiki/Tomato' + :en_wikipedia_url => 'http://en.wikipedia.org/wiki/Tomato', + :approval_status => 'approved' } end diff --git a/spec/factories/crop.rb b/spec/factories/crop.rb index b0513814f..261979b45 100644 --- a/spec/factories/crop.rb +++ b/spec/factories/crop.rb @@ -3,6 +3,7 @@ FactoryGirl.define do factory :crop do name "magic bean" en_wikipedia_url "http://en.wikipedia.org/wiki/Magic_bean" + approval_status "approved" creator factory :tomato do diff --git a/spec/features/crops/crop_wranglers_spec.rb b/spec/features/crops/crop_wranglers_spec.rb index 0e0b08fbe..b01e3acc9 100644 --- a/spec/features/crops/crop_wranglers_spec.rb +++ b/spec/features/crops/crop_wranglers_spec.rb @@ -25,7 +25,7 @@ feature "crop wranglers" do scenario "can see list of crops with extra detail of who created a crop" do visit root_path click_link 'Crop Wrangling' - within '.table' do + within '#recently-added' do expect(page).to have_content "#{crops.first.creator.login_name}" end end diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index dc7a4a63e..667ded7a2 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -90,9 +90,9 @@ describe Notifier do end it 'includes links to plant, harvest and stash seeds for the new crop' do - expect(mail.body.encoded).to match new_planting_url(crop_id: crop.id) - expect(mail.body.encoded).to match new_harvest_url(crop_id: crop.id) - expect(mail.body.encoded).to match new_seed_url(crop_id: crop.id) + expect(mail.body.encoded).to match new_planting_url + expect(mail.body.encoded).to match new_harvest_url + expect(mail.body.encoded).to match new_seed_url end end diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 4eccf8916..87d8a3b1d 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -45,11 +45,14 @@ describe Ability do context "standard member" do it "can't manage crops" do - @ability.should_not be_able_to(:create, Crop) @ability.should_not be_able_to(:update, @crop) @ability.should_not be_able_to(:destroy, @crop) end + it "can request crops" do + @ability.should be_able_to(:create, Crop) + end + it "can read crops" do @ability.should be_able_to(:read, @crop) end diff --git a/spec/views/crops/wrangle.html.haml_spec.rb b/spec/views/crops/wrangle.html.haml_spec.rb index 4426382d2..24438899b 100644 --- a/spec/views/crops/wrangle.html.haml_spec.rb +++ b/spec/views/crops/wrangle.html.haml_spec.rb @@ -12,7 +12,7 @@ describe "crops/wrangle" do crops = WillPaginate::Collection.create(page, per_page, total_entries) do |pager| pager.replace([ @tomato, @maize ]) end - assign(:crops, crops) + assign(:recent_crops, crops) assign(:crop_wranglers, Role.crop_wranglers) end