diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 2dcbb1842..f1985a45d 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -93,5 +93,4 @@ submit the change with your pull request. ### Security and Dependency Updates - DeppBot / [deppbot](https://github.com/deppbot) -- dependabot[bot] / [dependabot-bot] / [dependabot] (https://github.com/dependabot-bot) -- dependabot / [dependabot](https://github.com/dependabot) +- dependabot[bot] (https://github.com/dependabot-bot) diff --git a/Gemfile.lock b/Gemfile.lock index 27b361f75..e00ef2345 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -80,7 +80,7 @@ GEM uniform_notifier (~> 1.11) byebug (10.0.2) cancancan (2.3.0) - capybara (3.13.0) + capybara (3.13.2) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) @@ -134,7 +134,7 @@ GEM activesupport (>= 3.0.0) dalli (2.7.9) database_cleaner (1.7.0) - devise (4.5.0) + devise (4.6.1) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0, < 6.0) @@ -164,7 +164,7 @@ GEM factory_bot_rails (4.11.1) factory_bot (~> 4.11.1) railties (>= 3.0.0) - faker (1.9.1) + faker (1.9.2) i18n (>= 0.7) faraday (0.15.4) multipart-post (>= 1.2, < 3) @@ -221,7 +221,7 @@ GEM httparty (0.16.3) mime-types (~> 3.0) multi_xml (>= 0.5.2) - i18n (1.5.2) + i18n (1.5.3) concurrent-ruby (~> 1.0) i18n-tasks (0.9.28) activesupport (>= 4.0.2) @@ -406,7 +406,7 @@ GEM rspec-mocks (3.8.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.8.0) - rspec-rails (3.8.1) + rspec-rails (3.8.2) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) @@ -415,7 +415,7 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) - rubocop (0.61.1) + rubocop (0.64.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.5, != 2.5.1.1) diff --git a/app/assets/images/blog_32.png b/app/assets/images/blog_32.png index a599254f8..ae08ed38f 100644 Binary files a/app/assets/images/blog_32.png and b/app/assets/images/blog_32.png differ diff --git a/app/assets/images/email_32.png b/app/assets/images/email_32.png index 160ee6396..f4d655b36 100644 Binary files a/app/assets/images/email_32.png and b/app/assets/images/email_32.png differ diff --git a/app/assets/images/facebook-login-splash.png b/app/assets/images/facebook-login-splash.png index 445a00b30..22afc0383 100644 Binary files a/app/assets/images/facebook-login-splash.png and b/app/assets/images/facebook-login-splash.png differ diff --git a/app/assets/images/facebook-thumbnail.png b/app/assets/images/facebook-thumbnail.png index a1b4736ba..34c3e1556 100644 Binary files a/app/assets/images/facebook-thumbnail.png and b/app/assets/images/facebook-thumbnail.png differ diff --git a/app/assets/images/flickr_32.png b/app/assets/images/flickr_32.png index 82a350e22..ad7b753fb 100644 Binary files a/app/assets/images/flickr_32.png and b/app/assets/images/flickr_32.png differ diff --git a/app/assets/images/growstuff-apple-touch-icon-precomposed.png b/app/assets/images/growstuff-apple-touch-icon-precomposed.png index 67e397952..6eceb70d7 100644 Binary files a/app/assets/images/growstuff-apple-touch-icon-precomposed.png and b/app/assets/images/growstuff-apple-touch-icon-precomposed.png differ diff --git a/app/assets/images/growstuff-brand.png b/app/assets/images/growstuff-brand.png index 6e9f8729f..8ef09bad3 100644 Binary files a/app/assets/images/growstuff-brand.png and b/app/assets/images/growstuff-brand.png differ diff --git a/app/assets/images/location-not-set.en.png b/app/assets/images/location-not-set.en.png index 6e1cde69c..8c02672da 100644 Binary files a/app/assets/images/location-not-set.en.png and b/app/assets/images/location-not-set.en.png differ diff --git a/app/assets/images/placeholder_150.png b/app/assets/images/placeholder_150.png index c3d7f500c..af43242af 100644 Binary files a/app/assets/images/placeholder_150.png and b/app/assets/images/placeholder_150.png differ diff --git a/app/assets/images/rails.png b/app/assets/images/rails.png index d5edc04e6..284baefb7 100644 Binary files a/app/assets/images/rails.png and b/app/assets/images/rails.png differ diff --git a/app/assets/images/sunniness_not specified.png b/app/assets/images/sunniness_not specified.png index 108505a70..d3ab0950c 100644 Binary files a/app/assets/images/sunniness_not specified.png and b/app/assets/images/sunniness_not specified.png differ diff --git a/app/assets/images/sunniness_semi-shade.png b/app/assets/images/sunniness_semi-shade.png index 46a849b64..e28974465 100644 Binary files a/app/assets/images/sunniness_semi-shade.png and b/app/assets/images/sunniness_semi-shade.png differ diff --git a/app/assets/images/sunniness_shade.png b/app/assets/images/sunniness_shade.png index 72a7e995e..315cbcc86 100644 Binary files a/app/assets/images/sunniness_shade.png and b/app/assets/images/sunniness_shade.png differ diff --git a/app/assets/images/sunniness_sun.png b/app/assets/images/sunniness_sun.png index 1c6c310cf..d3b0d63f9 100644 Binary files a/app/assets/images/sunniness_sun.png and b/app/assets/images/sunniness_sun.png differ diff --git a/app/assets/javascripts/tooltips.js b/app/assets/javascripts/tooltips.js new file mode 100644 index 000000000..fe6e69830 --- /dev/null +++ b/app/assets/javascripts/tooltips.js @@ -0,0 +1,3 @@ +$(function() { + $('[data-toggle="tooltip"]').tooltip(); +}); diff --git a/app/assets/stylesheets/application.sass b/app/assets/stylesheets/application.sass index e7a834d45..a8e11cf2f 100644 --- a/app/assets/stylesheets/application.sass +++ b/app/assets/stylesheets/application.sass @@ -6,3 +6,4 @@ @import 'overrides' @import 'graphs' @import 'predictions' +@import 'plantings' \ No newline at end of file diff --git a/app/assets/stylesheets/overrides.sass b/app/assets/stylesheets/overrides.sass index 1e9374184..1b7d4d152 100644 --- a/app/assets/stylesheets/overrides.sass +++ b/app/assets/stylesheets/overrides.sass @@ -41,7 +41,6 @@ h3 .profile-sidebar margin-top: -5rem .avatar - border-radius: 50% border-radius: 50% z-index: 2 position: relative @@ -114,37 +113,8 @@ p.stats .progress border-radius: 0 - -.badge-super-late - background-color: $red -.badge-harvest - background-color: $blue - -.planting-super-late -.planting-late - background-color: $beige - -.planting - .planting-badges - position: absolute - - .planting-thumbnail - padding: 0 - border: 1px solid darken($beige, 10%) - border-radius: 4px - .planting-name - position: relative - top: -1em - .planting-quick-actions - position: absolute - top: 0 - right: 2em - - dl.planting-attributes - dt - text-align: left - dd - margin-left: auto + .progress-bar-text + text-align: center .layout-actions width: 100% diff --git a/app/assets/stylesheets/plantings.sass b/app/assets/stylesheets/plantings.sass new file mode 100644 index 000000000..a6d450b68 --- /dev/null +++ b/app/assets/stylesheets/plantings.sass @@ -0,0 +1,38 @@ +.planting + .planting-badges + font-size: 100% + position: absolute + top: 3em + .badge-super-late + background-color: $red + .badge-harvest + background-color: $blue + .planting-super-late + .planting-late + background-color: $beige + + .planting-thumbnail + width: 150px + padding: 0em + margin-bottom: 0.5em + margin-top: 0.5em + border: 1px solid darken($beige, 10%) + border-radius: 4px + + .planting-name + position: relative + text-align: center + font-size: 150% + top: -0.5em + .planting-quick-actions + position: absolute + left: 142px + top: 6px + .planting-thumbnail-photo + height: 150px + + dl.planting-attributes + dt + text-align: left + dd + margin-left: auto diff --git a/app/assets/stylesheets/predictions.sass b/app/assets/stylesheets/predictions.sass index ad7fd45c1..f8120c8b5 100644 --- a/app/assets/stylesheets/predictions.sass +++ b/app/assets/stylesheets/predictions.sass @@ -1,10 +1,14 @@ .predictions - .metric + .prediction-metric + text-align: center height: 180px border: 1px solid lighten($green, 20%) + border-radius: 5% background: $white margin: 4px strong - font-size: 250% + font-size: 4em font-align: center h3 + span + display: block \ No newline at end of file diff --git a/app/resources/api/v1/planting_resource.rb b/app/resources/api/v1/planting_resource.rb index 3a42f5d4b..030f57892 100644 --- a/app/resources/api/v1/planting_resource.rb +++ b/app/resources/api/v1/planting_resource.rb @@ -9,9 +9,10 @@ module Api has_many :photos has_many :harvests + attribute :slug attribute :planted_at - attribute :finished_at attribute :finished + attribute :finished_at attribute :quantity attribute :description attribute :sunniness @@ -23,6 +24,28 @@ module Api attribute :percentage_grown attribute :first_harvest_date attribute :last_harvest_date + + filter :slug + filter :crop + filter :planted_from + filter :garden + filter :owner + filter :finished, default: nil + + attribute :percentage_grown + def percentage_grown + @model.percentage_grown + end + + attribute :crop_name + def crop_name + @model.crop.name + end + + attribute :thumbnail + def thumbnail + @model.default_photo&.thumbnail_url + end end end end diff --git a/app/views/crops/_predictions.html.haml b/app/views/crops/_predictions.html.haml index 74e8bafb1..dfdc7659f 100644 --- a/app/views/crops/_predictions.html.haml +++ b/app/views/crops/_predictions.html.haml @@ -12,24 +12,21 @@ = link_to 'https://en.wikipedia.org/wiki/Annual_vs._perennial_plant_evolution' do an annual crop (living and reproducing in a single year or less) - .row - if crop.annual? && crop.median_lifespan.present? - .metric.col-md-3.col-xs-5 + .prediction-metric.col-md-3.col-xs-5 %h3 Median lifespan %strong= crop.median_lifespan %span days - if crop.median_days_to_first_harvest.present? - .metric.col-md-3.col-xs-5 + .prediction-metric.col-md-3.col-xs-5 %h3 First harvest expected %strong= crop.median_days_to_first_harvest - %span days - after planting + %span days after planting - if crop.annual? && crop.median_days_to_last_harvest.present? - .metric.col-md-3.col-xs-5 + .prediction-metric.col-md-3.col-xs-5 %h3 Last harvest expected %strong= crop.median_days_to_last_harvest - %span days - after planting + %span days after planting diff --git a/app/views/gardens/_overview.html.haml b/app/views/gardens/_overview.html.haml index ed12d0cf5..635874211 100644 --- a/app/views/gardens/_overview.html.haml +++ b/app/views/gardens/_overview.html.haml @@ -5,18 +5,15 @@ .panel-body .row .col-md-2.col-xs-12.garden-info - .row - .col-md-12.col-xs-6 - = render 'gardens/photo', garden: garden - .col-md-12.col-xs-6 - = display_garden_description(garden) + %p= render 'gardens/photo', garden: garden + %p= display_garden_description(garden) .col-md-10 - .row - - if garden.plantings.current.size.positive? + - if garden.plantings.current.size.positive? + .row - garden.plantings.current.order(created_at: :desc).includes(:crop, :photos).each do |planting| - .col-md-2.col-sm-4.col-xs-6 + .col-lg-2.col-sm-4.col-xs-6 = render "plantings/thumbnail", planting: planting - - else - .col-md-2.col-sm-6.col-xs-6 no plantings + - else + no plantings - if can?(:edit, garden) .panel-footer= render 'gardens/actions', garden: garden diff --git a/app/views/plantings/_badges.html.haml b/app/views/plantings/_badges.html.haml index acd244da4..3c5493818 100644 --- a/app/views/plantings/_badges.html.haml +++ b/app/views/plantings/_badges.html.haml @@ -1,21 +1,24 @@ -- unless planting.finished? - // Finish times - - if planting.finish_is_predicatable? - - if planting.super_late? - %span.badge.badge-super-late= t('.super_late') - = planting_finish_button(planting) - - elsif planting.late? - %span.badge.badge-late= t('.late_finishing') - - else - %span.badge - = days_from_now_to_finished(planting) - = t('.days_until_finished') +.planting-badges + - unless planting.finished? + // Finish times + - if planting.finish_is_predicatable? + - if planting.super_late? + .badge.badge-super-late= t('.super_late') + = planting_finish_button(planting) + - elsif planting.late? + .badge.badge-late= t('.late_finishing') + - else + .badge{'data-toggle': "tooltip", 'data-placement': "top", title: 'Predicted days until planting is finished'} + = finished_icon + = t('label.days_until_finished', number: days_from_now_to_finished(planting)) - // Harvest times - - unless planting.super_late? - - if planting.harvest_time? - %span.badge.badge-harvest= t('.harvesting_now') - - elsif planting.before_harvest_time? - %span.badge - = days_from_now_to_first_harvest(planting) - = t('.days_until_harvest') + // Harvest times + - unless planting.super_late? + - if planting.harvest_time? + .badge.badge-harvest{'data-toggle': "tooltip", 'data-placement': "top", title: 'Planting is ready for harvesting now'} + = harvest_icon + = t('label.harvesting_now') + - elsif planting.before_harvest_time? + .badge{'data-toggle': "tooltip", 'data-placement': "top", title: 'Predicted days until harvest'} + = harvest_icon + = t('label.days_until_harvest', number: days_from_now_to_first_harvest(planting)) diff --git a/app/views/plantings/_progress_bar.html.haml b/app/views/plantings/_progress_bar.html.haml index e8544fc65..aa2e6391b 100644 --- a/app/views/plantings/_progress_bar.html.haml +++ b/app/views/plantings/_progress_bar.html.haml @@ -1,11 +1,13 @@ .progress - if progress.nil? - = status + .progress-bar-text= status - else -# haml-lint:disable InlineStyles %div{ class: "progress-bar progress-bar-#{status}", role: "progressbar", style: "width: #{progress}%" } - if progress >= 30 - #{sprintf '%.0f', progress}% + .progress-bar-text + #{sprintf '%.0f', progress}% - if progress < 30 - #{sprintf '%.0f', progress}% + .progress-bar-text + #{sprintf '%.0f', progress}% -# haml-lint:enable InlineStyles diff --git a/app/views/plantings/_quick_actions.haml b/app/views/plantings/_quick_actions.haml new file mode 100644 index 000000000..5a8b02c3e --- /dev/null +++ b/app/views/plantings/_quick_actions.haml @@ -0,0 +1,13 @@ +- if can?(:edit, planting) + .planting-quick-actions.pull-right + %a.btn.btn-default.btn-xs#actionsMenu.nav-link.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", href: "#"} + =icon('fas', 'bars') + %ul.dropdown-menu{"aria-labelledby" => "actionsMenu"} + - if can?(:edit, planting) + %li= planting_edit_button(planting) + %li= add_photo_button(planting) + + - if planting.active? + %li= planting_finish_button(planting) + %li= planting_harvest_button(planting) + %li= planting_save_seeds_button(planting) diff --git a/app/views/plantings/_thumbnail.html.haml b/app/views/plantings/_thumbnail.html.haml index bfe4892a8..2ce49fd94 100644 --- a/app/views/plantings/_thumbnail.html.haml +++ b/app/views/plantings/_thumbnail.html.haml @@ -1,20 +1,12 @@ .planting - .planting-badges + .planting-thumbnail + = render 'plantings/quick_actions', planting: planting = render 'plantings/badges', planting: planting + .planting-thumbnail-image + = link_to planting do + = image_tag(planting_image_path(planting), + class: 'img-responsive planting-thumbnail-photo', + alt: planting) - .planting-quick-actions.pull-right - %a.btn.btn-default.btn-xs#actionsMenu.nav-link.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", href: "#"} - =icon('fas', 'bars') - .dropdown-menu{"aria-labelledby" => "actionsMenu"} - %p= render 'plantings/actions', planting: planting - - .thumbnail - - .planting-thumbnail{ class: planting_classes(planting) } - = link_to image_tag(planting_image_path(planting), - alt: planting.crop.name, class: 'img'), planting_path(planting) - = render 'plantings/progress', planting: planting, show_explanation: false - - .planting-name - = link_to planting.crop.name, planting - + = render 'plantings/progress', planting: planting, show_explanation: false + .planting-name= link_to planting.crop.name, planting diff --git a/config/locales/en.yml b/config/locales/en.yml index 0fb739f84..01cab2db2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -190,6 +190,10 @@ en: number_crops_linktext: "%{count} crops" number_gardens_linktext: "%{count} gardens" number_plantings_linktext: "%{count} times" + label: + days_until_harvest: "%{number} days" + days_until_finished: "%{number} days" + harvesting_now: harvesting now layouts: header: account: Account diff --git a/script/check_contributors_md.rb b/script/check_contributors_md.rb index 4792abbb5..9aa3fa290 100755 --- a/script/check_contributors_md.rb +++ b/script/check_contributors_md.rb @@ -1,6 +1,8 @@ #!/usr/bin/env ruby +require "English" puts "Checking to see if you're in CONTRIBUTORS.md..." + if ENV['TRAVIS'] if ENV['TRAVIS_PULL_REQUEST'] require 'httparty' @@ -27,7 +29,10 @@ Please set it using end end -unless system('grep', '-i', author, 'CONTRIBUTORS.md') +# Escape chars in name, and make case insensitive +author_to_search_for = Regexp.new(Regexp.escape(author), Regexp::IGNORECASE) + +unless File.read('CONTRIBUTORS.md').match?(author_to_search_for) abort %( Thanks for your contribution, #{author}! Please add your name and GitHub handle to the file CONTRIBUTORS.md, diff --git a/spec/controllers/admin_controller_spec.rb b/spec/controllers/admin_controller_spec.rb index 5aa87e7cb..ad6cba550 100644 --- a/spec/controllers/admin_controller_spec.rb +++ b/spec/controllers/admin_controller_spec.rb @@ -5,6 +5,7 @@ describe AdminController do describe "GET admin/newsletter" do before { get :newsletter } + describe 'fetches the admin newsletter page' do it { expect(response).to be_success } it { expect(response).to render_template("admin/newsletter") } @@ -12,6 +13,7 @@ describe AdminController do describe 'assigns @members' do let!(:m) { FactoryBot.create(:newsletter_recipient_member) } + it { expect(assigns(:members)).to eq [m] } end end diff --git a/spec/controllers/api/v1/plantings_controller_spec.rb b/spec/controllers/api/v1/plantings_controller_spec.rb new file mode 100644 index 000000000..57b450d94 --- /dev/null +++ b/spec/controllers/api/v1/plantings_controller_spec.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Api::V1::PlantingsController, type: :controller do + subject { JSON.parse response.body } + + let(:headers) do + { + 'Accept' => 'application/vnd.api+json', + 'Content-Type' => 'application/vnd.api+json' + } + end + let!(:member) { FactoryBot.create :member } + + describe '#index' do + let(:matching_planting) { subject['data'].select { |planting| planting['id'] == my_planting.id.to_s }.first } + + describe 'GET #index' do + context 'basic planting' do + let!(:my_planting) { FactoryBot.create(:planting, owner: member, planted_at: '2000-01-01') } + let(:expected_attributes) do + { + 'crop-name' => my_planting.crop.name, + 'description' => my_planting.description, + 'expected-lifespan' => nil, + 'finish-predicted-at' => nil, + 'finished' => my_planting.finished, + 'finished-at' => my_planting.finished_at, + 'first-harvest-date' => nil, + 'last-harvest-date' => nil, + 'percentage-grown' => nil, + 'planted-at' => '2000-01-01', + 'planted-from' => my_planting.planted_from, + 'quantity' => my_planting.quantity, + 'slug' => my_planting.slug, + 'sunniness' => nil, + 'thumbnail' => nil + } + end + + before { get :index, format: :json } + + it { expect(matching_planting).to include('id' => my_planting.id.to_s) } + it { expect(matching_planting['attributes']).to eq expected_attributes } + it { expect(response.status).to eq 200 } + end + + context 'with photo' do + let!(:my_planting) { FactoryBot.create(:planting, owner: member, planted_at: '2000-01-01') } + + let(:expected_attributes) do + { + 'crop-name' => my_planting.crop.name, + 'description' => my_planting.description, + 'expected-lifespan' => nil, + 'finish-predicted-at' => nil, + 'finished' => my_planting.finished, + 'finished-at' => my_planting.finished_at, + 'first-harvest-date' => nil, + 'last-harvest-date' => nil, + 'percentage-grown' => nil, + 'planted-at' => '2000-01-01', + 'planted-from' => my_planting.planted_from, + 'quantity' => my_planting.quantity, + 'slug' => my_planting.slug, + 'sunniness' => nil, + 'thumbnail' => photo.thumbnail_url + } + end + let(:photo) { FactoryBot.create(:photo, owner: my_planting.owner) } + + before do + my_planting.photos << photo + get :index, format: :json + end + + it { expect(matching_planting).to include('id' => my_planting.id.to_s) } + it { expect(matching_planting['attributes']).to eq expected_attributes } + it { expect(response.status).to eq 200 } + end + end + end +end diff --git a/spec/controllers/authentications_controller_spec.rb b/spec/controllers/authentications_controller_spec.rb index db4bec89a..7da3d0501 100644 --- a/spec/controllers/authentications_controller_spec.rb +++ b/spec/controllers/authentications_controller_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe AuthenticationsController do - before(:each) do + before do @member = FactoryBot.create(:member) sign_in @member controller.stub(:current_member) { @member } diff --git a/spec/controllers/charts/crops_controller_spec.rb b/spec/controllers/charts/crops_controller_spec.rb index 962b57891..120179c78 100644 --- a/spec/controllers/charts/crops_controller_spec.rb +++ b/spec/controllers/charts/crops_controller_spec.rb @@ -3,16 +3,22 @@ require 'rails_helper' describe Charts::CropsController do describe 'GET charts' do let(:crop) { FactoryBot.create :crop } + describe 'sunniness' do before { get :sunniness, params: { crop_slug: crop.to_param } } + it { expect(response).to be_success } end + describe 'planted_from' do before { get :planted_from, params: { crop_slug: crop.to_param } } + it { expect(response).to be_success } end + describe 'harvested_for' do before { get :harvested_for, params: { crop_slug: crop.to_param } } + it { expect(response).to be_success } end end diff --git a/spec/controllers/charts/gardens_controller_spec.rb b/spec/controllers/charts/gardens_controller_spec.rb index c0d331876..250b05358 100644 --- a/spec/controllers/charts/gardens_controller_spec.rb +++ b/spec/controllers/charts/gardens_controller_spec.rb @@ -9,17 +9,19 @@ describe Charts::GardensController do context "when not signed in" do describe 'GET timeline' do before { get :timeline, params: { garden_id: garden.to_param } } + it { expect(response).to be_success } end end context "when signed in" do - before(:each) { sign_in member } + before { sign_in member } let!(:member) { FactoryBot.create(:member) } describe 'GET timeline' do before { get :timeline, params: { garden_id: garden.to_param } } + it { expect(response).to be_success } end end diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 4d9e9fc6b..2961288dc 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -5,7 +5,7 @@ describe CommentsController do let(:member) { FactoryBot.create(:member) } - before(:each) do + before do sign_in member controller.stub(:current_member) { member } end @@ -35,12 +35,11 @@ describe CommentsController do describe "with valid params" do before { get :new, params: { post_id: post.id } } + let(:old_comment) { FactoryBot.create(:comment, post: post) } it "picks up post from params" do expect(assigns(:post)).to eq(post) end - let(:old_comment) { FactoryBot.create(:comment, post: post) } - it "assigns the old comments as @comments" do expect(assigns(:comments)).to eq [old_comment] end @@ -54,6 +53,7 @@ describe CommentsController do describe "GET edit" do let(:post) { FactoryBot.create(:post) } + before { get :edit, params: { id: comment.to_param } } describe "my comment" do diff --git a/spec/controllers/gardens_controller_spec.rb b/spec/controllers/gardens_controller_spec.rb index 720ba5a7b..3222829fe 100644 --- a/spec/controllers/gardens_controller_spec.rb +++ b/spec/controllers/gardens_controller_spec.rb @@ -9,11 +9,13 @@ RSpec.describe GardensController, type: :controller do context "when not signed in" do describe 'GET new' do before { get :new, params: { id: garden.to_param } } + it { expect(response).to redirect_to(new_member_session_path) } end describe 'PUT create' do before { put :create, params: { garden: valid_params } } + it { expect(response).to redirect_to(new_member_session_path) } end @@ -29,23 +31,26 @@ RSpec.describe GardensController, type: :controller do describe 'GET edit' do before { get :edit, params: { id: garden.to_param } } + it { expect(response).to redirect_to(new_member_session_path) } end describe 'POST update' do before { post :update, params: { id: garden.to_param, garden: valid_params } } + it { expect(response).to redirect_to(new_member_session_path) } end describe 'DELETE' do before { delete :destroy, params: { id: garden.to_param, params: { garden: valid_params } } } + it { expect(response).to redirect_to(new_member_session_path) } end end end context "when signed in" do - before(:each) { sign_in member } + before { sign_in member } let!(:member) { FactoryBot.create(:member) } @@ -63,16 +68,19 @@ RSpec.describe GardensController, type: :controller do describe 'GET edit' do before { get :edit, params: { id: not_my_garden.to_param } } + it { expect(response).to redirect_to(root_path) } end describe 'POST update' do before { post :update, params: { id: not_my_garden.to_param, garden: valid_params } } + it { expect(response).to redirect_to(root_path) } end describe 'DELETE' do before { delete :destroy, params: { id: not_my_garden.to_param, params: { garden: valid_params } } } + it { expect(response).to redirect_to(root_path) } end end diff --git a/spec/controllers/harvests_controller_spec.rb b/spec/controllers/harvests_controller_spec.rb index b7259293e..6853ff477 100644 --- a/spec/controllers/harvests_controller_spec.rb +++ b/spec/controllers/harvests_controller_spec.rb @@ -22,17 +22,20 @@ describe HarvestsController do describe "assigns all harvests as @harvests" do before { get :index, params: {} } + it { expect(assigns(:harvests)).to eq [harvest1, harvest2] } end describe "picks up owner from params and shows owner's harvests only" do before { get :index, params: { member_slug: member1.slug } } + it { expect(assigns(:owner)).to eq member1 } it { expect(assigns(:harvests)).to eq [harvest1] } end describe "picks up crop from params and shows the harvests for the crop only" do before { get :index, params: { crop_slug: maize.name } } + it { expect(assigns(:crop)).to eq maize } it { expect(assigns(:harvests)).to eq [harvest2] } end @@ -49,6 +52,7 @@ describe HarvestsController do describe "assigns the requested harvest as @harvest" do before { get :show, params: { id: harvest.to_param } } + it { expect(assigns(:harvest)).to eq(harvest) } end end @@ -70,6 +74,7 @@ describe HarvestsController do describe "assigns the requested harvest as @harvest" do before { get :edit, params: { id: harvest.to_param } } + it { expect(assigns(:harvest)).to eq(harvest) } end end @@ -84,18 +89,22 @@ describe HarvestsController do describe "assigns a newly created harvest as @harvest" do before { post :create, params: { harvest: valid_attributes } } + it { expect(assigns(:harvest)).to be_a(Harvest) } it { expect(assigns(:harvest)).to be_persisted } end describe "redirects to the created harvest" do before { post :create, params: { harvest: valid_attributes } } + it { expect(response).to redirect_to(Harvest.last) } end describe "links to planting" do let(:planting) { FactoryBot.create(:planting, owner_id: member.id, garden: member.gardens.first) } + before { post :create, params: { harvest: valid_attributes.merge(planting_id: planting.id) } } + it { expect(Harvest.last.planting.id).to eq(planting.id) } end end @@ -111,6 +120,7 @@ describe HarvestsController do describe "re-renders the 'new' template" do # Trigger the behavior that occurs when invalid params are submitted before { post :create, params: { harvest: { "crop_id" => "invalid value" } } } + it { expect(response).to render_template("new") } end end @@ -133,6 +143,7 @@ describe HarvestsController do describe "PUT update" do describe "with valid params" do let(:harvest) { Harvest.create! valid_attributes } + it "updates the requested harvest" do new_crop = FactoryBot.create :crop expect do @@ -143,11 +154,13 @@ describe HarvestsController do describe "assigns the requested harvest as @harvest" do before { put :update, params: { id: harvest.to_param, harvest: valid_attributes } } + it { expect(assigns(:harvest)).to eq(harvest) } end describe "redirects to the harvest" do before { put :update, params: { id: harvest.to_param, harvest: valid_attributes } } + it { expect(response).to redirect_to(harvest) } end end diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index c27d05de9..a62c8a9cb 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -9,8 +9,9 @@ describe LikesController do before { sign_in member } describe "POST create" do - it { expect(response.content_type).to eq "application/json" } before { post :create, params: { post_id: blogpost.id, format: :json } } + it { expect(response.content_type).to eq "application/json" } + it { expect(Like.last.likeable_id).to eq(blogpost.id) } it { expect(Like.last.likeable_type).to eq('Post') } it { JSON.parse(response.body)["description"] == "1 like" } @@ -26,6 +27,7 @@ describe LikesController do describe "DELETE destroy" do before { delete :destroy, params: { id: like.id, format: :json } } + it { expect(response.content_type).to eq "application/json" } describe "un-liking something i liked before" do diff --git a/spec/controllers/member_controller_spec.rb b/spec/controllers/member_controller_spec.rb index 34ef19c34..f6d01207f 100644 --- a/spec/controllers/member_controller_spec.rb +++ b/spec/controllers/member_controller_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe MembersController do - before :each do + before do @member = FactoryBot.create(:member) @posts = [FactoryBot.create(:post, author: @member)] @twitter_auth = FactoryBot.create(:authentication, member: @member) @@ -58,6 +58,7 @@ describe MembersController do describe "GET member's RSS feed" do describe "returns an RSS feed" do before { get :show, params: { slug: @member.to_param }, format: "rss" } + it { response.should be_success } it { response.should render_template("members/show") } it { response.content_type.should eq("application/rss+xml") } diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index db0ebf8fb..d81f775f1 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -35,7 +35,7 @@ describe PhotosController do let(:member) { FactoryBot.create(:member) } let!(:auth) { FactoryBot.create(:flickr_authentication, member: member) } - before(:each) do + before do sign_in member member.stub(:flickr_photos) { [[], 0] } member.stub(:flickr_sets) { { "foo" => "bar" } } @@ -43,7 +43,8 @@ describe PhotosController do end describe "planting photos" do - before(:each) { get :new, params: { type: "planting", id: planting.id } } + before { get :new, params: { type: "planting", id: planting.id } } + it { assigns(:flickr_auth).should be_an_instance_of(Authentication) } it { assigns(:item).should eq planting } it { expect(flash[:alert]).not_to be_present } @@ -52,19 +53,21 @@ describe PhotosController do describe "harvest photos" do before { get :new, params: { type: "harvest", id: harvest.id } } + it { assigns(:item).should eq harvest } it { expect(flash[:alert]).not_to be_present } end describe "garden photos" do before { get :new, params: { type: "garden", id: garden.id } } + it { expect(assigns(:item)).to eq garden } it { expect(flash[:alert]).not_to be_present } end end describe "POST create" do - before(:each) do + before do Photo.any_instance.stub(:flickr_metadata).and_return(title: "A Heartbreaking work of staggering genius", license_name: "CC-BY", license_url: "http://example.com/aybpl", @@ -135,6 +138,7 @@ describe PhotosController do describe "for the second time" do let(:planting) { FactoryBot.create :planting, owner: member } let(:valid_params) { { photo: { flickr_photo_id: 1 }, id: planting.id, type: 'planting' } } + it "does not add a photo twice" do expect { post :create, params: valid_params }.to change(Photo, :count).by(1) expect { post :create, params: valid_params }.not_to change(Photo, :count) @@ -156,6 +160,7 @@ describe PhotosController do before do post :create, params: { photo: { flickr_photo_id: photo.flickr_photo_id }, type: "harvest", id: harvest.id } end + it { expect(flash[:alert]).not_to be_present } it { expect(Photo.last.harvests.first).to eq harvest } end diff --git a/spec/controllers/places_controller_spec.rb b/spec/controllers/places_controller_spec.rb index d235b98c9..a32d27c28 100644 --- a/spec/controllers/places_controller_spec.rb +++ b/spec/controllers/places_controller_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' describe PlacesController do - before :each do + before do controller.stub(:current_member) { nil } end describe "GET show" do - before(:each) do + before do @member_london = FactoryBot.create(:london_member) @member_south_pole = FactoryBot.create(:south_pole_member) end diff --git a/spec/controllers/plantings_controller_spec.rb b/spec/controllers/plantings_controller_spec.rb index c4a60d1a4..d0a5c11a6 100644 --- a/spec/controllers/plantings_controller_spec.rb +++ b/spec/controllers/plantings_controller_spec.rb @@ -26,12 +26,14 @@ describe PlantingsController do describe "picks up owner from params and shows owner's plantings only" do before { get :index, params: { member_slug: member1.slug } } + it { expect(assigns(:owner)).to eq member1 } it { expect(assigns(:plantings)).to eq [planting1] } end describe "picks up crop from params and shows the plantings for the crop only" do before { get :index, params: { crop_slug: maize.slug } } + it { expect(assigns(:crop)).to eq maize } it { expect(assigns(:plantings)).to eq [planting2] } end @@ -40,44 +42,56 @@ describe PlantingsController do describe "GET new" do describe "picks up crop from params" do let(:crop) { FactoryBot.create(:crop) } + before { get :new, params: { crop_id: crop.id } } + it { expect(assigns(:crop)).to eq(crop) } end describe "doesn't die if no crop specified" do before { get :new, params: {} } + it { expect(assigns(:crop)).to be_a_new(Crop) } end describe "picks up member's garden from params" do let(:garden) { FactoryBot.create(:garden, owner: member) } + before { get :new, params: { garden_id: garden.id } } + it { expect(assigns(:garden)).to eq(garden) } end describe "Doesn't display another member's garden on planting form" do let(:another_member) { FactoryBot.create(:member) } # over-riding member from login_member() let(:garden) { FactoryBot.create(:garden, owner: another_member) } + before { get :new, params: { garden_id: garden.id } } + it { expect(assigns(:garden)).not_to eq(garden) } end describe "Doesn't display un-approved crops on planting form" do let(:crop) { FactoryBot.create(:crop, approval_status: 'pending') } let!(:garden) { FactoryBot.create(:garden, owner: member) } + before { get :new, params: { crop_id: crop.id } } + it { expect(assigns(:crop)).not_to eq(crop) } end describe "Doesn't display rejected crops on planting form" do let(:crop) { FactoryBot.create(:crop, approval_status: 'rejected', reason_for_rejection: 'nope') } let!(:garden) { FactoryBot.create(:garden, owner: member) } + before { get :new, params: { crop_id: crop.id } } + it { expect(assigns(:crop)).not_to eq(crop) } end describe "doesn't die if no garden specified" do before { get :new, params: {} } + it { expect(assigns(:garden)).to be_a_new(Garden) } end @@ -89,7 +103,9 @@ describe PlantingsController do context 'with parent seed' do let(:seed) { FactoryBot.create :seed, owner: member } + before { get :new, params: { seed_id: seed.to_param } } + it { expect(assigns(:seed)).to eq(seed) } end end @@ -97,6 +113,7 @@ describe PlantingsController do describe 'POST :create' do describe "sets the owner automatically" do before { post :create, params: { planting: valid_attributes } } + it { expect(assigns(:planting).owner).to eq subject.current_member } end end diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 015bbb705..82b52652d 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe RegistrationsController do - before :each do + before do @member = FactoryBot.create(:member) sign_in @member controller.stub(:current_user) { @member } diff --git a/spec/controllers/seeds_controller_spec.rb b/spec/controllers/seeds_controller_spec.rb index 3c90841d1..eefaa1c36 100644 --- a/spec/controllers/seeds_controller_spec.rb +++ b/spec/controllers/seeds_controller_spec.rb @@ -5,8 +5,10 @@ describe SeedsController do describe "GET index" do let(:owner) { FactoryBot.create(:member) } + describe "picks up owner from params" do before { get :index, params: { member_slug: owner.slug } } + it { expect(assigns(:owner)).to eq(owner) } end end @@ -22,7 +24,9 @@ describe SeedsController do context 'with parent planting' do let(:planting) { FactoryBot.create :planting, owner: owner } + before { get :new, params: { planting_id: planting.to_param } } + it { expect(assigns(:planting)).to eq(planting) } end end diff --git a/spec/factories/notifications.rb b/spec/factories/notifications.rb index b0b3dce97..4d2cee82f 100644 --- a/spec/factories/notifications.rb +++ b/spec/factories/notifications.rb @@ -5,6 +5,7 @@ FactoryBot.define do sender { FactoryBot.create :member } recipient { FactoryBot.create :member } subject { "MyString" } + body { "MyText" } read { false } post diff --git a/spec/features/crops/crop_wranglers_spec.rb b/spec/features/crops/crop_wranglers_spec.rb index 86dc8a1c0..4dc8633ac 100644 --- a/spec/features/crops/crop_wranglers_spec.rb +++ b/spec/features/crops/crop_wranglers_spec.rb @@ -34,6 +34,7 @@ feature "crop wranglers", js: true do describe "visiting a crop can see wrangler links" do before { visit crop_path(crops.first) } + it { expect(page).to have_content 'You are a CROP WRANGLER' } it { expect(page).to have_link 'Edit' } it { expect(page).to have_link 'Delete' } diff --git a/spec/features/crops/show_spec.rb b/spec/features/crops/show_spec.rb index 1075ee602..e7bfc0358 100644 --- a/spec/features/crops/show_spec.rb +++ b/spec/features/crops/show_spec.rb @@ -13,6 +13,7 @@ feature "browse crops" do context "when the most recently created harvest is not the most recently harvested" do before { FactoryBot.create_list :harvest, 20, crop: tomato, harvested_at: 1.year.ago, created_at: 1.minute.ago } + let!(:most_recent_harvest) do FactoryBot.create :harvest, crop: tomato, harvested_at: 60.minutes.ago, created_at: 10.minutes.ago end @@ -25,6 +26,7 @@ feature "browse crops" do context "when the most recently created planting is not the most recently planted" do before { FactoryBot.create_list :planting, 20, crop: tomato, planted_at: 1.year.ago, created_at: 1.minute.ago } + let!(:most_recent_planting) do FactoryBot.create :planting, crop: tomato, planted_at: 60.minutes.ago, created_at: 10.minutes.ago end diff --git a/spec/features/gardens/actions_spec.rb b/spec/features/gardens/actions_spec.rb index 8c5068415..98337063d 100644 --- a/spec/features/gardens/actions_spec.rb +++ b/spec/features/gardens/actions_spec.rb @@ -55,13 +55,16 @@ feature "Gardens" do describe '#show' do describe 'my garden' do before { visit garden_path(garden) } + it { is_expected.to have_link 'Edit' } it { is_expected.to have_link 'Delete' } it { is_expected.to have_content "Plant something here" } it { is_expected.to have_content "Add photo" } end + describe "someone else's garden" do before { visit garden_path(other_member_garden) } + it { is_expected.not_to have_link 'Edit' } it { is_expected.not_to have_link 'Delete' } it { is_expected.not_to have_content "Plant something here" } diff --git a/spec/features/gardens/gardens_index_spec.rb b/spec/features/gardens/gardens_index_spec.rb index fa047d8d8..0c29e3df6 100644 --- a/spec/features/gardens/gardens_index_spec.rb +++ b/spec/features/gardens/gardens_index_spec.rb @@ -34,7 +34,7 @@ feature "Gardens#index", :js do it "show active garden" do expect(page).to have_text active_garden.name end - it "should not show inactive garden" do + it "does not show inactive garden" do expect(page).not_to have_text inactive_garden.name end it "links to active garden" do @@ -74,7 +74,7 @@ feature "Gardens#index", :js do let(:member) { FactoryBot.create :member, login_name: 'robbieburns' } let(:crop) { FactoryBot.create :crop } - before(:each) do + before do # time to harvest = 50 day # time to finished = 90 days FactoryBot.create(:harvest, @@ -104,8 +104,8 @@ feature "Gardens#index", :js do it { expect(page).to have_link href: planting_path(planting) } it { expect(page).to have_link href: garden_path(planting.garden) } - it { expect(page).to have_text '50 days until harvest' } - it { expect(page).to have_text '90 days until finished' } + it { expect(page).to have_text '50 days' } + it { expect(page).to have_text '90 days' } it { expect(page).not_to have_text 'harvesting now' } end @@ -121,8 +121,8 @@ feature "Gardens#index", :js do it { expect(crop.median_lifespan).to eq 90 } it { expect(page).to have_text 'harvesting now' } - it { expect(page).to have_text '39 days until finished' } - it { expect(page).not_to have_text 'days until harvest' } + it { expect(page).to have_text '39 days' } + it { expect(page).not_to have_text 'Predicted days until harvest' } end describe 'super late' do @@ -134,8 +134,8 @@ feature "Gardens#index", :js do it { expect(page).to have_text 'super late' } it { expect(page).not_to have_text 'harvesting now' } - it { expect(page).not_to have_text 'days until harvest' } - it { expect(page).not_to have_text 'days until finished' } + it { expect(page).not_to have_text 'Predicted days until harvest' } + it { expect(page).not_to have_text 'Predicted days until planting is finished' } end end end diff --git a/spec/features/harvests/browse_harvests_spec.rb b/spec/features/harvests/browse_harvests_spec.rb index 010433be2..cadbc19e7 100644 --- a/spec/features/harvests/browse_harvests_spec.rb +++ b/spec/features/harvests/browse_harvests_spec.rb @@ -21,7 +21,7 @@ feature "browse harvests" do feature "filled in optional fields" do let!(:harvest) { create :harvest, :long_description } - before(:each) do + before do visit harvests_path end diff --git a/spec/features/home/home_spec.rb b/spec/features/home/home_spec.rb index d02bb619f..812f84710 100644 --- a/spec/features/home/home_spec.rb +++ b/spec/features/home/home_spec.rb @@ -87,6 +87,7 @@ feature "home page" do describe 'should say welcome' do before { visit root_path } + it { expect(page).to have_content "Welcome to #{ENV['GROWSTUFF_SITE_NAME']}, #{member.login_name}" } end end diff --git a/spec/features/places/searching_a_place_spec.rb b/spec/features/places/searching_a_place_spec.rb index edbb06e59..fb11308b5 100644 --- a/spec/features/places/searching_a_place_spec.rb +++ b/spec/features/places/searching_a_place_spec.rb @@ -30,23 +30,23 @@ feature "User searches" do search_with "Philippines" end - it "should show that there are nearby seeds, plantings, and members" do + it "shows that there are nearby seeds, plantings, and members" do expect(page).to have_content "Nearby members" expect(page).to have_content "Seeds available for trade near Philippines" expect(page).to have_content "Recent plantings near Philippines" end - it "should go to members' index page" do + it "goes to members' index page" do click_link 'View all members >>' expect(current_path).to eq members_path end - it "should go to plantings' index page" do + it "goes to plantings' index page" do click_link 'View all plantings >>' expect(current_path).to eq plantings_path end - it "should go to seeds' index page" do + it "goes to seeds' index page" do click_link 'View all seeds >>' expect(current_path).to eq seeds_path end diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 81eb20b43..386ee6407 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -64,7 +64,7 @@ feature "Planting a crop", :js, :elasticsearch do @a_future_date = 1.year.from_now.strftime("%Y-%m-%d") end - it "should show that it is not planted yet" do + it "shows that it is not planted yet" do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do @@ -80,7 +80,7 @@ feature "Planting a crop", :js, :elasticsearch do expect(page).to have_content "0%" end - it "should show that days before maturity is unknown" do + it "shows that days before maturity is unknown" do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do @@ -96,7 +96,7 @@ feature "Planting a crop", :js, :elasticsearch do expect(page).to have_content "Not enough data" end - it "should show that planting is in progress" do + it "shows that planting is in progress" do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do @@ -115,7 +115,7 @@ feature "Planting a crop", :js, :elasticsearch do expect(page).not_to have_content "Not enough data" end - it "should show that planting is 100% complete (no date specified)" do + it "shows that planting is 100% complete (no date specified)" do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do @@ -133,7 +133,7 @@ feature "Planting a crop", :js, :elasticsearch do expect(page).to have_content "Yes (no date specified)" end - it "should show that planting is 100% complete (date specified)" do + it "shows that planting is 100% complete (date specified)" do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do @@ -234,13 +234,14 @@ feature "Planting a crop", :js, :elasticsearch do click_button "Save" end end + it { expect(page).to have_content "planting was successfully created" } it { expect(page).to have_content "Finished: Yes (no date specified)" } it { expect(page).to have_content "100%" } end describe "Planting sunniness" do - it "should show the a sunny image" do + it "shows the a sunny image" do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do @@ -256,7 +257,7 @@ feature "Planting a crop", :js, :elasticsearch do expect(page).to have_css("img[alt='sun']") end - it "should show a sunniness not specified image" do + it "shows a sunniness not specified image" do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do diff --git a/spec/features/seeds/adding_seeds_spec.rb b/spec/features/seeds/adding_seeds_spec.rb index 021a24336..f87d8f59d 100644 --- a/spec/features/seeds/adding_seeds_spec.rb +++ b/spec/features/seeds/adding_seeds_spec.rb @@ -47,6 +47,7 @@ feature "Seeds", :js, :elasticsearch do click_button "Save" end end + it { expect(page).to have_content "Successfully added maize seed to your stash" } it { expect(page).to have_content "Quantity: 42" } it { expect(page).to have_content "Days until maturity: 999–1999" } diff --git a/spec/features/seeds/misc_seeds_spec.rb b/spec/features/seeds/misc_seeds_spec.rb index fafcc3d12..e7c1e0291 100644 --- a/spec/features/seeds/misc_seeds_spec.rb +++ b/spec/features/seeds/misc_seeds_spec.rb @@ -10,10 +10,12 @@ feature "seeds", js: true do describe "button on index to edit seed" do let!(:seed) { create :seed, owner: member } + before do visit seeds_path click_link "edit_seed_glyphicon" end + it { expect(current_path).to eq edit_seed_path(seed) } it { expect(page).to have_content 'Editing seeds' } end @@ -23,6 +25,7 @@ feature "seeds", js: true do visit root_path click_link "Save seeds" end + it { expect(current_path).to eq new_seed_path } it { expect(page).to have_content 'Save seeds' } end @@ -32,6 +35,7 @@ feature "seeds", js: true do visit member_seeds_path(member) click_link "View #{member}'s profile >>" end + it { expect(current_path).to eq member_path(member) } end @@ -49,32 +53,39 @@ feature "seeds", js: true do describe "delete seeds" do let(:seed) { FactoryBot.create :seed, owner: member } + before do visit seed_path(seed) click_link 'Delete' end + it { expect(current_path).to eq seeds_path } end describe '#show' do before { visit seed_path(seed) } + describe "view seeds with max and min days until maturity" do let(:seed) { FactoryBot.create :seed, days_until_maturity_min: 5, days_until_maturity_max: 7 } + it { expect(page).to have_content "Days until maturity: 5–7" } end describe "view seeds with only max days until maturity" do let(:seed) { FactoryBot.create :seed, days_until_maturity_max: 7 } + it { expect(page).to have_content "Days until maturity: 7" } end describe "view seeds with only min days until maturity" do let(:seed) { FactoryBot.create :seed, days_until_maturity_min: 5 } + it { expect(page).to have_content "Days until maturity: 5" } end describe "view seeds with neither max nor min days until maturity" do let(:seed) { FactoryBot.create :seed } + it { expect(page).to have_content "Days until maturity: unknown" } end end diff --git a/spec/features/signout_spec.rb b/spec/features/signout_spec.rb index 35cd8af9b..2b020a4c2 100644 --- a/spec/features/signout_spec.rb +++ b/spec/features/signout_spec.rb @@ -3,6 +3,7 @@ require 'rails_helper' feature "signout" do let(:member) { create :member } + let(:path) {} scenario "redirect to previous page after signout" do visit crops_path # some random page click_link 'Sign in' @@ -29,8 +30,6 @@ feature "signout" do end end - let(:path) {} - describe 'after signout, redirect to signin page if page needs authentication' do include_examples "sign-in redirects", "/plantings/new" include_examples "sign-in redirects", "/harvests/new" diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 5c1d11d9e..353e6e9b0 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -17,25 +17,25 @@ describe ApplicationHelper do describe '#avatar_uri' do context 'with a normal user' do - before :each do + before do @member = FactoryBot.build(:member, email: 'example@example.com', preferred_avatar_uri: nil) end - it 'should render a gravatar uri' do + it 'renders a gravatar uri' do expect(avatar_uri(@member)).to eq 'http://www.gravatar.com/avatar/23463b99b62a72f26ed677cc556c44e8?size=150&default=identicon' end - it 'should render a gravatar uri for a given size' do + it 'renders a gravatar uri for a given size' do expect(avatar_uri(@member, 456)).to eq 'http://www.gravatar.com/avatar/23463b99b62a72f26ed677cc556c44e8?size=456&default=identicon' end end context 'with a user who specified a preferred avatar uri' do - before :each do + before do @member = FactoryBot.build(:member, email: 'example@example.com', preferred_avatar_uri: 'http://media.catmoji.com/post/ujg/cat-in-hat.jpg') end - it 'should render a the specified uri' do + it 'renders a the specified uri' do expect(avatar_uri(@member)).to eq 'http://media.catmoji.com/post/ujg/cat-in-hat.jpg' end end diff --git a/spec/helpers/buttons_helper_spec.rb b/spec/helpers/buttons_helper_spec.rb index d3def8e00..d16d01f0e 100644 --- a/spec/helpers/buttons_helper_spec.rb +++ b/spec/helpers/buttons_helper_spec.rb @@ -11,7 +11,8 @@ require 'rails_helper' # end # end RSpec.describe ButtonsHelper, type: :helper do - before { allow(self).to receive(:can?) { true } } + before { allow(self).to receive(:can?).and_return(true) } + let(:garden) { FactoryBot.create :garden } let(:planting) { FactoryBot.create :planting } let(:harvest) { FactoryBot.create :harvest } diff --git a/spec/helpers/crops_helper_spec.rb b/spec/helpers/crops_helper_spec.rb index 49a570836..532019e41 100644 --- a/spec/helpers/crops_helper_spec.rb +++ b/spec/helpers/crops_helper_spec.rb @@ -2,13 +2,13 @@ require 'rails_helper' describe CropsHelper do describe "display_seed_availability" do - before :each do - @member = create :member + before do + @member = create :member @crop = create :tomato end context "with no seeds" do - it 'should render' do + it 'renders' do expect(helper.display_seed_availability(@member, @crop)).to eq "You don't have any seeds of this crop." end end @@ -18,7 +18,7 @@ describe CropsHelper do create :seed, crop: @crop, quantity: nil, owner: @member end - it 'should render' do + it 'renders' do expect( helper.display_seed_availability(@member, @crop) ).to eq "You have an unknown quantity of seeds of this crop." @@ -35,7 +35,7 @@ describe CropsHelper do create :seed, crop: a_different_crop, quantity: 3, owner: @member end - it 'should render' do + it 'renders' do expect(helper.display_seed_availability(@member, @crop)).to eq "You have 33 seeds of this crop." end end diff --git a/spec/lib/actions/oauth_signup_action_spec.rb b/spec/lib/actions/oauth_signup_action_spec.rb index 3fc37c00e..c6006e7c4 100644 --- a/spec/lib/actions/oauth_signup_action_spec.rb +++ b/spec/lib/actions/oauth_signup_action_spec.rb @@ -2,12 +2,12 @@ require 'rails_helper' require './lib/actions/oauth_signup_action' describe 'Growstuff::OauthSignupAction' do - before :each do + before do @action = Growstuff::OauthSignupAction.new end context 'with a valid authentication' do - before :each do + before do @auth = OmniAuth::AuthHash.new('provider' => 'facebook', 'uid' => '123545', 'info' => { @@ -23,7 +23,7 @@ describe 'Growstuff::OauthSignupAction' do end context 'no existing user' do - before :each do + before do @auth['info']['email'] = 'no.existing.user@gmail.com' Member.where(email: @auth['info']['email']).delete_all @@ -32,36 +32,36 @@ describe 'Growstuff::OauthSignupAction' do @authentication = @action.establish_authentication(@auth, @member) end - after :each do + after do @member.delete @authentication.delete end - it 'should create a new user' do + it 'creates a new user' do expect(@action.member_created?).to eq true end - it 'should set the right email' do + it 'sets the right email' do expect(@member.email).to eq @auth['info']['email'] end - it 'should generate a login_name' do + it 'generates a login_name' do expect(@member.login_name).to eq 'JohnnyB' end - it 'should set an avatar' do + it 'sets an avatar' do expect(@member.preferred_avatar_uri).to eq @auth['info']['image'] end - it 'should generate a random password' do + it 'generates a random password' do expect(@member.password).not_to eq nil end - it 'should not agree to the tos' do + it 'does not agree to the tos' do expect(@member.tos_agreement).to eq nil end - it 'should store the uid and provider for the member' do + it 'stores the uid and provider for the member' do expect(@authentication.member.id).to eq @member.id expect(@authentication.provider).to eq 'facebook' expect(@authentication.uid).to eq '123545' @@ -70,7 +70,7 @@ describe 'Growstuff::OauthSignupAction' do context 'an existing user' do context 'who has never used oauth' do - before :each do + before do @auth['info']['email'] = 'never.used.oauth@yahoo.com' Member.where(email: @auth['info']['email']).delete_all @@ -82,29 +82,29 @@ describe 'Growstuff::OauthSignupAction' do @authentication = @action.establish_authentication(@auth, @member) end - after :each do + after do @existing_member.delete @member.delete @authentication.delete end - it 'should not create a new user' do + it 'does not create a new user' do expect(@action.member_created?).to eq nil end - it 'should locate the existing member by email' do + it 'locates the existing member by email' do expect(@member.id).to eq @existing_member.id end - it 'should not generate a login_name' do + it 'does not generate a login_name' do expect(@member.login_name).to eq 'existing' end - it 'should not change the avatar' do + it 'does not change the avatar' do expect(@member.preferred_avatar_uri).to eq 'http://cl.jroo.me/z3/W/H/K/e/a.baa-very-cool-hat-you-.jpg' end - it 'should store the uid and provider for the member' do + it 'stores the uid and provider for the member' do expect(@authentication.member.id).to eq @member.id expect(@authentication.provider).to eq 'facebook' expect(@authentication.uid).to eq '123545' @@ -112,7 +112,7 @@ describe 'Growstuff::OauthSignupAction' do end context 'who has used oauth' do - before :each do + before do @auth['info']['email'] = 'i.used.oauth.once@coolemail.com' Member.where(email: @auth['info']['email']).delete_all @@ -131,30 +131,30 @@ describe 'Growstuff::OauthSignupAction' do @authentication = @action.establish_authentication(@auth, @member) end - after :each do + after do @existing_member.delete @member.delete @existing_authentication.delete @authentication.delete end - it 'should not create a new user' do + it 'does not create a new user' do expect(@action.member_created?).to eq nil end - it 'should locate the existing member by uid and provider' do + it 'locates the existing member by uid and provider' do expect(@member.id).to eq @existing_member.id end - it 'should not generate a login_name' do + it 'does not generate a login_name' do expect(@member.login_name).to eq 'schrodingerscat' end - it 'should not change the avatar' do + it 'does not change the avatar' do expect(@member.preferred_avatar_uri).to eq 'http://cl.jroo.me/z3/W/H/K/e/a.baa-very-cool-hat-you-.jpg' end - it 'should locate the existing uid and provider for the member' do + it 'locates the existing uid and provider for the member' do expect(@authentication.id).to eq @existing_authentication.id end end diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 7891135c9..7fa8bf9c6 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -51,7 +51,7 @@ describe Ability do context "crop wrangler" do let(:role) { FactoryBot.create(:crop_wrangler) } - before(:each) do + before do member.roles << role end diff --git a/spec/models/alternate_name_spec.rb b/spec/models/alternate_name_spec.rb index 42b8aa9aa..b7c4303e9 100644 --- a/spec/models/alternate_name_spec.rb +++ b/spec/models/alternate_name_spec.rb @@ -3,11 +3,11 @@ require 'rails_helper' describe AlternateName do let(:an) { FactoryBot.create(:alternate_eggplant) } - it 'should save a basic alternate name' do + it 'saves a basic alternate name' do expect(an.save).to be(true) end - it 'should be possible to add multiple alternate names to a crop' do + it 'is possible to add multiple alternate names to a crop' do crop = an.crop an2 = AlternateName.create( name: "really alternative tomato", diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index bc90ee8ba..687219386 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -42,7 +42,7 @@ describe Comment do end context "ordering" do - before(:each) do + before do @m = FactoryBot.create(:member) @p = FactoryBot.create(:post, author: @m) @c1 = FactoryBot.create(:comment, post: @p, author: @m) diff --git a/spec/models/follow_spec.rb b/spec/models/follow_spec.rb index bd61fe2ee..63e397d95 100644 --- a/spec/models/follow_spec.rb +++ b/spec/models/follow_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Follow do - before(:each) do + before do @member1 = FactoryBot.create(:member) @member2 = FactoryBot.create(:member) end @@ -20,20 +20,20 @@ describe Follow do end context "when follow is created" do - before(:each) do + before do @follow = Follow.create(follower_id: @member1.id, followed_id: @member2.id) end - it "should not duplicate follows" do + it "does not duplicate follows" do expect(Follow.create(follower_id: @member1.id, followed_id: @member2.id)).not_to be_valid end - it "should list users in following/follower collections when follow is created" do + it "lists users in following/follower collections when follow is created" do expect(@member1.followed).to include(@member2) expect(@member2.followers).to include(@member1) end - it "should no longer list users in following/follower collections when follow is deleted" do + it "noes longer list users in following/follower collections when follow is deleted" do @follow.destroy expect(@member1.followed).not_to include(@member2) expect(@member2.followers).not_to include(@member1) diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index 346e719b5..67c462bb6 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -4,11 +4,11 @@ describe Garden do let(:owner) { FactoryBot.create(:member, login_name: 'hatupatu') } let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Springfield Community Garden') } - it "should have a slug" do + it "has a slug" do garden.slug.should match(/hatupatu-springfield-community-garden/) end - it "should have a description" do + it "has a description" do garden.description.should == "This is a **totally** cool garden" end @@ -47,11 +47,11 @@ describe Garden do garden.should_not be_valid end - it "should have an owner" do + it "has an owner" do garden.owner.should be_an_instance_of Member end - it "should stringify as its name" do + it "stringifies as its name" do garden.to_s.should == garden.name end @@ -63,14 +63,14 @@ describe Garden do let(:pear) { FactoryBot.create(:pear) } let(:walnut) { FactoryBot.create(:walnut) } - it "should fetch < 4 featured plantings if insufficient exist" do + it "fetches < 4 featured plantings if insufficient exist" do @p1 = FactoryBot.create(:planting, crop: tomato, garden: garden, owner: garden.owner) @p2 = FactoryBot.create(:planting, crop: maize, garden: garden, owner: garden.owner) expect(garden.featured_plantings).to eq [@p2, @p1] end - it "should fetch most recent 4 featured plantings" do + it "fetches most recent 4 featured plantings" do @p1 = FactoryBot.create(:planting, crop: tomato, garden: garden, owner: garden.owner) @p2 = FactoryBot.create(:planting, crop: maize, garden: garden, owner: garden.owner) @p3 = FactoryBot.create(:planting, crop: chard, garden: garden, owner: garden.owner) @@ -80,7 +80,7 @@ describe Garden do expect(garden.featured_plantings).to eq [@p5, @p4, @p3, @p2] end - it "should skip repeated plantings" do + it "skips repeated plantings" do @p1 = FactoryBot.create(:planting, crop: tomato, garden: garden, owner: garden.owner) @p2 = FactoryBot.create(:planting, crop: maize, garden: garden, owner: garden.owner) @p3 = FactoryBot.create(:planting, crop: chard, garden: garden, owner: garden.owner) @@ -148,7 +148,7 @@ describe Garden do end end - it 'should refuse invalid unit values' do + it 'refuses invalid unit values' do garden = FactoryBot.build(:garden, area_unit: 'not valid') garden.should_not be_valid garden.errors[:area_unit].should include("not valid is not a valid area unit") diff --git a/spec/models/harvest_spec.rb b/spec/models/harvest_spec.rb index 9711d2a59..35cb9ba5f 100644 --- a/spec/models/harvest_spec.rb +++ b/spec/models/harvest_spec.rb @@ -52,7 +52,7 @@ describe Harvest do end end - it 'should refuse invalid unit values' do + it 'refuses invalid unit values' do @harvest = FactoryBot.build(:harvest, unit: 'not valid') @harvest.should_not be_valid @harvest.errors[:unit].should include("not valid is not a valid unit") @@ -105,7 +105,7 @@ describe Harvest do end end - it 'should refuse invalid weight unit values' do + it 'refuses invalid weight unit values' do @harvest = FactoryBot.build(:harvest, weight_unit: 'not valid') @harvest.should_not be_valid @harvest.errors[:weight_unit].should include("not valid is not a valid unit") @@ -223,23 +223,23 @@ describe Harvest do end context 'photos' do - before :each do + before do @harvest = FactoryBot.create(:harvest) end context 'without a photo' do - it 'should have no default photo' do + it 'has no default photo' do expect(@harvest.default_photo).to eq nil end context 'and with a crop(planting) photo' do - before :each do + before do @planting = FactoryBot.create(:planting, crop: @harvest.crop) @photo = FactoryBot.create(:photo, owner: @planting.owner) @planting.photos << @photo end - it 'should have a default photo' do + it 'has a default photo' do expect(@harvest.default_photo).to eq @photo end end @@ -270,19 +270,19 @@ describe Harvest do end context 'and with a crop(planting) photo' do - before :each do + before do @planting = FactoryBot.create(:planting, crop: @harvest.crop) @crop_photo = FactoryBot.create(:photo, owner: @planting.owner) @planting.photos << @crop_photo end - it 'should prefer the harvest photo' do + it 'prefers the harvest photo' do expect(@harvest.default_photo).to eq @photo end end context 'and a second photo' do - before :each do + before do @photo2 = FactoryBot.create(:photo, owner: @harvest.owner) @harvest.photos << @photo2 end diff --git a/spec/models/like_spec.rb b/spec/models/like_spec.rb index c92e3c389..6c47dcddb 100644 --- a/spec/models/like_spec.rb +++ b/spec/models/like_spec.rb @@ -5,7 +5,7 @@ describe 'like' do let(:post) { FactoryBot.create(:post) } context 'existing like' do - before(:each) do + before do @like = Like.create(member: member, likeable: post) end diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index e1b176378..0f015ae3f 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -6,6 +6,7 @@ describe 'member' do describe 'should be fetchable from the database' do subject { Member.find(member.id) } + it { is_expected.to be_an_instance_of Member } it { expect(subject.encrypted_password).not_to be_nil } end @@ -19,7 +20,7 @@ describe 'member' do expect(member.bio).to eq 'I love seeds' end - it 'should have a default garden' do + it 'has a default garden' do expect(member.gardens.count).to eq 1 end @@ -27,16 +28,16 @@ describe 'member' do expect(member.show_email).to eq false end - it 'should stringify as the login_name' do + it 'stringifies as the login_name' do expect(member.to_s).to eq 'hinemoa' end - it 'should be able to fetch posts' do + it 'is able to fetch posts' do post = FactoryBot.create(:post, author: member) expect(member.posts).to eq [post] end - it 'should be able to fetch gardens' do + it 'is able to fetch gardens' do expect(member.gardens.first.name).to eq "Garden" end @@ -92,7 +93,7 @@ describe 'member' do context 'no TOS agreement' do let(:member) { FactoryBot.build(:no_tos_member) } - it "should refuse to save a member who hasn't agreed to the TOS" do + it "refuses to save a member who hasn't agreed to the TOS" do member.save.should_not be(true) end end @@ -107,7 +108,7 @@ describe 'member' do end context 'same :login_name' do - it "should not allow two members with the same login_name" do + it "does not allow two members with the same login_name" do FactoryBot.create(:member, login_name: "bob") member = FactoryBot.build(:member, login_name: "bob") member.should_not be_valid @@ -199,7 +200,7 @@ describe 'member' do end context 'confirmed scope' do - before(:each) do + before do FactoryBot.create(:member) FactoryBot.create(:member) end @@ -251,7 +252,7 @@ describe 'member' do # 4) ordered by the most recent sign in context 'with a few members and plantings' do - before :each do + before do @members = [ :london_member, :london_member, :london_member, :unconfirmed_member, # !1 diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 66153709a..1ff33dccd 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -218,25 +218,25 @@ describe Planting do planting.location.should eq "#{garden_owner.login_name}'s #{garden.name}" end - it "should have a slug" do + it "has a slug" do planting.slug.should match(/^hatupatu-springfield-community-garden-tomato$/) end - it 'should sort in reverse creation order' do + it 'sorts in reverse creation order' do @planting2 = FactoryBot.create(:planting) Planting.first.should eq @planting2 end describe '#planted?' do - it "should be false for future plantings" do + it "is false for future plantings" do planting = FactoryBot.create :planting, planted_at: Time.zone.today + 1 expect(planting.planted?).to eq(false) end - it "should be false for never planted" do + it "is false for never planted" do planting = FactoryBot.create :planting, planted_at: nil expect(planting.planted?).to eq(false) end - it "should be true for past plantings" do + it "is true for past plantings" do planting = FactoryBot.create :planting, planted_at: Time.zone.today - 1 expect(planting.planted?).to eq(true) end @@ -287,7 +287,7 @@ describe Planting do context 'sunniness' do let(:planting) { FactoryBot.create(:sunny_planting) } - it 'should have a sunniness value' do + it 'has a sunniness value' do planting.sunniness.should eq 'sun' end @@ -298,7 +298,7 @@ describe Planting do end end - it 'should refuse invalid sunniness values' do + it 'refuses invalid sunniness values' do @planting = FactoryBot.build(:planting, sunniness: 'not valid') @planting.should_not be_valid @planting.errors[:sunniness].should include("not valid is not a valid sunniness value") @@ -306,7 +306,7 @@ describe Planting do end context 'planted from' do - it 'should have a planted_from value' do + it 'has a planted_from value' do @planting = FactoryBot.create(:seed_planting) @planting.planted_from.should eq 'seed' end @@ -320,7 +320,7 @@ describe Planting do end end - it 'should refuse invalid planted_from values' do + it 'refuses invalid planted_from values' do @planting = FactoryBot.build(:planting, planted_from: 'not valid') @planting.should_not be_valid @planting.errors[:planted_from].should include("not valid is not a valid planting method") @@ -332,6 +332,7 @@ describe Planting do context 'photos' do let(:planting) { FactoryBot.create(:planting) } let(:photo) { FactoryBot.create(:photo, owner_id: planting.owner_id) } + before { planting.photos << photo } it 'has a photo' do diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index eeda089d2..7d79a62a7 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -2,9 +2,10 @@ require 'rails_helper' describe Post do let(:member) { FactoryBot.create(:member, login_name: 'whinacooper') } + it_behaves_like "it is likeable" - it "should have a slug" do + it "has a slug" do post = FactoryBot.create(:post, author: member) time = post.created_at datestr = time.strftime("%Y%m%d") @@ -135,16 +136,16 @@ describe Post do let!(:chard) { FactoryBot.create(:chard) } let!(:post) { FactoryBot.create(:post, body: "[maize](crop)[tomato](crop)[tomato](crop)") } - it "should be generated" do + it "is generated" do expect(tomato.posts).to eq [post] expect(maize.posts).to eq [post] end - it "should not duplicate" do + it "does not duplicate" do expect(post.crops) =~ [tomato, maize] end - it "should be updated when post was modified" do + it "is updated when post was modified" do post.update(body: "[chard](crop)") expect(post.crops).to eq [chard] @@ -158,12 +159,12 @@ describe Post do post.destroy end - it "should delete the association" do + it "deletes the association" do expect(Crop.find(tomato.id).posts).to eq [] expect(Crop.find(maize.id).posts).to eq [] end - it "should not delete the crops" do + it "does not delete the crops" do expect(Crop.find(tomato.id)).not_to eq nil expect(Crop.find(maize.id)).not_to eq nil end diff --git a/spec/models/scientific_name_spec.rb b/spec/models/scientific_name_spec.rb index 872ea6766..0b170812d 100644 --- a/spec/models/scientific_name_spec.rb +++ b/spec/models/scientific_name_spec.rb @@ -4,11 +4,11 @@ describe ScientificName do context 'all fields present' do let(:sn) { FactoryBot.create(:zea_mays) } - it 'should save a basic scientific name' do + it 'saves a basic scientific name' do sn.save.should be(true) end - it 'should be fetchable from the database' do + it 'is fetchable from the database' do sn.save @sn2 = ScientificName.find_by(name: 'Zea mays') @sn2.crop.name.should == 'maize' @@ -21,7 +21,7 @@ describe ScientificName do end context 'invalid data' do - it 'should not save a scientific name without a name' do + it 'does not save a scientific name without a name' do sn = ScientificName.new expect { sn.save! }.to raise_error ActiveRecord::RecordInvalid end diff --git a/spec/models/seed_spec.rb b/spec/models/seed_spec.rb index d71fbeda7..5991d336b 100644 --- a/spec/models/seed_spec.rb +++ b/spec/models/seed_spec.rb @@ -4,11 +4,11 @@ describe Seed do let(:owner) { FactoryBot.create :owner, login_name: 'tamateapokaiwhenua' } let(:seed) { FactoryBot.build(:seed, owner: owner) } - it 'should save a basic seed' do + it 'saves a basic seed' do seed.save.should be(true) end - it "should have a slug" do + it "has a slug" do seed.save seed.slug.should match(/tamateapokaiwhenua-magic-bean/) end @@ -45,7 +45,7 @@ describe Seed do end end - it 'should refuse invalid tradable_to values' do + it 'refuses invalid tradable_to values' do @seed = FactoryBot.build(:seed, tradable_to: 'not valid') @seed.should_not be_valid @seed.errors[:tradable_to].should include( @@ -54,7 +54,7 @@ describe Seed do ) end - it 'should not allow nil or blank values' do + it 'does not allow nil or blank values' do @seed = FactoryBot.build(:seed, tradable_to: nil) @seed.should_not be_valid @seed = FactoryBot.build(:seed, tradable_to: '') @@ -112,7 +112,7 @@ describe Seed do end end - it 'should refuse invalid organic/GMO/heirloom values' do + it 'refuses invalid organic/GMO/heirloom values' do %i(organic gmo heirloom).each do |field| @seed = FactoryBot.build(:seed, field => 'not valid') @seed.should_not be_valid @@ -120,7 +120,7 @@ describe Seed do end end - it 'should not allow nil or blank values' do + it 'does not allow nil or blank values' do %i(organic gmo heirloom).each do |field| @seed = FactoryBot.build(:seed, field => nil) @seed.should_not be_valid @@ -154,6 +154,7 @@ describe Seed do let(:seed) { FactoryBot.create :seed } before { seed.photos << FactoryBot.create(:photo, owner: seed.owner) } + it 'is found in has_photos scope' do Seed.has_photos.should include(seed) end @@ -162,6 +163,7 @@ describe Seed do context 'ancestry' do let(:parent_planting) { FactoryBot.create :planting } let(:seed) { FactoryBot.create :seed, parent_planting: parent_planting, owner: parent_planting.owner } + it "seed has a parent planting" do expect(seed.parent_planting).to eq(parent_planting) end diff --git a/spec/requests/api/v1/crop_request_spec.rb b/spec/requests/api/v1/crop_request_spec.rb index 7d026d9ec..662b27c46 100644 --- a/spec/requests/api/v1/crop_request_spec.rb +++ b/spec/requests/api/v1/crop_request_spec.rb @@ -65,11 +65,13 @@ RSpec.describe 'Plantings', type: :request do describe '#index' do before { get '/api/v1/crops', params: {}, headers: headers } + it { expect(subject['data']).to include(crop_encoded_as_json_api) } end describe '#show' do before { get "/api/v1/crops/#{crop.id}", params: {}, headers: headers } + it { expect(subject['data']['attributes']).to eq(attributes) } it { expect(subject['data']['relationships']).to include("plantings" => plantings_as_json_api) } it { expect(subject['data']['relationships']).to include("harvests" => harvests_as_json_api) } diff --git a/spec/requests/api/v1/harvest_request_spec.rb b/spec/requests/api/v1/harvest_request_spec.rb index c4fddd350..5b1c9b0a8 100644 --- a/spec/requests/api/v1/harvest_request_spec.rb +++ b/spec/requests/api/v1/harvest_request_spec.rb @@ -59,11 +59,13 @@ RSpec.describe 'Harvests', type: :request do describe '#index' do before { get '/api/v1/harvests', params: {}, headers: headers } + it { expect(subject['data']).to include(harvest_encoded_as_json_api) } end describe '#show' do before { get "/api/v1/harvests/#{harvest.id}", params: {}, headers: headers } + it { expect(subject['data']['attributes']).to eq(attributes) } it { expect(subject['data']['relationships']).to include("planting" => planting_as_json_api) } it { expect(subject['data']['relationships']).to include("crop" => crop_as_json_api) } diff --git a/spec/requests/api/v1/member_request_spec.rb b/spec/requests/api/v1/member_request_spec.rb index f44b2a4ae..9178f91cc 100644 --- a/spec/requests/api/v1/member_request_spec.rb +++ b/spec/requests/api/v1/member_request_spec.rb @@ -59,11 +59,13 @@ RSpec.describe 'Members', type: :request do describe '#index' do before { get '/api/v1/members', params: {}, headers: headers } + it { expect(subject['data']).to include(member_encoded_as_json_api) } end describe '#show' do before { get "/api/v1/members/#{member.id}", params: {}, headers: headers } + it { expect(subject['data']['relationships']).to include("gardens" => gardens_as_json_api) } it { expect(subject['data']['relationships']).to include("plantings" => plantings_as_json_api) } it { expect(subject['data']['relationships']).to include("seeds" => seeds_as_json_api) } diff --git a/spec/requests/api/v1/photos_request_spec.rb b/spec/requests/api/v1/photos_request_spec.rb index 15fb8cd19..833e5499c 100644 --- a/spec/requests/api/v1/photos_request_spec.rb +++ b/spec/requests/api/v1/photos_request_spec.rb @@ -57,11 +57,13 @@ RSpec.describe 'Photos', type: :request do describe '#index' do before { get '/api/v1/photos', params: {}, headers: headers } + it { expect(subject['data']).to include(photo_encoded_as_json_api) } end describe '#show' do before { get "/api/v1/photos/#{photo.id}", params: {}, headers: headers } + it { expect(subject['data']['attributes']).to eq(attributes) } it { expect(subject['data']['relationships']).to include("plantings" => plantings_as_json_api) } it { expect(subject['data']['relationships']).to include("harvests" => harvests_as_json_api) } diff --git a/spec/requests/api/v1/plantings_request_spec.rb b/spec/requests/api/v1/plantings_request_spec.rb index 0291af4b2..0a9ca54dc 100644 --- a/spec/requests/api/v1/plantings_request_spec.rb +++ b/spec/requests/api/v1/plantings_request_spec.rb @@ -53,18 +53,21 @@ RSpec.describe 'Plantings', type: :request do let(:attributes) do { + "slug" => planting.slug, "planted-at" => "2014-07-30", "finished-at" => nil, "finished" => false, "quantity" => 33, "description" => planting.description, + "crop-name" => planting.crop.name, "sunniness" => nil, "planted-from" => nil, "expected-lifespan" => nil, "finish-predicted-at" => nil, "percentage-grown" => nil, "first-harvest-date" => nil, - "last-harvest-date" => nil + "last-harvest-date" => nil, + "thumbnail" => nil } end diff --git a/spec/requests/api/v1/seeds_request_spec.rb b/spec/requests/api/v1/seeds_request_spec.rb index 909d08864..000d55e14 100644 --- a/spec/requests/api/v1/seeds_request_spec.rb +++ b/spec/requests/api/v1/seeds_request_spec.rb @@ -46,11 +46,13 @@ RSpec.describe 'Photos', type: :request do describe '#index' do before { get '/api/v1/seeds', params: {}, headers: headers } + it { expect(subject['data']).to include(seed_encoded_as_json_api) } end describe '#show' do before { get "/api/v1/seeds/#{seed.id}", params: {}, headers: headers } + it { expect(subject['data']['attributes']).to eq(attributes) } it { expect(subject['data']['relationships']).to include("owner" => owner_as_json_api) } it { expect(subject['data']['relationships']).to include("crop" => crop_as_json_api) } diff --git a/spec/support/controller_macros.rb b/spec/support/controller_macros.rb index 354c64069..b54cf0282 100644 --- a/spec/support/controller_macros.rb +++ b/spec/support/controller_macros.rb @@ -2,7 +2,7 @@ module ControllerMacros def login_member(member_factory = :member) let(:member) { FactoryBot.create(member_factory || :member) } - before(:each) do + before do @request.env["devise.mapping"] = Devise.mappings[:member] sign_in member end diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index e0dbc9aa8..720a47032 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -3,7 +3,7 @@ RSpec.configure do |config| DatabaseCleaner.clean_with(:truncation) end - config.before(:each) do + config.before do DatabaseCleaner.strategy = :transaction end @@ -11,11 +11,11 @@ RSpec.configure do |config| DatabaseCleaner.strategy = :truncation end - config.before(:each) do + config.before do DatabaseCleaner.start end - config.after(:each) do + config.after do DatabaseCleaner.clean end end diff --git a/spec/support/is_likeable.rb b/spec/support/is_likeable.rb index e1a590b30..c402d589c 100644 --- a/spec/support/is_likeable.rb +++ b/spec/support/is_likeable.rb @@ -1,5 +1,5 @@ shared_examples "it is likeable" do - before(:each) do + before do # Possibly a horrible hack. # Will fail if factory name does not match the model name.. @likeable = FactoryBot.create(described_class.to_s.underscore.to_sym) @@ -17,7 +17,7 @@ shared_examples "it is likeable" do expect(@likeable.members.length).to eq 2 end - it 'should destroy the like when it is destroyed' do + it 'destroys the like when it is destroyed' do like_count = -1 * @likeable.likes.count expect { @likeable.destroy }.to change(Like, :count).by like_count end diff --git a/spec/views/admin/index_spec.rb b/spec/views/admin/index_spec.rb index cc8b145d3..7e8c27fdc 100644 --- a/spec/views/admin/index_spec.rb +++ b/spec/views/admin/index_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'admin/index.html.haml', type: "view" do - before(:each) do + before do @member = FactoryBot.create(:admin_member) sign_in @member controller.stub(:current_user) { @member } diff --git a/spec/views/admin/newsletter_spec.rb b/spec/views/admin/newsletter_spec.rb index 384833034..4807aaa8e 100644 --- a/spec/views/admin/newsletter_spec.rb +++ b/spec/views/admin/newsletter_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'admin/newsletter.html.haml', type: "view" do - before(:each) do + before do @member = FactoryBot.create(:admin_member) sign_in @member controller.stub(:current_user) { @member } diff --git a/spec/views/comments/edit.html.haml_spec.rb b/spec/views/comments/edit.html.haml_spec.rb index 2ef7d480f..b7a547f8c 100644 --- a/spec/views/comments/edit.html.haml_spec.rb +++ b/spec/views/comments/edit.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "comments/edit" do - before(:each) do + before do controller.stub(:current_user) { nil } assign(:comment, FactoryBot.create(:comment)) end diff --git a/spec/views/comments/index.html.haml_spec.rb b/spec/views/comments/index.html.haml_spec.rb index 91ed15a88..b9e577562 100644 --- a/spec/views/comments/index.html.haml_spec.rb +++ b/spec/views/comments/index.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "comments/index" do - before(:each) do + before do controller.stub(:current_user) { nil } page = 1 per_page = 2 diff --git a/spec/views/comments/index.rss.haml_spec.rb b/spec/views/comments/index.rss.haml_spec.rb index 672658bac..d1b376cab 100644 --- a/spec/views/comments/index.rss.haml_spec.rb +++ b/spec/views/comments/index.rss.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'comments/index.rss.haml' do - before(:each) do + before do controller.stub(:current_user) { nil } @author = FactoryBot.create(:member) @post = FactoryBot.create(:post) diff --git a/spec/views/comments/new.html.haml_spec.rb b/spec/views/comments/new.html.haml_spec.rb index e0533ea5b..cc6638936 100644 --- a/spec/views/comments/new.html.haml_spec.rb +++ b/spec/views/comments/new.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "comments/new" do - before(:each) do + before do controller.stub(:current_user) { nil } @post = FactoryBot.create(:post) @comment = FactoryBot.create(:comment, post: @post) diff --git a/spec/views/comments/show.html.haml_spec.rb b/spec/views/comments/show.html.haml_spec.rb index 6315b4f69..32a524d65 100644 --- a/spec/views/comments/show.html.haml_spec.rb +++ b/spec/views/comments/show.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "comments/show" do - before(:each) do + before do controller.stub(:current_user) { nil } @comment = assign(:comment, FactoryBot.create(:comment)) render diff --git a/spec/views/crops/_planting_advice.html.haml_spec.rb b/spec/views/crops/_planting_advice.html.haml_spec.rb index f5adc5b29..7335fd127 100644 --- a/spec/views/crops/_planting_advice.html.haml_spec.rb +++ b/spec/views/crops/_planting_advice.html.haml_spec.rb @@ -5,7 +5,7 @@ describe "crops/_planting_advice" do let(:planting) { FactoryBot.create(:planting) } - shared_examples "render planting_advice" do + shared_context "render planting_advice" do before { render 'crops/planting_advice', crop: planting.crop } end diff --git a/spec/views/crops/_popover.html.haml_spec.rb b/spec/views/crops/_popover.html.haml_spec.rb index dde4a893f..577667eca 100644 --- a/spec/views/crops/_popover.html.haml_spec.rb +++ b/spec/views/crops/_popover.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "crops/_popover" do - before(:each) do + before do @tomato = FactoryBot.create(:tomato) @sn = FactoryBot.create(:solanum_lycopersicum, crop: @tomato) @planting = FactoryBot.create(:planting, crop: @tomato) diff --git a/spec/views/crops/edit.html.haml_spec.rb b/spec/views/crops/edit.html.haml_spec.rb index f0d8e9251..ba43f645f 100644 --- a/spec/views/crops/edit.html.haml_spec.rb +++ b/spec/views/crops/edit.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "crops/edit" do - before(:each) do + before do controller.stub(:current_user) do FactoryBot.create(:crop_wrangling_member) end diff --git a/spec/views/crops/hierarchy.html.haml_spec.rb b/spec/views/crops/hierarchy.html.haml_spec.rb index 833bb2b98..c1d79f0bb 100644 --- a/spec/views/crops/hierarchy.html.haml_spec.rb +++ b/spec/views/crops/hierarchy.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "crops/hierarchy" do - before(:each) do + before do controller.stub(:current_user) { nil } @tomato = FactoryBot.create(:tomato) @roma = FactoryBot.create(:crop, name: 'Roma tomato', parent: @tomato) diff --git a/spec/views/crops/index.html.haml_spec.rb b/spec/views/crops/index.html.haml_spec.rb index 7d05d18db..7d86653de 100644 --- a/spec/views/crops/index.html.haml_spec.rb +++ b/spec/views/crops/index.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "crops/index" do - before(:each) do + before do controller.stub(:current_user) { nil } page = 1 per_page = 2 @@ -29,7 +29,7 @@ describe "crops/index" do end context "logged in and crop wrangler" do - before(:each) do + before do @member = FactoryBot.create(:crop_wrangling_member) sign_in @member controller.stub(:current_user) { @member } diff --git a/spec/views/crops/index.rss.haml_spec.rb b/spec/views/crops/index.rss.haml_spec.rb index 72a8bbdff..a7afbba7a 100644 --- a/spec/views/crops/index.rss.haml_spec.rb +++ b/spec/views/crops/index.rss.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'crops/index.rss.haml' do - before(:each) do + before do controller.stub(:current_user) { nil } @author = FactoryBot.create(:member) @tomato = FactoryBot.create(:tomato) diff --git a/spec/views/crops/new.html.haml_spec.rb b/spec/views/crops/new.html.haml_spec.rb index 5ce7eefdc..0dcf43624 100644 --- a/spec/views/crops/new.html.haml_spec.rb +++ b/spec/views/crops/new.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "crops/new" do - before(:each) do + before do @crop = FactoryBot.create(:maize) 3.times do @crop.scientific_names.build diff --git a/spec/views/crops/wrangle.html.haml_spec.rb b/spec/views/crops/wrangle.html.haml_spec.rb index 085060570..8b9814140 100644 --- a/spec/views/crops/wrangle.html.haml_spec.rb +++ b/spec/views/crops/wrangle.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "crops/wrangle" do - before(:each) do + before do @member = FactoryBot.create(:crop_wrangling_member) controller.stub(:current_user) { @member } page = 1 diff --git a/spec/views/devise/confirmations/new_spec.rb b/spec/views/devise/confirmations/new_spec.rb index 720822083..de26a4ad8 100644 --- a/spec/views/devise/confirmations/new_spec.rb +++ b/spec/views/devise/confirmations/new_spec.rb @@ -1,5 +1,5 @@ describe 'devise/confirmations/new.html.haml', type: "view" do - before(:each) do + before do @view.stub(:resource).and_return(Member.new) @view.stub(:resource_name).and_return("member") @view.stub(:resource_class).and_return(Member) @@ -7,7 +7,7 @@ describe 'devise/confirmations/new.html.haml', type: "view" do render end - it 'should contain a login field' do + it 'contains a login field' do rendered.should have_content "Enter either your login name or your email address" end end diff --git a/spec/views/devise/mailer/confirmation_instructions_spec.rb b/spec/views/devise/mailer/confirmation_instructions_spec.rb index d2cce98c4..08e411796 100644 --- a/spec/views/devise/mailer/confirmation_instructions_spec.rb +++ b/spec/views/devise/mailer/confirmation_instructions_spec.rb @@ -2,16 +2,16 @@ require 'rails_helper' describe 'devise/mailer/confirmation_instructions.html.haml', type: "view" do context "logged in" do - before(:each) do + before do @resource = FactoryBot.create(:member) render end - it 'should have a confirmation link' do + it 'has a confirmation link' do rendered.should have_content 'Confirm my account' end - it 'should have a link to the homepage' do + it 'has a link to the homepage' do rendered.should have_content root_url end end diff --git a/spec/views/devise/mailer/reset_password_instructions_spec.rb b/spec/views/devise/mailer/reset_password_instructions_spec.rb index fc2ad1bbe..ef90f7589 100644 --- a/spec/views/devise/mailer/reset_password_instructions_spec.rb +++ b/spec/views/devise/mailer/reset_password_instructions_spec.rb @@ -2,14 +2,14 @@ require 'rails_helper' describe 'devise/mailer/reset_password_instructions.html.haml', type: "view" do context "logged in" do - before(:each) do + before do @resource = mock_model(Member) @resource.stub(:email).and_return("example@example.com") @resource.stub(:reset_password_token).and_return("joe") render end - it 'should have some of the right text' do + it 'has some of the right text' do rendered.should have_content 'Change my password' rendered.should have_content 'Someone has requested a link to reset your password' end diff --git a/spec/views/devise/mailer/unlock_instructions_spec.rb b/spec/views/devise/mailer/unlock_instructions_spec.rb index 633545cf3..d3ac3357d 100644 --- a/spec/views/devise/mailer/unlock_instructions_spec.rb +++ b/spec/views/devise/mailer/unlock_instructions_spec.rb @@ -1,16 +1,16 @@ require 'rails_helper' describe 'devise/mailer/unlock_instructions.html.haml', type: "view" do context "logged in" do - before(:each) do + before do @resource = FactoryBot.create(:member) render end - it "should explain what's happened" do + it "explains what's happened" do rendered.should have_content "account has been locked" end - it "should have an unlock link" do + it "has an unlock link" do rendered.should have_content "Unlock my account" end end diff --git a/spec/views/devise/registrations/edit_spec.rb b/spec/views/devise/registrations/edit_spec.rb index 85ee6588a..b260d13a8 100644 --- a/spec/views/devise/registrations/edit_spec.rb +++ b/spec/views/devise/registrations/edit_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe 'devise/registrations/edit.html.haml', type: "view" do context "logged in" do - before(:each) do + before do controller.stub(:current_user) { nil } @member = FactoryBot.create(:member) controller.stub(:current_member) { @member } @@ -12,13 +12,13 @@ describe 'devise/registrations/edit.html.haml', type: "view" do @view.stub(:devise_mapping).and_return(Devise.mappings[:member]) end - it 'should have some fields' do + it 'has some fields' do render rendered.should have_content 'Email' end context 'email section' do - before(:each) do + before do render end @@ -32,7 +32,7 @@ describe 'devise/registrations/edit.html.haml', type: "view" do end context 'profile section' do - before(:each) do + before do render end @@ -66,7 +66,7 @@ describe 'devise/registrations/edit.html.haml', type: "view" do end context 'connected to twitter' do - before(:each) do + before do @twitter_auth = FactoryBot.create(:authentication, member: @member) render end @@ -88,7 +88,7 @@ describe 'devise/registrations/edit.html.haml', type: "view" do end context 'connected to flickr' do - before(:each) do + before do @flickr_auth = FactoryBot.create(:flickr_authentication, member: @member) render end diff --git a/spec/views/devise/registrations/new_spec.rb b/spec/views/devise/registrations/new_spec.rb index 48805b806..0ee95b5b0 100644 --- a/spec/views/devise/registrations/new_spec.rb +++ b/spec/views/devise/registrations/new_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe 'devise/registrations/new.html.haml', type: "view" do context "logged in" do - before(:each) do + before do @view.stub(:resource).and_return(Member.new) @view.stub(:resource_name).and_return("member") @view.stub(:resource_class).and_return(Member) @@ -10,7 +10,7 @@ describe 'devise/registrations/new.html.haml', type: "view" do render end - it 'should have some fields' do + it 'has some fields' do rendered.should have_content 'Email' end diff --git a/spec/views/devise/sessions/new_spec.rb b/spec/views/devise/sessions/new_spec.rb index dfe91af2a..d8ae1c480 100644 --- a/spec/views/devise/sessions/new_spec.rb +++ b/spec/views/devise/sessions/new_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe 'devise/sessions/new.html.haml', type: "view" do context "logged in" do - before(:each) do + before do @view.stub(:resource).and_return(Member.new) @view.stub(:resource_name).and_return("member") @view.stub(:resource_class).and_return(Member) @@ -10,7 +10,7 @@ describe 'devise/sessions/new.html.haml', type: "view" do render end - it 'should have some fields' do + it 'has some fields' do rendered.should have_content 'Remember me' rendered.should have_content 'Password' end diff --git a/spec/views/devise/shared/_links_spec.rb b/spec/views/devise/shared/_links_spec.rb index 39147113f..c19101593 100644 --- a/spec/views/devise/shared/_links_spec.rb +++ b/spec/views/devise/shared/_links_spec.rb @@ -9,14 +9,14 @@ describe 'devise/shared/_links.haml', type: "view" do dm end - it 'should have a sign-in link if not in sessions' do + it 'has a sign-in link if not in sessions' do @view.stub(:controller_name).and_return("anything but sessions") @view.stub(:resource_name).and_return("member") @view.stub(devise_mapping: devise_mapping(false, false, false, false, false)) render end - it "shouldn't have a sign-in link if in sessions" do + it "does not have a sign-in link if in sessions" do @view.stub(:controller_name).and_return("sessions") @view.stub(:resource_name).and_return("member") @view.stub(devise_mapping: devise_mapping(false, false, false, false, false)) diff --git a/spec/views/devise/unlocks/new_spec.rb b/spec/views/devise/unlocks/new_spec.rb index 60d056d72..ba1e11215 100644 --- a/spec/views/devise/unlocks/new_spec.rb +++ b/spec/views/devise/unlocks/new_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe 'devise/unlocks/new.html.haml', type: "view" do context "logged in" do - before(:each) do + before do @view.stub(:resource).and_return(Member.new) @view.stub(:resource_name).and_return("member") @view.stub(:resource_class).and_return(Member) @@ -10,7 +10,7 @@ describe 'devise/unlocks/new.html.haml', type: "view" do render end - it 'should have some fields' do + it 'has some fields' do rendered.should have_content 'Email' end end diff --git a/spec/views/forums/edit.html.haml_spec.rb b/spec/views/forums/edit.html.haml_spec.rb index 77f5cff31..1782bb7b7 100644 --- a/spec/views/forums/edit.html.haml_spec.rb +++ b/spec/views/forums/edit.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "forums/edit" do - before(:each) do + before do @forum = assign(:forum, stub_model(Forum, name: "MyString", description: "MyText", diff --git a/spec/views/forums/index.html.haml_spec.rb b/spec/views/forums/index.html.haml_spec.rb index 02b265e85..7307501fe 100644 --- a/spec/views/forums/index.html.haml_spec.rb +++ b/spec/views/forums/index.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "forums/index" do - before(:each) do + before do @admin = FactoryBot.create(:admin_member) controller.stub(:current_user) { @admin } @forum1 = FactoryBot.create(:forum) @@ -20,7 +20,7 @@ describe "forums/index" do end context "posts" do - before(:each) do + before do @post = FactoryBot.create(:forum_post, forum: @forum1) @comment = FactoryBot.create(:comment, post: @post) render diff --git a/spec/views/forums/new.html.haml_spec.rb b/spec/views/forums/new.html.haml_spec.rb index 72cd7ae45..4fec098df 100644 --- a/spec/views/forums/new.html.haml_spec.rb +++ b/spec/views/forums/new.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "forums/new" do - before(:each) do + before do @forum = assign(:forum, FactoryBot.create(:forum)) render end diff --git a/spec/views/forums/show.html.haml_spec.rb b/spec/views/forums/show.html.haml_spec.rb index 08892df58..c40a77a81 100644 --- a/spec/views/forums/show.html.haml_spec.rb +++ b/spec/views/forums/show.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "forums/show" do - before(:each) do + before do controller.stub(:current_user) { nil } @forum = assign(:forum, FactoryBot.create(:forum)) end diff --git a/spec/views/gardens/edit.html.haml_spec.rb b/spec/views/gardens/edit.html.haml_spec.rb index 1326f1544..a0564bf84 100644 --- a/spec/views/gardens/edit.html.haml_spec.rb +++ b/spec/views/gardens/edit.html.haml_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe "gardens/edit" do context "logged in" do - before(:each) do + before do @owner = FactoryBot.create(:member) sign_in @owner controller.stub(:current_user) { @owner } diff --git a/spec/views/gardens/new.html.haml_spec.rb b/spec/views/gardens/new.html.haml_spec.rb index 7346997dc..d76659f73 100644 --- a/spec/views/gardens/new.html.haml_spec.rb +++ b/spec/views/gardens/new.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "gardens/new" do - before(:each) do + before do @member = FactoryBot.create(:member) sign_in @member controller.stub(:current_user) { @member } diff --git a/spec/views/gardens/show.html.haml_spec.rb b/spec/views/gardens/show.html.haml_spec.rb index 7451f26c8..5fee8fc4e 100644 --- a/spec/views/gardens/show.html.haml_spec.rb +++ b/spec/views/gardens/show.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "gardens/show" do - before(:each) do + before do @owner = FactoryBot.create(:member) controller.stub(:current_user) { @owner } @garden = FactoryBot.create(:garden, owner: @owner) diff --git a/spec/views/harvests/edit.html.haml_spec.rb b/spec/views/harvests/edit.html.haml_spec.rb index 1193b4284..90df77ebe 100644 --- a/spec/views/harvests/edit.html.haml_spec.rb +++ b/spec/views/harvests/edit.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "harvests/edit" do - before(:each) do + before do assign(:harvest, FactoryBot.create(:harvest)) render end diff --git a/spec/views/harvests/index.html.haml_spec.rb b/spec/views/harvests/index.html.haml_spec.rb index b5ebcfb67..461749f0b 100644 --- a/spec/views/harvests/index.html.haml_spec.rb +++ b/spec/views/harvests/index.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "harvests/index" do - before(:each) do + before do controller.stub(:current_user) { nil } @member = FactoryBot.create(:member) @tomato = FactoryBot.create(:tomato) diff --git a/spec/views/harvests/index.rss.haml_spec.rb b/spec/views/harvests/index.rss.haml_spec.rb index b0898cf78..3bb73bca1 100644 --- a/spec/views/harvests/index.rss.haml_spec.rb +++ b/spec/views/harvests/index.rss.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'harvests/index.rss.haml' do - before(:each) do + before do controller.stub(:current_user) { nil } @member = FactoryBot.create(:member) @tomato = FactoryBot.create(:tomato) diff --git a/spec/views/harvests/new.html.haml_spec.rb b/spec/views/harvests/new.html.haml_spec.rb index d79055a38..ee8e80a74 100644 --- a/spec/views/harvests/new.html.haml_spec.rb +++ b/spec/views/harvests/new.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "harvests/new" do - before(:each) do + before do assign(:harvest, FactoryBot.create(:harvest)) render end diff --git a/spec/views/home/_blurb.html.haml_spec.rb b/spec/views/home/_blurb.html.haml_spec.rb index 47244a445..395ce74b0 100644 --- a/spec/views/home/_blurb.html.haml_spec.rb +++ b/spec/views/home/_blurb.html.haml_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe 'home/_blurb.html.haml', type: "view" do context 'signed out' do - before :each do + before do controller.stub(:current_user) { nil } render end diff --git a/spec/views/home/_members.html.haml_spec.rb b/spec/views/home/_members.html.haml_spec.rb index 76aa434b6..946622d56 100644 --- a/spec/views/home/_members.html.haml_spec.rb +++ b/spec/views/home/_members.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'home/_members.html.haml', type: "view" do - before(:each) do + before do @member = FactoryBot.create(:london_member) @member.updated_at = 2.days.ago assign(:members, [@member]) diff --git a/spec/views/home/_seeds.html.haml_spec.rb b/spec/views/home/_seeds.html.haml_spec.rb index 7b8d6156c..baacfc37e 100644 --- a/spec/views/home/_seeds.html.haml_spec.rb +++ b/spec/views/home/_seeds.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'home/_seeds.html.haml', type: "view" do - before(:each) do + before do @owner = FactoryBot.create(:london_member) @seed = FactoryBot.create(:tradable_seed, owner: @owner) render diff --git a/spec/views/home/index_spec.rb b/spec/views/home/index_spec.rb index 4bc1e9c10..61f40d3f1 100644 --- a/spec/views/home/index_spec.rb +++ b/spec/views/home/index_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'home/index.html.haml', type: "view" do - before(:each) do + before do @member = FactoryBot.create(:london_member) @member.updated_at = 2.days.ago assign(:interesting_members, [@member]) @@ -19,7 +19,7 @@ describe 'home/index.html.haml', type: "view" do end context 'logged out' do - before(:each) do + before do controller.stub(:current_user) { nil } render end @@ -31,7 +31,7 @@ describe 'home/index.html.haml', type: "view" do end context 'signed in' do - before(:each) do + before do sign_in @member controller.stub(:current_user) { @member } render diff --git a/spec/views/layouts/_header_spec.rb b/spec/views/layouts/_header_spec.rb index 58509f589..f4521ee88 100644 --- a/spec/views/layouts/_header_spec.rb +++ b/spec/views/layouts/_header_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe 'layouts/_header.html.haml', type: "view" do context "when not logged in" do - before(:each) do + before do controller.stub(:current_user) { nil } render end @@ -11,7 +11,7 @@ describe 'layouts/_header.html.haml', type: "view" do assert_select("a.navbar-brand img[src]", href: root_path) end - it 'should have signup/signin links' do + it 'has signup/signin links' do rendered.should have_content 'Sign up' rendered.should have_content 'Sign in' end @@ -51,7 +51,7 @@ describe 'layouts/_header.html.haml', type: "view" do end context "logged in" do - before(:each) do + before do @member = FactoryBot.create(:member) sign_in @member controller.stub(:current_user) { @member } @@ -59,34 +59,34 @@ describe 'layouts/_header.html.haml', type: "view" do end context "login name" do - it 'should have member login name' do + it 'has member login name' do rendered.should have_content @member.login_name.to_s end - it "should show link to member's gardens" do + it "shows link to member's gardens" do assert_select("a[href='#{member_gardens_path(@member)}']", "Gardens") end - it "should show link to member's plantings" do + it "shows link to member's plantings" do assert_select("a[href='#{member_plantings_path(@member)}']", "Plantings") end - it "should show link to member's seeds" do + it "shows link to member's seeds" do assert_select("a[href='#{member_seeds_path(@member)}']", "Seeds") end - it "should show link to member's posts" do + it "shows link to member's posts" do assert_select("a[href='#{member_posts_path(@member)}']", "Posts") end end - it 'should show signout link' do + it 'shows signout link' do rendered.should have_content 'Sign out' end - it 'should show inbox link' do + it 'shows inbox link' do rendered.should have_content 'Inbox' rendered.should_not match(/Inbox \(\d+\)/) end context 'has notifications' do - it 'should show inbox count' do + it 'shows inbox count' do FactoryBot.create(:notification, recipient: @member) render rendered.should have_content 'Inbox (1)' diff --git a/spec/views/layouts/_meta_spec.rb b/spec/views/layouts/_meta_spec.rb index 151c6fe19..2f729083e 100644 --- a/spec/views/layouts/_meta_spec.rb +++ b/spec/views/layouts/_meta_spec.rb @@ -1,26 +1,26 @@ require 'rails_helper' describe 'layouts/_meta.html.haml', type: "view" do - before(:each) do + before do render end - it 'should have a Posts RSS feed' do + it 'has a Posts RSS feed' do posts_rss = url_for(controller: 'posts', format: 'rss', only_path: false) assert_select "head>link[href='#{posts_rss}']" end - it 'should have a Crops RSS feed' do + it 'has a Crops RSS feed' do crops_rss = url_for(controller: 'crops', format: 'rss', only_path: false) assert_select "head>link[href='#{crops_rss}']" end - it 'should have a Plantings RSS feed' do + it 'has a Plantings RSS feed' do plantings_rss = url_for(controller: 'plantings', format: 'rss', only_path: false) assert_select "head>link[href='#{plantings_rss}']" end - it 'should have a title' do + it 'has a title' do assert_select "head>title" end end diff --git a/spec/views/layouts/application_spec.rb b/spec/views/layouts/application_spec.rb index e706bc575..49d6d70f4 100644 --- a/spec/views/layouts/application_spec.rb +++ b/spec/views/layouts/application_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'layouts/application.html.haml', type: "view" do - before(:each) do + before do controller.stub(:current_user) { nil } end diff --git a/spec/views/members/_location.html.haml_spec.rb b/spec/views/members/_location.html.haml_spec.rb index 50d7b675f..db1fae09c 100644 --- a/spec/views/members/_location.html.haml_spec.rb +++ b/spec/views/members/_location.html.haml_spec.rb @@ -4,7 +4,7 @@ describe "members/_location" do context "member with location" do let(:member) { FactoryBot.create(:london_member) } - before(:each) { render partial: 'members/location', locals: { member: member } } + before { render partial: 'members/location', locals: { member: member } } it 'shows location if available' do expect(rendered).to have_content member.location @@ -16,7 +16,7 @@ describe "members/_location" do end context "member with no location" do - before(:each) do + before do member = FactoryBot.create(:member) render partial: 'members/location', locals: { member: member } end diff --git a/spec/views/members/index.html.haml_spec.rb b/spec/views/members/index.html.haml_spec.rb index 9488fa5df..34fda500f 100644 --- a/spec/views/members/index.html.haml_spec.rb +++ b/spec/views/members/index.html.haml_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe "members/index" do let(:member) { FactoryBot.create(:london_member) } - before(:each) do + before do controller.stub(:current_user) { nil } page = 1 per_page = 2 diff --git a/spec/views/members/show.rss.haml_spec.rb b/spec/views/members/show.rss.haml_spec.rb index 6ee321be4..a0a7414e0 100644 --- a/spec/views/members/show.rss.haml_spec.rb +++ b/spec/views/members/show.rss.haml_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe 'members/show.rss.haml', type: "view" do subject { rendered } - before(:each) do + before do @member = assign(:member, FactoryBot.create(:member, login_name: 'callum')) @post1 = FactoryBot.create(:post, id: 1, author: @member) @post2 = FactoryBot.create(:markdown_post, id: 2, author: @member) diff --git a/spec/views/notifications/index.html.haml_spec.rb b/spec/views/notifications/index.html.haml_spec.rb index 0bb4257fa..d02e43038 100644 --- a/spec/views/notifications/index.html.haml_spec.rb +++ b/spec/views/notifications/index.html.haml_spec.rb @@ -1,13 +1,13 @@ require 'rails_helper' describe "notifications/index" do - before(:each) do + before do @member = FactoryBot.create(:member) controller.stub(:current_user) { @member } end context "ordinary notifications" do - before(:each) do + before do @notification = FactoryBot.create(:notification, sender: @member, recipient: @member) assign(:notifications, Kaminari.paginate_array([@notification, @notification]).page(1)) diff --git a/spec/views/notifications/new.html.haml_spec.rb b/spec/views/notifications/new.html.haml_spec.rb index a7f030f47..242f433e3 100644 --- a/spec/views/notifications/new.html.haml_spec.rb +++ b/spec/views/notifications/new.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "notifications/new" do - before(:each) do + before do @recipient = FactoryBot.create(:member) @sender = FactoryBot.create(:member) assign(:notification, FactoryBot.create(:notification, recipient_id: @recipient.id, sender_id: @sender.id)) diff --git a/spec/views/notifications/show.html.haml_spec.rb b/spec/views/notifications/show.html.haml_spec.rb index 14db0448c..9f5087f41 100644 --- a/spec/views/notifications/show.html.haml_spec.rb +++ b/spec/views/notifications/show.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "notifications/show" do - before(:each) do + before do @member = FactoryBot.create(:member) @notification = FactoryBot.create(:notification, recipient: @member) assign(:notification, @notification) diff --git a/spec/views/notifier/notify.html.haml_spec.rb b/spec/views/notifier/notify.html.haml_spec.rb index 913ea10d2..39b52e603 100644 --- a/spec/views/notifier/notify.html.haml_spec.rb +++ b/spec/views/notifier/notify.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'notifier/notify.html.haml', type: "view" do - before(:each) do + before do @notification = FactoryBot.create(:notification) @reply_link = "http://example.com" @signed_message = "EncryptedMessage" @@ -9,24 +9,24 @@ describe 'notifier/notify.html.haml', type: "view" do render end - it 'should say that you have a message' do + it 'says that you have a message' do rendered.should have_content 'You have received a message' end - it 'should include notification metadata' do + it 'includes notification metadata' do rendered.should have_content @notification.sender.login_name rendered.should have_content @notification.post.subject end - it 'should include a reply link' do + it 'includes a reply link' do assert_select "a[href='#{@reply_link}']", text: /Reply/ end - it 'should contain a link to your inbox' do + it 'contains a link to your inbox' do assert_select "a[href*='notifications']" end - it 'should have fully qualified URLs' do + it 'has fully qualified URLs' do # lots of lovely fully qualified URLs assert_select "a[href^='http']", minimum: 4 # no relative URLs starting with / diff --git a/spec/views/photos/edit.html.haml_spec.rb b/spec/views/photos/edit.html.haml_spec.rb index d83a1a911..a4491a226 100644 --- a/spec/views/photos/edit.html.haml_spec.rb +++ b/spec/views/photos/edit.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "photos/edit" do - before(:each) do + before do @photo = assign(:photo, stub_model(Photo, owner_id: 1, flickr_photo_id: 1, diff --git a/spec/views/photos/index.html.haml_spec.rb b/spec/views/photos/index.html.haml_spec.rb index b603de1e6..5598de23a 100644 --- a/spec/views/photos/index.html.haml_spec.rb +++ b/spec/views/photos/index.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "photos/index" do - before(:each) do + before do page = 1 per_page = 2 total_entries = 2 diff --git a/spec/views/photos/new.html.haml_spec.rb b/spec/views/photos/new.html.haml_spec.rb index e4f24f9e4..9f4072ee5 100644 --- a/spec/views/photos/new.html.haml_spec.rb +++ b/spec/views/photos/new.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "photos/new" do - before(:each) do + before do @member = FactoryBot.create(:member) controller.stub(:current_user) { @member } page = 1 @@ -22,7 +22,7 @@ describe "photos/new" do end context "user has photosets" do - before(:each) do + before do assign(:sets, "foo" => "bar") # Hash of names => IDs end diff --git a/spec/views/photos/show.html.haml_spec.rb b/spec/views/photos/show.html.haml_spec.rb index 42d247941..162477aa5 100644 --- a/spec/views/photos/show.html.haml_spec.rb +++ b/spec/views/photos/show.html.haml_spec.rb @@ -49,7 +49,7 @@ describe "photos/show" do end context "signed in as owner" do - before(:each) do + before do controller.stub(:current_user) { member } render end @@ -62,7 +62,7 @@ describe "photos/show" do end context "signed in as another member" do - before(:each) do + before do controller.stub(:current_user) { FactoryBot.create :member } render end @@ -72,7 +72,7 @@ describe "photos/show" do end context "not signed in" do - before(:each) do + before do controller.stub(:current_user) { nil } render end @@ -82,7 +82,7 @@ describe "photos/show" do end context "CC-licensed photo" do - before(:each) do + before do controller.stub(:current_user) { nil } @photo.harvests << harvest @photo.plantings << planting @@ -98,7 +98,7 @@ describe "photos/show" do end context "unlicensed photo" do - before(:each) do + before do controller.stub(:current_user) { nil } @photo = assign(:photo, FactoryBot.create(:unlicensed_photo)) render diff --git a/spec/views/places/_map_attribution.html.haml_spec.rb b/spec/views/places/_map_attribution.html.haml_spec.rb index 7082290c8..afe384dfe 100644 --- a/spec/views/places/_map_attribution.html.haml_spec.rb +++ b/spec/views/places/_map_attribution.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "places/_map_attribution.html.haml", type: :view do - before(:each) do + before do render end diff --git a/spec/views/places/index.html.haml_spec.rb b/spec/views/places/index.html.haml_spec.rb index f3a3661ae..072eb4ca3 100644 --- a/spec/views/places/index.html.haml_spec.rb +++ b/spec/views/places/index.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "places/index" do - before(:each) do + before do render end diff --git a/spec/views/places/show.html.haml_spec.rb b/spec/views/places/show.html.haml_spec.rb index 635d06ab9..7f9aa0c9c 100644 --- a/spec/views/places/show.html.haml_spec.rb +++ b/spec/views/places/show.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "places/show" do - before(:each) do + before do @member = FactoryBot.create(:london_member) @nearby_members = [FactoryBot.create(:member)] controller.stub(:current_user) { @member } diff --git a/spec/views/plant_parts/edit.html.haml_spec.rb b/spec/views/plant_parts/edit.html.haml_spec.rb index 683dd6ab0..3eaa4fbac 100644 --- a/spec/views/plant_parts/edit.html.haml_spec.rb +++ b/spec/views/plant_parts/edit.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "plant_parts/edit" do - before(:each) do + before do @plant_part = assign(:plant_part, stub_model(PlantPart, name: "MyString")) end diff --git a/spec/views/plant_parts/index.html.haml_spec.rb b/spec/views/plant_parts/index.html.haml_spec.rb index 65ecf2d63..b46c4a1a5 100644 --- a/spec/views/plant_parts/index.html.haml_spec.rb +++ b/spec/views/plant_parts/index.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "plant_parts/index" do - before(:each) do + before do controller.stub(:current_user) { nil } @pp = FactoryBot.create(:plant_part) assign(:plant_parts, [@pp]) diff --git a/spec/views/plant_parts/new.html.haml_spec.rb b/spec/views/plant_parts/new.html.haml_spec.rb index b1b3f12ae..90a1465f4 100644 --- a/spec/views/plant_parts/new.html.haml_spec.rb +++ b/spec/views/plant_parts/new.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "plant_parts/new" do - before(:each) do + before do assign(:plant_part, stub_model(PlantPart, name: "MyString").as_new_record) end diff --git a/spec/views/plant_parts/show.html.haml_spec.rb b/spec/views/plant_parts/show.html.haml_spec.rb index b367a723b..9947cfcce 100644 --- a/spec/views/plant_parts/show.html.haml_spec.rb +++ b/spec/views/plant_parts/show.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "plant_parts/show" do - before(:each) do + before do controller.stub(:current_user) { nil } @pp = FactoryBot.create(:plant_part) @harvest = FactoryBot.create(:harvest, plant_part: @pp) diff --git a/spec/views/plantings/_form.html.haml_spec.rb b/spec/views/plantings/_form.html.haml_spec.rb index 8da8f1bfe..c4f6247b0 100644 --- a/spec/views/plantings/_form.html.haml_spec.rb +++ b/spec/views/plantings/_form.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "plantings/_form" do - before(:each) do + before do @member = FactoryBot.create(:member) @garden = FactoryBot.create(:garden, owner: @member) @uppercase = FactoryBot.create(:uppercasecrop) diff --git a/spec/views/plantings/edit.html.haml_spec.rb b/spec/views/plantings/edit.html.haml_spec.rb index 0afa1e829..768434f16 100644 --- a/spec/views/plantings/edit.html.haml_spec.rb +++ b/spec/views/plantings/edit.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "plantings/edit" do - before(:each) do + before do @member = FactoryBot.create(:member, login_name: 'right', email: 'right@example.com') @@ -20,7 +20,7 @@ describe "plantings/edit" do end context "logged in" do - before(:each) do + before do sign_in @member controller.stub(:current_user) { @member } render diff --git a/spec/views/plantings/index.html.haml_spec.rb b/spec/views/plantings/index.html.haml_spec.rb index 3df5b20ff..792c2b5e5 100644 --- a/spec/views/plantings/index.html.haml_spec.rb +++ b/spec/views/plantings/index.html.haml_spec.rb @@ -6,7 +6,7 @@ describe "plantings/index" do let(:tomato) { FactoryBot.create(:tomato) } let(:maize) { FactoryBot.create(:maize) } - before(:each) do + before do controller.stub(:current_user) { nil } page = 1 per_page = 3 diff --git a/spec/views/plantings/index.rss.haml_spec.rb b/spec/views/plantings/index.rss.haml_spec.rb index c4a394561..24faa046c 100644 --- a/spec/views/plantings/index.rss.haml_spec.rb +++ b/spec/views/plantings/index.rss.haml_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' describe 'plantings/index.rss.haml' do - before(:each) do + before do controller.stub(:current_user) { nil } end context 'all plantings' do - before :each do + before do @planting = FactoryBot.create(:planting) @sunny = FactoryBot.create(:sunny_planting) @seedling = FactoryBot.create(:seedling_planting) @@ -36,7 +36,7 @@ describe 'plantings/index.rss.haml' do end context "one person's plantings" do - before :each do + before do @planting = FactoryBot.create(:planting) assign(:plantings, [@planting]) assign(:owner, @planting.owner) diff --git a/spec/views/plantings/new.html.haml_spec.rb b/spec/views/plantings/new.html.haml_spec.rb index 6b6b11f57..418860c86 100644 --- a/spec/views/plantings/new.html.haml_spec.rb +++ b/spec/views/plantings/new.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "plantings/new" do - before(:each) do + before do @member = FactoryBot.create(:member) controller.stub(:current_user) { @member } @@ -18,7 +18,7 @@ describe "plantings/new" do end context "logged in" do - before(:each) do + before do sign_in @member assign(:planting, Planting.new) assign(:crop, @crop2) diff --git a/spec/views/plantings/show.html.haml_spec.rb b/spec/views/plantings/show.html.haml_spec.rb index 47a742c58..1d12e6f6d 100644 --- a/spec/views/plantings/show.html.haml_spec.rb +++ b/spec/views/plantings/show.html.haml_spec.rb @@ -10,7 +10,7 @@ describe "plantings/show" do planted_from: 'cutting') end - before(:each) do + before do assign(:planting, planting) assign(:photos, planting.photos.paginate(page: 1)) controller.stub(:current_user) { member } @@ -55,7 +55,7 @@ describe "plantings/show" do end context "no location set" do - before(:each) do + before do render end @@ -77,7 +77,7 @@ describe "plantings/show" do end context "location set" do - before(:each) do + before do planting.owner.update(location: 'Greenwich, UK') render end diff --git a/spec/views/posts/_single.html.haml_spec.rb b/spec/views/posts/_single.html.haml_spec.rb index a153995c5..524e1ae9c 100644 --- a/spec/views/posts/_single.html.haml_spec.rb +++ b/spec/views/posts/_single.html.haml_spec.rb @@ -5,13 +5,13 @@ describe "posts/_single" do render partial: "single", locals: { post: @post } end - before(:each) do + before do @post = FactoryBot.create(:post) controller.stub(:current_user) { nil } end context "when the number of comments doesn't matter" do - before(:each) do + before do render_post end @@ -25,7 +25,7 @@ describe "posts/_single" do end context "when logged in" do - before(:each) do + before do @member = FactoryBot.create(:member) sign_in @member controller.stub(:current_user) { @member } @@ -42,7 +42,7 @@ describe "posts/_single" do end context "when logged in as post author" do - before(:each) do + before do @member = FactoryBot.create(:member) sign_in @member controller.stub(:current_user) { @member } @@ -56,7 +56,7 @@ describe "posts/_single" do end context "when there are no comments" do - before(:each) do + before do render_post end @@ -66,7 +66,7 @@ describe "posts/_single" do end context "when there is 1 comment" do - before(:each) do + before do @comment = FactoryBot.create(:comment, post: @post) render_post end @@ -77,7 +77,7 @@ describe "posts/_single" do end context "when there are 2 comments" do - before(:each) do + before do @comment = FactoryBot.create(:comment, post: @post) @comment2 = FactoryBot.create(:comment, post: @post) render_post @@ -89,7 +89,7 @@ describe "posts/_single" do end context "when comments should be hidden" do - before(:each) do + before do @member = FactoryBot.create(:member) sign_in @member controller.stub(:current_user) { @member } @@ -113,7 +113,7 @@ describe "posts/_single" do end context "when post has been edited" do - before(:each) do + before do @member = FactoryBot.create(:member) sign_in @member controller.stub(:current_user) { @member } @@ -132,7 +132,7 @@ describe "posts/_single" do end context "when comment has been edited" do - before(:each) do + before do @member = FactoryBot.create(:member) sign_in @member controller.stub(:current_user) { @member } @@ -152,7 +152,7 @@ describe "posts/_single" do end context "when post has not been edited" do - before(:each) do + before do @member = FactoryBot.create(:member) sign_in @member controller.stub(:current_user) { @member } @@ -167,7 +167,7 @@ describe "posts/_single" do end context "when comment has not been edited" do - before(:each) do + before do @member = FactoryBot.create(:member) sign_in @member controller.stub(:current_user) { @member } diff --git a/spec/views/posts/edit.html.haml_spec.rb b/spec/views/posts/edit.html.haml_spec.rb index 8ec056aff..b8a72ca74 100644 --- a/spec/views/posts/edit.html.haml_spec.rb +++ b/spec/views/posts/edit.html.haml_spec.rb @@ -1,14 +1,14 @@ require 'rails_helper' describe "posts/edit" do - before(:each) do + before do controller.stub(:current_user) { nil } @author = FactoryBot.create(:member) @post = assign(:post, FactoryBot.create(:post, author: @author)) end context "logged in" do - before(:each) do + before do sign_in @author render end @@ -29,7 +29,7 @@ describe "posts/edit" do end context "forum specified" do - before(:each) do + before do @forum = assign(:forum, FactoryBot.create(:forum)) assign(:post, FactoryBot.create(:post, forum: @forum, diff --git a/spec/views/posts/index.html.haml_spec.rb b/spec/views/posts/index.html.haml_spec.rb index b2f956904..44508846d 100644 --- a/spec/views/posts/index.html.haml_spec.rb +++ b/spec/views/posts/index.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "posts/index" do - before(:each) do + before do controller.stub(:current_user) { nil } @author = FactoryBot.create(:member) page = 1 diff --git a/spec/views/posts/index.rss.haml_spec.rb b/spec/views/posts/index.rss.haml_spec.rb index 3d4ec11f2..83576079f 100644 --- a/spec/views/posts/index.rss.haml_spec.rb +++ b/spec/views/posts/index.rss.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'posts/index.rss.haml', type: "view" do - before(:each) do + before do controller.stub(:current_user) { nil } author = FactoryBot.create(:member) @post1 = FactoryBot.create(:post, id: 1, author: author) diff --git a/spec/views/posts/new.html.haml_spec.rb b/spec/views/posts/new.html.haml_spec.rb index 6c6a2ae68..eaef7f5da 100644 --- a/spec/views/posts/new.html.haml_spec.rb +++ b/spec/views/posts/new.html.haml_spec.rb @@ -2,7 +2,8 @@ require 'rails_helper' describe "posts/new" do let(:author) { FactoryBot.create(:member) } - before(:each) do + + before do assign(:post, FactoryBot.create(:post, author: author)) # assign(:forum, Forum.new) sign_in author @@ -36,7 +37,7 @@ describe "posts/new" do context "forum specified" do let(:forum) { FactoryBot.create(:forum) } - before(:each) do + before do assign(:forum, forum) assign(:post, FactoryBot.create(:post, forum: forum)) render diff --git a/spec/views/posts/show.html.haml_spec.rb b/spec/views/posts/show.html.haml_spec.rb index 8a9733039..2754439d1 100644 --- a/spec/views/posts/show.html.haml_spec.rb +++ b/spec/views/posts/show.html.haml_spec.rb @@ -2,9 +2,10 @@ require 'rails_helper' describe "posts/show" do subject { rendered } + let(:author) { FactoryBot.create(:member, login_name: 'mary') } - before(:each) do + before do controller.stub(:current_user) { nil } assign(:post, post) end @@ -60,7 +61,7 @@ describe "posts/show" do let(:post) { FactoryBot.create(:html_post, author: author) } let!(:comment) { FactoryBot.create(:comment, post: post) } - before(:each) do + before do @comments = post.comments render end @@ -81,7 +82,7 @@ describe "posts/show" do context "when there is more than one comment" do let(:post) { FactoryBot.create(:html_post, author: author) } - before(:each) do + before do @comment1 = FactoryBot.create(:comment, post: post, body: "F1rst!!!", created_at: Date.new(2010, 5, 17)) @comment3 = FactoryBot.create(:comment, post: post, body: "Th1rd!!!", @@ -111,7 +112,7 @@ describe "posts/show" do context "signed in" do let(:post) { FactoryBot.create(:post, author: author) } - before(:each) do + before do sign_in author controller.stub(:current_user) { author } render diff --git a/spec/views/posts/show.rss.haml_spec.rb b/spec/views/posts/show.rss.haml_spec.rb index c22c4196f..802bebe93 100644 --- a/spec/views/posts/show.rss.haml_spec.rb +++ b/spec/views/posts/show.rss.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'posts/show.rss.haml' do - before(:each) do + before do controller.stub(:current_user) { nil } @author = FactoryBot.create(:member) @post = FactoryBot.create(:post) diff --git a/spec/views/roles/edit.html.haml_spec.rb b/spec/views/roles/edit.html.haml_spec.rb index 01def5033..f546c7c21 100644 --- a/spec/views/roles/edit.html.haml_spec.rb +++ b/spec/views/roles/edit.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "roles/edit" do - before(:each) do + before do @role = assign(:role, stub_model(Role, name: "MyString", description: "MyText")) diff --git a/spec/views/roles/index.html.haml_spec.rb b/spec/views/roles/index.html.haml_spec.rb index 8338f3cd9..a666a4ac8 100644 --- a/spec/views/roles/index.html.haml_spec.rb +++ b/spec/views/roles/index.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "roles/index" do - before(:each) do + before do controller.stub(:current_user) { nil } assign(:roles, [ stub_model(Role, diff --git a/spec/views/roles/new.html.haml_spec.rb b/spec/views/roles/new.html.haml_spec.rb index eab80fa36..d04afacef 100644 --- a/spec/views/roles/new.html.haml_spec.rb +++ b/spec/views/roles/new.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "roles/new" do - before(:each) do + before do assign(:role, stub_model(Role, name: "MyString", description: "MyText").as_new_record) diff --git a/spec/views/roles/show.html.haml_spec.rb b/spec/views/roles/show.html.haml_spec.rb index f6d0b10b3..1f41bb23c 100644 --- a/spec/views/roles/show.html.haml_spec.rb +++ b/spec/views/roles/show.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "roles/show" do - before(:each) do + before do @role = assign(:role, stub_model(Role, name: "Name", description: "MyText")) diff --git a/spec/views/scientific_names/edit.html.haml_spec.rb b/spec/views/scientific_names/edit.html.haml_spec.rb index 249cd249b..5cf1b6fe6 100644 --- a/spec/views/scientific_names/edit.html.haml_spec.rb +++ b/spec/views/scientific_names/edit.html.haml_spec.rb @@ -5,7 +5,7 @@ describe "scientific_names/edit" do let(:member) { FactoryBot.create(:member) } let(:scientific_name) { FactoryBot.create(:zea_mays, creator: member) } - before(:each) do + before do sign_in member controller.stub(:current_user) { member } assign(:scientific_name, scientific_name) diff --git a/spec/views/scientific_names/index.html.haml_spec.rb b/spec/views/scientific_names/index.html.haml_spec.rb index 4d63ac9e1..9d098e58b 100644 --- a/spec/views/scientific_names/index.html.haml_spec.rb +++ b/spec/views/scientific_names/index.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "scientific_names/index" do - before(:each) do + before do controller.stub(:current_user) { nil } assign(:scientific_names, [ FactoryBot.create(:zea_mays), @@ -22,7 +22,7 @@ describe "scientific_names/index" do end context "logged in and crop wrangler" do - before(:each) do + before do @member = FactoryBot.create(:crop_wrangling_member) sign_in @member controller.stub(:current_user) { @member } diff --git a/spec/views/scientific_names/new.html.haml_spec.rb b/spec/views/scientific_names/new.html.haml_spec.rb index 0cf5a4205..1f6320308 100644 --- a/spec/views/scientific_names/new.html.haml_spec.rb +++ b/spec/views/scientific_names/new.html.haml_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' describe "scientific_names/new" do - before(:each) do + before do assign(:scientific_name, FactoryBot.create(:zea_mays)) end context "logged in" do - before(:each) do + before do @member = FactoryBot.create(:member) sign_in @member controller.stub(:current_user) { @member } diff --git a/spec/views/scientific_names/show.html.haml_spec.rb b/spec/views/scientific_names/show.html.haml_spec.rb index b728df2b3..c8e64a6dc 100644 --- a/spec/views/scientific_names/show.html.haml_spec.rb +++ b/spec/views/scientific_names/show.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "scientific_names/show" do - before(:each) do + before do controller.stub(:current_user) { nil } @scientific_name = assign(:scientific_name, FactoryBot.create(:zea_mays)) @@ -14,14 +14,14 @@ describe "scientific_names/show" do end context 'signed in' do - before :each do + before do @wrangler = FactoryBot.create(:crop_wrangling_member) sign_in @wrangler controller.stub(:current_user) { @wrangler } render end - it 'should have an edit button' do + it 'has an edit button' do rendered.should have_content 'Edit' end end diff --git a/spec/views/seeds/edit.html.haml_spec.rb b/spec/views/seeds/edit.html.haml_spec.rb index f450d7065..4bc6bf815 100644 --- a/spec/views/seeds/edit.html.haml_spec.rb +++ b/spec/views/seeds/edit.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "seeds/edit" do - before(:each) do + before do @member = FactoryBot.create(:member) sign_in @member controller.stub(:current_user) { @member } diff --git a/spec/views/seeds/index.rss.haml_spec.rb b/spec/views/seeds/index.rss.haml_spec.rb index 4df8e526c..cfeedd904 100644 --- a/spec/views/seeds/index.rss.haml_spec.rb +++ b/spec/views/seeds/index.rss.haml_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' describe 'seeds/index.rss.haml' do - before(:each) do + before do controller.stub(:current_user) { nil } end context 'all seeds' do - before(:each) do + before do @seed = FactoryBot.create(:seed) @tradable = FactoryBot.create(:tradable_seed) assign(:seeds, [@seed, @tradable]) @@ -35,7 +35,7 @@ describe 'seeds/index.rss.haml' do end context "one member's seeds" do - before(:each) do + before do @seed = FactoryBot.create(:seed) assign(:seeds, [@seed]) assign(:owner, @seed.owner) diff --git a/spec/views/seeds/new.html.haml_spec.rb b/spec/views/seeds/new.html.haml_spec.rb index 3b33cc6c4..2a132c432 100644 --- a/spec/views/seeds/new.html.haml_spec.rb +++ b/spec/views/seeds/new.html.haml_spec.rb @@ -4,7 +4,7 @@ describe "seeds/new" do let!(:seed) { FactoryBot.create(:seed, owner: member) } let!(:member) { FactoryBot.create(:member) } - before(:each) do + before do sign_in member controller.stub(:current_user) { @member } assign(:seed, seed) diff --git a/spec/views/seeds/show.html.haml_spec.rb b/spec/views/seeds/show.html.haml_spec.rb index 2ad38bdcf..2426495be 100644 --- a/spec/views/seeds/show.html.haml_spec.rb +++ b/spec/views/seeds/show.html.haml_spec.rb @@ -2,7 +2,8 @@ require 'rails_helper' describe "seeds/show" do let(:seed) { FactoryBot.create(:seed) } - before(:each) do + + before do controller.stub(:current_user) { nil } assign(:seed, seed) assign(:photos, seed.photos.paginate(page: 1)) @@ -19,7 +20,7 @@ describe "seeds/show" do let!(:seed) { FactoryBot.create(:tradable_seed, owner: owner) } let!(:member) { FactoryBot.create(:member) } - before(:each) do + before do assign(:seed, seed) # note current_member is not the owner of this seed sign_in member @@ -46,7 +47,7 @@ describe "seeds/show" do let(:owner) { FactoryBot.create(:member) } let!(:seed) { FactoryBot.create(:tradable_seed, owner: owner) } - before(:each) do + before do sign_in owner controller.stub(:current_user) { owner } assign(:seed, seed)