From 22f9e3bf208a01ec463e648bbddef24eaa48918c Mon Sep 17 00:00:00 2001 From: Carrosen Date: Thu, 9 May 2019 12:14:46 +0200 Subject: [PATCH 01/20] creates feature test for host_can_make_offer_on_listing, adds button to listing, 1/8 tests going green --- app/views/listings/index.html.haml | 1 + .../host_can_make_offer_on_listing.feature | 28 +++++++++++++++++++ features/step_definitions/assertion_steps.rb | 5 ++++ features/step_definitions/basic_steps.rb | 19 +++++++++++-- 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 features/host_can_make_offer_on_listing.feature diff --git a/app/views/listings/index.html.haml b/app/views/listings/index.html.haml index 4bf7960..54eb837 100644 --- a/app/views/listings/index.html.haml +++ b/app/views/listings/index.html.haml @@ -7,3 +7,4 @@ %p= listing.start_date %p= listing.end_date %p= listing.pet_picture + %button= "Make an offer" diff --git a/features/host_can_make_offer_on_listing.feature b/features/host_can_make_offer_on_listing.feature new file mode 100644 index 0000000..41cf056 --- /dev/null +++ b/features/host_can_make_offer_on_listing.feature @@ -0,0 +1,28 @@ +Feature: Host can make an offer on a listing + As a host, + In order to make some money, + I want to be able to make an offer on a listing + + Background: + Given the following listings exist + | pet_name | pet_location | pet_description | start_date | end_date | pet_picture | + | Zane | Gothenburg | I'm nice | 2019-06-28 | 2019-06-29 | picture1 | + | Carla | Stockholm | I love cats! | 2019-05-28 | 2019-06-01 | picture2 | + + When I visit the landing page + Then I should see "Zane" + And I should see "Gothenburg" within "Zane" section + And I should see "I'm nice" within "Zane" section + And I should see "2019-06-28" within "Zane" section + And I should see "2019-06-29" within "Zane" section + And I should see "picture1" within "Zane" section + + Scenario: + When I click on "Make an offer" within "Zane" section + Then I should see "Create your offer" + And I fill in "Name" with "Steffe" + And I fill in "Email" with "steffe@gmail.com" + And I fill in "Location" with "Gothenburg" + And I fill in "Price/day" with "100kr" + When I click "Make offer" + Then I should be on show listing page \ No newline at end of file diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index 128a3b0..a6251e7 100644 --- a/features/step_definitions/assertion_steps.rb +++ b/features/step_definitions/assertion_steps.rb @@ -21,3 +21,8 @@ Then("I should be on landing page") do expect(current_path).to eq root_path end + +Then("I should be on show listing page") do + pending # Write code here that turns the phrase above into concrete actions +end + diff --git a/features/step_definitions/basic_steps.rb b/features/step_definitions/basic_steps.rb index fe545fd..389692c 100644 --- a/features/step_definitions/basic_steps.rb +++ b/features/step_definitions/basic_steps.rb @@ -18,6 +18,19 @@ click_on button end -Then "stop" do - binding.pry -end \ No newline at end of file +When("I click on {string} within {string} section") do |content, section| +name = Listing.find_by(pet_name: section) +dom_section = "#listing_#{name.id}" +within(dom_section) do + expect(page).to have_content content + end +end + +When("I click {string}") do |string| + pending # Write code here that turns the phrase above into concrete actions +end + + +# Then "stop" do +# binding.pry +# end \ No newline at end of file From 25be6a92cc460bfbe80595913130695192d1fa6b Mon Sep 17 00:00:00 2001 From: stefan_karlberg Date: Thu, 9 May 2019 13:43:37 +0200 Subject: [PATCH 02/20] Creates model Offer. Creates controller Offers. --- app/controllers/offers_controller.rb | 9 +++++++++ app/models/offer.rb | 2 ++ app/views/offers/new.html.haml | 1 + config/routes.rb | 4 +++- db/migrate/20190509113524_create_offers.rb | 12 ++++++++++++ db/schema.rb | 11 ++++++++++- spec/factories/offers.rb | 8 ++++++++ spec/models/offer_spec.rb | 5 +++++ 8 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 app/controllers/offers_controller.rb create mode 100644 app/models/offer.rb create mode 100644 app/views/offers/new.html.haml create mode 100644 db/migrate/20190509113524_create_offers.rb create mode 100644 spec/factories/offers.rb create mode 100644 spec/models/offer_spec.rb diff --git a/app/controllers/offers_controller.rb b/app/controllers/offers_controller.rb new file mode 100644 index 0000000..16bdc4d --- /dev/null +++ b/app/controllers/offers_controller.rb @@ -0,0 +1,9 @@ +class OffersController < ApplicationController + def index + @offers = Offer.all + end + + def new + @offer = Offer.new + end +end diff --git a/app/models/offer.rb b/app/models/offer.rb new file mode 100644 index 0000000..a3654cf --- /dev/null +++ b/app/models/offer.rb @@ -0,0 +1,2 @@ +class Offer < ApplicationRecord +end diff --git a/app/views/offers/new.html.haml b/app/views/offers/new.html.haml new file mode 100644 index 0000000..66803f2 --- /dev/null +++ b/app/views/offers/new.html.haml @@ -0,0 +1 @@ +%h1 Create your offer \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1fd0c3f..b609b23 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Rails.application.routes.draw do root controller: :listings, action: :index - resources :listings, only: [:new, :create] + resources :listings, only: [:new, :create] do + resources :offers + end end diff --git a/db/migrate/20190509113524_create_offers.rb b/db/migrate/20190509113524_create_offers.rb new file mode 100644 index 0000000..fa06fc4 --- /dev/null +++ b/db/migrate/20190509113524_create_offers.rb @@ -0,0 +1,12 @@ +class CreateOffers < ActiveRecord::Migration[5.2] + def change + create_table :offers do |t| + t.string :name + t.string :email + t.string :location + t.integer :price + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 5688d75..fa0d979 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_05_08_150729) do +ActiveRecord::Schema.define(version: 2019_05_09_113524) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -26,4 +26,13 @@ t.string "pet_picture" end + create_table "offers", force: :cascade do |t| + t.string "name" + t.string "email" + t.string "location" + t.integer "price" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + end diff --git a/spec/factories/offers.rb b/spec/factories/offers.rb new file mode 100644 index 0000000..99730aa --- /dev/null +++ b/spec/factories/offers.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :offer do + name { "MyString" } + email { "MyString" } + location { "MyString" } + price { 1 } + end +end diff --git a/spec/models/offer_spec.rb b/spec/models/offer_spec.rb new file mode 100644 index 0000000..c75384e --- /dev/null +++ b/spec/models/offer_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Offer, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 1f9a218d4c69911185ea7efd803d2c2df80a14d4 Mon Sep 17 00:00:00 2001 From: Carrosen Date: Thu, 9 May 2019 14:19:42 +0200 Subject: [PATCH 03/20] adds column to db table, Listing references to model offer --- config/routes.rb | 2 +- db/migrate/20190509121804_add_listing_to_offers.rb | 5 +++++ db/schema.rb | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20190509121804_add_listing_to_offers.rb diff --git a/config/routes.rb b/config/routes.rb index b609b23..2fae6e6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do root controller: :listings, action: :index resources :listings, only: [:new, :create] do - resources :offers + resources :offers end end diff --git a/db/migrate/20190509121804_add_listing_to_offers.rb b/db/migrate/20190509121804_add_listing_to_offers.rb new file mode 100644 index 0000000..fef522d --- /dev/null +++ b/db/migrate/20190509121804_add_listing_to_offers.rb @@ -0,0 +1,5 @@ +class AddListingToOffers < ActiveRecord::Migration[5.2] + def change + add_reference :offers, :listing, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index fa0d979..39a6942 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_05_09_113524) do +ActiveRecord::Schema.define(version: 2019_05_09_121804) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -33,6 +33,9 @@ t.integer "price" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.bigint "listing_id" + t.index ["listing_id"], name: "index_offers_on_listing_id" end + add_foreign_key "offers", "listings" end From a408eebc0ad4447b953b2849a24a37f48a0bef1a Mon Sep 17 00:00:00 2001 From: stefan_karlberg Date: Thu, 9 May 2019 15:01:44 +0200 Subject: [PATCH 04/20] Added path to new offer in listings. Trying to make tests pass. Now going red. --- app/models/listing.rb | 1 + app/models/offer.rb | 1 + app/views/listings/index.html.haml | 2 +- config/routes.rb | 5 ++--- features/host_can_make_offer_on_listing.feature | 4 +++- features/step_definitions/assertion_steps.rb | 4 ++++ 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/models/listing.rb b/app/models/listing.rb index ce2f2ed..b727292 100644 --- a/app/models/listing.rb +++ b/app/models/listing.rb @@ -1,3 +1,4 @@ class Listing < ApplicationRecord validates_presence_of :pet_name, :pet_location, :pet_description, :start_date, :end_date, :pet_picture + has_many :offers end diff --git a/app/models/offer.rb b/app/models/offer.rb index a3654cf..ae80b0b 100644 --- a/app/models/offer.rb +++ b/app/models/offer.rb @@ -1,2 +1,3 @@ class Offer < ApplicationRecord + belongs_to :listing end diff --git a/app/views/listings/index.html.haml b/app/views/listings/index.html.haml index 54eb837..a897b72 100644 --- a/app/views/listings/index.html.haml +++ b/app/views/listings/index.html.haml @@ -7,4 +7,4 @@ %p= listing.start_date %p= listing.end_date %p= listing.pet_picture - %button= "Make an offer" + = link_to 'Make an offer', new_offer_path diff --git a/config/routes.rb b/config/routes.rb index 2fae6e6..daa74ea 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,5 @@ Rails.application.routes.draw do root controller: :listings, action: :index - resources :listings, only: [:new, :create] do - resources :offers - end + resources :listings, only: [:new, :create] + resources :offers end diff --git a/features/host_can_make_offer_on_listing.feature b/features/host_can_make_offer_on_listing.feature index 41cf056..3299af2 100644 --- a/features/host_can_make_offer_on_listing.feature +++ b/features/host_can_make_offer_on_listing.feature @@ -16,9 +16,11 @@ Feature: Host can make an offer on a listing And I should see "2019-06-28" within "Zane" section And I should see "2019-06-29" within "Zane" section And I should see "picture1" within "Zane" section - + + @javascript Scenario: When I click on "Make an offer" within "Zane" section + Then I should be on offer page Then I should see "Create your offer" And I fill in "Name" with "Steffe" And I fill in "Email" with "steffe@gmail.com" diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index a6251e7..dc329c4 100644 --- a/features/step_definitions/assertion_steps.rb +++ b/features/step_definitions/assertion_steps.rb @@ -22,6 +22,10 @@ expect(current_path).to eq root_path end +Then("I should be on offer page") do + expect(current_path).to eq new_offer_path +end + Then("I should be on show listing page") do pending # Write code here that turns the phrase above into concrete actions end From 237efde12326a12e54ba5f997a588e2a1d307f8b Mon Sep 17 00:00:00 2001 From: Carrosen Date: Thu, 9 May 2019 15:46:01 +0200 Subject: [PATCH 05/20] adds params to controller, tries to fix error, WIP --- app/controllers/offers_controller.rb | 7 ++++++- app/views/listings/index.html.haml | 2 +- config/routes.rb | 5 +++-- features/step_definitions/assertion_steps.rb | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/offers_controller.rb b/app/controllers/offers_controller.rb index 16bdc4d..2cc3c6a 100644 --- a/app/controllers/offers_controller.rb +++ b/app/controllers/offers_controller.rb @@ -4,6 +4,11 @@ def index end def new - @offer = Offer.new + @offer = Offer.new(params[:listing_id]) + end + + private + def offer_params + params.require(:offer).permit(:listing_id) end end diff --git a/app/views/listings/index.html.haml b/app/views/listings/index.html.haml index a897b72..be15afd 100644 --- a/app/views/listings/index.html.haml +++ b/app/views/listings/index.html.haml @@ -7,4 +7,4 @@ %p= listing.start_date %p= listing.end_date %p= listing.pet_picture - = link_to 'Make an offer', new_offer_path + = link_to 'Make an offer', new_listing_offer_path(:listing_id) diff --git a/config/routes.rb b/config/routes.rb index daa74ea..2fae6e6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,6 @@ Rails.application.routes.draw do root controller: :listings, action: :index - resources :listings, only: [:new, :create] - resources :offers + resources :listings, only: [:new, :create] do + resources :offers + end end diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index dc329c4..4410024 100644 --- a/features/step_definitions/assertion_steps.rb +++ b/features/step_definitions/assertion_steps.rb @@ -23,7 +23,7 @@ end Then("I should be on offer page") do - expect(current_path).to eq new_offer_path + expect(current_path).to eq new_listing_offer_path end Then("I should be on show listing page") do From d7eb10cf7314078e149b5b8dccc790ada2573ca2 Mon Sep 17 00:00:00 2001 From: stefan_karlberg Date: Thu, 9 May 2019 16:32:39 +0200 Subject: [PATCH 06/20] Created new partial - form for offer. Adds required params in Offer controller. Tests still red. --- app/controllers/offers_controller.rb | 6 ++++-- app/views/listings/index.html.haml | 3 ++- app/views/offers/new.html.haml | 4 +++- app/views/partials/_form_offer.html.haml | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 app/views/partials/_form_offer.html.haml diff --git a/app/controllers/offers_controller.rb b/app/controllers/offers_controller.rb index 2cc3c6a..1c32b76 100644 --- a/app/controllers/offers_controller.rb +++ b/app/controllers/offers_controller.rb @@ -4,11 +4,13 @@ def index end def new - @offer = Offer.new(params[:listing_id]) + @offer = Offer.new(offer_params) end private def offer_params - params.require(:offer).permit(:listing_id) + params.require(:offer).permit(:name, :email, :location, :price) end end + + diff --git a/app/views/listings/index.html.haml b/app/views/listings/index.html.haml index be15afd..da2081a 100644 --- a/app/views/listings/index.html.haml +++ b/app/views/listings/index.html.haml @@ -7,4 +7,5 @@ %p= listing.start_date %p= listing.end_date %p= listing.pet_picture - = link_to 'Make an offer', new_listing_offer_path(:listing_id) + = link_to 'Make an offer', new_listing_offer_path(listing.id) + diff --git a/app/views/offers/new.html.haml b/app/views/offers/new.html.haml index 66803f2..1bc955d 100644 --- a/app/views/offers/new.html.haml +++ b/app/views/offers/new.html.haml @@ -1 +1,3 @@ -%h1 Create your offer \ No newline at end of file +%h1 Create your offer + += render "./partials/form_offer.html.haml" \ No newline at end of file diff --git a/app/views/partials/_form_offer.html.haml b/app/views/partials/_form_offer.html.haml new file mode 100644 index 0000000..f878324 --- /dev/null +++ b/app/views/partials/_form_offer.html.haml @@ -0,0 +1,19 @@ += form_with model: @offer, local: true to |form| + %p + = form.label :name + %br/ + = form.text_field :name + %p + = form.label :email + %br/ + = form.text_field :email + %p + = form.label :location + %br/ + = form.text_area :location + %p + = form.label :price + %br/ + = form.text_area :price + %p + = form.submit "Create offer" \ No newline at end of file From 2f57db63327cb8cf6dbc35e2814c54dae9ceafc1 Mon Sep 17 00:00:00 2001 From: Carrosen Date: Thu, 9 May 2019 19:26:23 +0200 Subject: [PATCH 07/20] adds validations of db columns to offer spec, and to validate presence of columns in Offer model, adds show method to offers controller --- app/controllers/offers_controller.rb | 9 +++++--- app/models/offer.rb | 1 + app/views/listings/index.html.haml | 3 +-- .../host_can_make_offer_on_listing.feature | 1 - spec/models/offer_spec.rb | 21 ++++++++++++++++++- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/controllers/offers_controller.rb b/app/controllers/offers_controller.rb index 1c32b76..483a668 100644 --- a/app/controllers/offers_controller.rb +++ b/app/controllers/offers_controller.rb @@ -7,10 +7,13 @@ def new @offer = Offer.new(offer_params) end + def show + @offer = Listing.find(params[:id]) + end + + private def offer_params params.require(:offer).permit(:name, :email, :location, :price) end -end - - +end \ No newline at end of file diff --git a/app/models/offer.rb b/app/models/offer.rb index ae80b0b..38035cc 100644 --- a/app/models/offer.rb +++ b/app/models/offer.rb @@ -1,3 +1,4 @@ class Offer < ApplicationRecord belongs_to :listing + validates_presence_of :name, :email, :location, :price end diff --git a/app/views/listings/index.html.haml b/app/views/listings/index.html.haml index da2081a..47005ef 100644 --- a/app/views/listings/index.html.haml +++ b/app/views/listings/index.html.haml @@ -7,5 +7,4 @@ %p= listing.start_date %p= listing.end_date %p= listing.pet_picture - = link_to 'Make an offer', new_listing_offer_path(listing.id) - + = link_to 'Make an offer', new_listing_offer_path(listing.id) \ No newline at end of file diff --git a/features/host_can_make_offer_on_listing.feature b/features/host_can_make_offer_on_listing.feature index 3299af2..ae7fa22 100644 --- a/features/host_can_make_offer_on_listing.feature +++ b/features/host_can_make_offer_on_listing.feature @@ -17,7 +17,6 @@ Feature: Host can make an offer on a listing And I should see "2019-06-29" within "Zane" section And I should see "picture1" within "Zane" section - @javascript Scenario: When I click on "Make an offer" within "Zane" section Then I should be on offer page diff --git a/spec/models/offer_spec.rb b/spec/models/offer_spec.rb index c75384e..c36ed5c 100644 --- a/spec/models/offer_spec.rb +++ b/spec/models/offer_spec.rb @@ -1,5 +1,24 @@ require 'rails_helper' RSpec.describe Offer, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + describe 'DB table' do + it { is_expected.to have_db_column :id } + it { is_expected.to have_db_column :name } + it { is_expected.to have_db_column :email } + it { is_expected.to have_db_column :location } + it { is_expected.to have_db_column :price } + end + + describe 'Validations' do + it { is_expected.to validate_presence_of :name } + it { is_expected.to validate_presence_of :email } + it { is_expected.to validate_presence_of :location } + it { is_expected.to validate_presence_of :price } + end + + describe 'Factory' do + it 'should have a valid Factory' do + expect(FactoryBot.create(:offer)).to be_valid + end + end end From 33456e442a4b5f16a6154753c41f64933fc72c90 Mon Sep 17 00:00:00 2001 From: stefan_karlberg Date: Fri, 10 May 2019 10:35:44 +0200 Subject: [PATCH 08/20] Adds new view, listings/show, new path in listings/index on button. New method show in listing-controller --- app/controllers/listings_controller.rb | 4 ++++ app/controllers/offers_controller.rb | 6 +++-- app/models/listing.rb | 2 +- app/views/listings/index.html.haml | 2 +- app/views/listings/show.html.haml | 32 ++++++++++++++++++++++++++ config/routes.rb | 2 +- 6 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 app/views/listings/show.html.haml diff --git a/app/controllers/listings_controller.rb b/app/controllers/listings_controller.rb index b0d2c6b..ca84d55 100644 --- a/app/controllers/listings_controller.rb +++ b/app/controllers/listings_controller.rb @@ -7,6 +7,10 @@ def new @listing = Listing.new end + def show + @listing = Listing.find(params[:id]) + end + def create listing = Listing.create(listing_params) diff --git a/app/controllers/offers_controller.rb b/app/controllers/offers_controller.rb index 483a668..5601136 100644 --- a/app/controllers/offers_controller.rb +++ b/app/controllers/offers_controller.rb @@ -7,8 +7,10 @@ def new @offer = Offer.new(offer_params) end - def show - @offer = Listing.find(params[:id]) + def create + @listing = Listing.find(params[:listing_id]) + @offer = @listing.offers.create(offer_params) + redirect_to root_path(@listing) end diff --git a/app/models/listing.rb b/app/models/listing.rb index b727292..ef65d40 100644 --- a/app/models/listing.rb +++ b/app/models/listing.rb @@ -1,4 +1,4 @@ class Listing < ApplicationRecord - validates_presence_of :pet_name, :pet_location, :pet_description, :start_date, :end_date, :pet_picture has_many :offers + validates_presence_of :pet_name, :pet_location, :pet_description, :start_date, :end_date, :pet_picture end diff --git a/app/views/listings/index.html.haml b/app/views/listings/index.html.haml index 47005ef..827e6e6 100644 --- a/app/views/listings/index.html.haml +++ b/app/views/listings/index.html.haml @@ -7,4 +7,4 @@ %p= listing.start_date %p= listing.end_date %p= listing.pet_picture - = link_to 'Make an offer', new_listing_offer_path(listing.id) \ No newline at end of file + = link_to 'Make an offer', listing_path(listing) \ No newline at end of file diff --git a/app/views/listings/show.html.haml b/app/views/listings/show.html.haml new file mode 100644 index 0000000..de280e3 --- /dev/null +++ b/app/views/listings/show.html.haml @@ -0,0 +1,32 @@ +%h1= @listing.pet_name +%p=@listing.pet_location +%p=@listing.pet_description +%p Dates: #{@listing.start_date} to #{@listing.end_date} +%p=@listing.pet_picture + + + + %h2= Make an offer: + += form_with(model: [ @listing, @listing.offers.build ], local: true) do |form| + %p + = form.label :name + %br/ + = form.text_field :name + %p + = form.label :email + %br/ + = form.text_field :email + %p + = form.label :location + %br/ + = form.text_area :location + %p + = form.label :price + %br/ + = form.text_area :price + %p + = form.submit "Create offer" + +-# <%= link_to 'Edit', edit_article_path(@article) %> | +-# <%= link_to 'Back', articles_path %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2fae6e6..20053ca 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Rails.application.routes.draw do root controller: :listings, action: :index - resources :listings, only: [:new, :create] do + resources :listings, only: [:new, :show, :create] do resources :offers end end From 6bc6f767d7357e28637da04c57f29cc519625c24 Mon Sep 17 00:00:00 2001 From: Carrosen Date: Fri, 10 May 2019 11:16:52 +0200 Subject: [PATCH 09/20] adds form for offer to show view, changes step definitions to more accurate ones, removes empty lines. First test in scenario going green, 1/10 --- app/models/listing.rb | 2 +- app/views/listings/show.html.haml | 13 +++++-------- features/host_can_make_offer_on_listing.feature | 7 ++++--- features/step_definitions/assertion_steps.rb | 7 ++++++- features/step_definitions/basic_steps.rb | 13 ++++++++----- spec/factories/offers.rb | 2 +- spec/models/offer_spec.rb | 2 +- 7 files changed, 26 insertions(+), 20 deletions(-) diff --git a/app/models/listing.rb b/app/models/listing.rb index ef65d40..8f5cebc 100644 --- a/app/models/listing.rb +++ b/app/models/listing.rb @@ -1,4 +1,4 @@ class Listing < ApplicationRecord has_many :offers validates_presence_of :pet_name, :pet_location, :pet_description, :start_date, :end_date, :pet_picture -end +end \ No newline at end of file diff --git a/app/views/listings/show.html.haml b/app/views/listings/show.html.haml index de280e3..d2909f8 100644 --- a/app/views/listings/show.html.haml +++ b/app/views/listings/show.html.haml @@ -6,10 +6,9 @@ - %h2= Make an offer: - +%h2 Create your offer = form_with(model: [ @listing, @listing.offers.build ], local: true) do |form| - %p + %p = form.label :name %br/ = form.text_field :name @@ -21,12 +20,10 @@ = form.label :location %br/ = form.text_area :location - %p + %p = form.label :price %br/ = form.text_area :price - %p + %p = form.submit "Create offer" - --# <%= link_to 'Edit', edit_article_path(@article) %> | --# <%= link_to 'Back', articles_path %> \ No newline at end of file + = link_to 'Back', root_path \ No newline at end of file diff --git a/features/host_can_make_offer_on_listing.feature b/features/host_can_make_offer_on_listing.feature index ae7fa22..fee70b4 100644 --- a/features/host_can_make_offer_on_listing.feature +++ b/features/host_can_make_offer_on_listing.feature @@ -18,12 +18,13 @@ Feature: Host can make an offer on a listing And I should see "picture1" within "Zane" section Scenario: - When I click on "Make an offer" within "Zane" section - Then I should be on offer page + When I click "Make an offer" within "Zane" section + Then I should be on the "Zane" listing page Then I should see "Create your offer" And I fill in "Name" with "Steffe" And I fill in "Email" with "steffe@gmail.com" And I fill in "Location" with "Gothenburg" And I fill in "Price/day" with "100kr" When I click "Make offer" - Then I should be on show listing page \ No newline at end of file + And I click "Back" + Then I should be on the landing page \ No newline at end of file diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index 4410024..dd2e32c 100644 --- a/features/step_definitions/assertion_steps.rb +++ b/features/step_definitions/assertion_steps.rb @@ -26,7 +26,12 @@ expect(current_path).to eq new_listing_offer_path end -Then("I should be on show listing page") do +Then("I should be on the {string} listing page") do |string| pending # Write code here that turns the phrase above into concrete actions end +Then("I should be on the landing page") do + pending # Write code here that turns the phrase above into concrete actions +end + + diff --git a/features/step_definitions/basic_steps.rb b/features/step_definitions/basic_steps.rb index 389692c..df1c782 100644 --- a/features/step_definitions/basic_steps.rb +++ b/features/step_definitions/basic_steps.rb @@ -26,11 +26,14 @@ end end +When("I click {string} within {string} section") do |link, section| + name = Listing.find_by(pet_name: section) + dom_section = "#listing_#{name.id}" + within(dom_section) do + click_on link + end +end + When("I click {string}") do |string| pending # Write code here that turns the phrase above into concrete actions end - - -# Then "stop" do -# binding.pry -# end \ No newline at end of file diff --git a/spec/factories/offers.rb b/spec/factories/offers.rb index 99730aa..a05afbe 100644 --- a/spec/factories/offers.rb +++ b/spec/factories/offers.rb @@ -5,4 +5,4 @@ location { "MyString" } price { 1 } end -end +end \ No newline at end of file diff --git a/spec/models/offer_spec.rb b/spec/models/offer_spec.rb index c36ed5c..d7f639b 100644 --- a/spec/models/offer_spec.rb +++ b/spec/models/offer_spec.rb @@ -21,4 +21,4 @@ expect(FactoryBot.create(:offer)).to be_valid end end -end +end \ No newline at end of file From 99b9f4a87fc14c5392efcb0025f09ca62a618cd5 Mon Sep 17 00:00:00 2001 From: stefan_karlberg Date: Fri, 10 May 2019 11:21:21 +0200 Subject: [PATCH 10/20] Added new assertion step, 6/10 in Scenario going green. --- features/step_definitions/assertion_steps.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index dd2e32c..f9b68b3 100644 --- a/features/step_definitions/assertion_steps.rb +++ b/features/step_definitions/assertion_steps.rb @@ -26,8 +26,9 @@ expect(current_path).to eq new_listing_offer_path end -Then("I should be on the {string} listing page") do |string| - pending # Write code here that turns the phrase above into concrete actions +Then("I should be on the {string} listing page") do |listing_name| + name = Listing.find_by(pet_name: listing_name) + visit listing_path(name) end Then("I should be on the landing page") do From 00218f3b7ecccc91e543b68e9463d36355b811bb Mon Sep 17 00:00:00 2001 From: Carrosen Date: Fri, 10 May 2019 11:29:18 +0200 Subject: [PATCH 11/20] changes test in feature to match label on offer form in show view --- app/views/partials/_form_offer.html.haml | 2 +- features/host_can_make_offer_on_listing.feature | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/partials/_form_offer.html.haml b/app/views/partials/_form_offer.html.haml index f878324..0601d5a 100644 --- a/app/views/partials/_form_offer.html.haml +++ b/app/views/partials/_form_offer.html.haml @@ -16,4 +16,4 @@ %br/ = form.text_area :price %p - = form.submit "Create offer" \ No newline at end of file + = form.submit "Create offer" diff --git a/features/host_can_make_offer_on_listing.feature b/features/host_can_make_offer_on_listing.feature index fee70b4..e43b9b6 100644 --- a/features/host_can_make_offer_on_listing.feature +++ b/features/host_can_make_offer_on_listing.feature @@ -24,7 +24,7 @@ Feature: Host can make an offer on a listing And I fill in "Name" with "Steffe" And I fill in "Email" with "steffe@gmail.com" And I fill in "Location" with "Gothenburg" - And I fill in "Price/day" with "100kr" + And I fill in "Price" with "100kr" When I click "Make offer" And I click "Back" Then I should be on the landing page \ No newline at end of file From 2c5b6b321dfb13d84948ee47ace4bc559230cd45 Mon Sep 17 00:00:00 2001 From: stefan_karlberg Date: Fri, 10 May 2019 11:48:01 +0200 Subject: [PATCH 12/20] Refrased feature test in host_can_make_offer_on_listing 8/10 go green --- app/views/listings/show.html.haml | 1 + features/host_can_make_offer_on_listing.feature | 3 +-- features/step_definitions/basic_steps.rb | 6 +----- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/app/views/listings/show.html.haml b/app/views/listings/show.html.haml index d2909f8..55c661f 100644 --- a/app/views/listings/show.html.haml +++ b/app/views/listings/show.html.haml @@ -26,4 +26,5 @@ = form.text_area :price %p = form.submit "Create offer" + = link_to 'Back', root_path \ No newline at end of file diff --git a/features/host_can_make_offer_on_listing.feature b/features/host_can_make_offer_on_listing.feature index e43b9b6..abd0662 100644 --- a/features/host_can_make_offer_on_listing.feature +++ b/features/host_can_make_offer_on_listing.feature @@ -25,6 +25,5 @@ Feature: Host can make an offer on a listing And I fill in "Email" with "steffe@gmail.com" And I fill in "Location" with "Gothenburg" And I fill in "Price" with "100kr" - When I click "Make offer" - And I click "Back" + When I click "Create offer" button Then I should be on the landing page \ No newline at end of file diff --git a/features/step_definitions/basic_steps.rb b/features/step_definitions/basic_steps.rb index df1c782..11b5bb0 100644 --- a/features/step_definitions/basic_steps.rb +++ b/features/step_definitions/basic_steps.rb @@ -32,8 +32,4 @@ within(dom_section) do click_on link end -end - -When("I click {string}") do |string| - pending # Write code here that turns the phrase above into concrete actions -end +end \ No newline at end of file From bd91206580f52124843b72b115e6f08ccd0ccd6c Mon Sep 17 00:00:00 2001 From: Carrosen Date: Fri, 10 May 2019 12:09:57 +0200 Subject: [PATCH 13/20] changes test I should be on landing page to correct syntax to match step definitions. Happy path all green --- app/views/listings/show.html.haml | 4 +--- features/host_can_make_offer_on_listing.feature | 2 +- features/step_definitions/assertion_steps.rb | 4 ---- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/app/views/listings/show.html.haml b/app/views/listings/show.html.haml index 55c661f..27e7dd9 100644 --- a/app/views/listings/show.html.haml +++ b/app/views/listings/show.html.haml @@ -4,8 +4,6 @@ %p Dates: #{@listing.start_date} to #{@listing.end_date} %p=@listing.pet_picture - - %h2 Create your offer = form_with(model: [ @listing, @listing.offers.build ], local: true) do |form| %p @@ -23,7 +21,7 @@ %p = form.label :price %br/ - = form.text_area :price + = form.number_field :price %p = form.submit "Create offer" diff --git a/features/host_can_make_offer_on_listing.feature b/features/host_can_make_offer_on_listing.feature index abd0662..6a61278 100644 --- a/features/host_can_make_offer_on_listing.feature +++ b/features/host_can_make_offer_on_listing.feature @@ -26,4 +26,4 @@ Feature: Host can make an offer on a listing And I fill in "Location" with "Gothenburg" And I fill in "Price" with "100kr" When I click "Create offer" button - Then I should be on the landing page \ No newline at end of file + Then I should be on landing page \ No newline at end of file diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index f9b68b3..f5a49d7 100644 --- a/features/step_definitions/assertion_steps.rb +++ b/features/step_definitions/assertion_steps.rb @@ -31,8 +31,4 @@ visit listing_path(name) end -Then("I should be on the landing page") do - pending # Write code here that turns the phrase above into concrete actions -end - From 98f66ce1e4b9d2de15db6aaad8765be13aae0785 Mon Sep 17 00:00:00 2001 From: stefan_karlberg Date: Fri, 10 May 2019 12:21:22 +0200 Subject: [PATCH 14/20] Added new Scenario in feature test for sad path, in case fields are not filled in. --- app/controllers/offers_controller.rb | 7 ++++++- features/host_can_make_offer_on_listing.feature | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/controllers/offers_controller.rb b/app/controllers/offers_controller.rb index 5601136..a6bfb05 100644 --- a/app/controllers/offers_controller.rb +++ b/app/controllers/offers_controller.rb @@ -10,7 +10,12 @@ def new def create @listing = Listing.find(params[:listing_id]) @offer = @listing.offers.create(offer_params) - redirect_to root_path(@listing) + + if listing.persisted? + redirect_to root_path(@listing) + else + redirect_to new_listing_path, notice: "Please fill in all fields" + end end diff --git a/features/host_can_make_offer_on_listing.feature b/features/host_can_make_offer_on_listing.feature index 6a61278..5ad2ff3 100644 --- a/features/host_can_make_offer_on_listing.feature +++ b/features/host_can_make_offer_on_listing.feature @@ -17,7 +17,7 @@ Feature: Host can make an offer on a listing And I should see "2019-06-29" within "Zane" section And I should see "picture1" within "Zane" section - Scenario: + Scenario: Host can successfully create an offer When I click "Make an offer" within "Zane" section Then I should be on the "Zane" listing page Then I should see "Create your offer" @@ -26,4 +26,14 @@ Feature: Host can make an offer on a listing And I fill in "Location" with "Gothenburg" And I fill in "Price" with "100kr" When I click "Create offer" button - Then I should be on landing page \ No newline at end of file + Then I should be on landing page + + Scenario: Host can not create an offer when not all the fields are filled in. + When I click "Make an offer" within "Zane" section + Then I should be on the "Zane" listing page + Then I should see "Create your offer" + And I fill in "Name" with "Steffe" + And I fill in "Location" with "Gothenburg" + And I fill in "Price" with "100kr" + When I click "Create offer" button + Then I should see "Please fill in all fields correctly" \ No newline at end of file From 03cab9a94ce5537eedfc9c23d05cee1fe06ec45b Mon Sep 17 00:00:00 2001 From: Carrosen Date: Fri, 10 May 2019 13:42:16 +0200 Subject: [PATCH 15/20] adds if statement to create method in offers controller, adds error message saying you need to fill in all fields correctly --- app/controllers/offers_controller.rb | 8 ++++---- features/host_can_make_offer_on_listing.feature | 2 +- features/step_definitions/assertion_steps.rb | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/offers_controller.rb b/app/controllers/offers_controller.rb index a6bfb05..5666bdb 100644 --- a/app/controllers/offers_controller.rb +++ b/app/controllers/offers_controller.rb @@ -10,11 +10,11 @@ def new def create @listing = Listing.find(params[:listing_id]) @offer = @listing.offers.create(offer_params) - - if listing.persisted? - redirect_to root_path(@listing) + # binding.pry + if @offer.persisted? + redirect_to root_path else - redirect_to new_listing_path, notice: "Please fill in all fields" + redirect_to listing_path(@listing), notice: "Please fill in all fields correctly" end end diff --git a/features/host_can_make_offer_on_listing.feature b/features/host_can_make_offer_on_listing.feature index 5ad2ff3..b5185c9 100644 --- a/features/host_can_make_offer_on_listing.feature +++ b/features/host_can_make_offer_on_listing.feature @@ -16,7 +16,7 @@ Feature: Host can make an offer on a listing And I should see "2019-06-28" within "Zane" section And I should see "2019-06-29" within "Zane" section And I should see "picture1" within "Zane" section - + Scenario: Host can successfully create an offer When I click "Make an offer" within "Zane" section Then I should be on the "Zane" listing page diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index f5a49d7..0eb6200 100644 --- a/features/step_definitions/assertion_steps.rb +++ b/features/step_definitions/assertion_steps.rb @@ -31,4 +31,6 @@ visit listing_path(name) end - +# Then("stop") do +# binding.pry +# end From 0fc9693fa58c4ace5c533298c836183b4baf526f Mon Sep 17 00:00:00 2001 From: stefan_karlberg Date: Fri, 10 May 2019 13:52:20 +0200 Subject: [PATCH 16/20] Changed syntax in create method, added listing in Factory bot --- app/controllers/offers_controller.rb | 2 +- features/step_definitions/assertion_steps.rb | 6 +----- spec/factories/offers.rb | 1 + 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/controllers/offers_controller.rb b/app/controllers/offers_controller.rb index 5666bdb..89eba2f 100644 --- a/app/controllers/offers_controller.rb +++ b/app/controllers/offers_controller.rb @@ -10,7 +10,7 @@ def new def create @listing = Listing.find(params[:listing_id]) @offer = @listing.offers.create(offer_params) - # binding.pry + if @offer.persisted? redirect_to root_path else diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index 0eb6200..25dab61 100644 --- a/features/step_definitions/assertion_steps.rb +++ b/features/step_definitions/assertion_steps.rb @@ -29,8 +29,4 @@ Then("I should be on the {string} listing page") do |listing_name| name = Listing.find_by(pet_name: listing_name) visit listing_path(name) -end - -# Then("stop") do -# binding.pry -# end +end \ No newline at end of file diff --git a/spec/factories/offers.rb b/spec/factories/offers.rb index a05afbe..17ec0f6 100644 --- a/spec/factories/offers.rb +++ b/spec/factories/offers.rb @@ -4,5 +4,6 @@ email { "MyString" } location { "MyString" } price { 1 } + listing end end \ No newline at end of file From 052d9fc0de889233dd943eecee24b6942227888f Mon Sep 17 00:00:00 2001 From: stefan_karlberg Date: Fri, 10 May 2019 15:08:52 +0200 Subject: [PATCH 17/20] deletes unnessecery partial form and folder for offer in view. --- app/views/listings/show.html.haml | 4 +--- app/views/offers/new.html.haml | 3 --- app/views/partials/_form_offer.html.haml | 19 ------------------- 3 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 app/views/offers/new.html.haml delete mode 100644 app/views/partials/_form_offer.html.haml diff --git a/app/views/listings/show.html.haml b/app/views/listings/show.html.haml index 27e7dd9..05f4006 100644 --- a/app/views/listings/show.html.haml +++ b/app/views/listings/show.html.haml @@ -23,6 +23,4 @@ %br/ = form.number_field :price %p - = form.submit "Create offer" - - = link_to 'Back', root_path \ No newline at end of file + = form.submit "Create offer" \ No newline at end of file diff --git a/app/views/offers/new.html.haml b/app/views/offers/new.html.haml deleted file mode 100644 index 1bc955d..0000000 --- a/app/views/offers/new.html.haml +++ /dev/null @@ -1,3 +0,0 @@ -%h1 Create your offer - -= render "./partials/form_offer.html.haml" \ No newline at end of file diff --git a/app/views/partials/_form_offer.html.haml b/app/views/partials/_form_offer.html.haml deleted file mode 100644 index 0601d5a..0000000 --- a/app/views/partials/_form_offer.html.haml +++ /dev/null @@ -1,19 +0,0 @@ -= form_with model: @offer, local: true to |form| - %p - = form.label :name - %br/ - = form.text_field :name - %p - = form.label :email - %br/ - = form.text_field :email - %p - = form.label :location - %br/ - = form.text_area :location - %p - = form.label :price - %br/ - = form.text_area :price - %p - = form.submit "Create offer" From 793351c422ed429e62e3438530c9ab1c3db90bd1 Mon Sep 17 00:00:00 2001 From: Carrosen Date: Fri, 10 May 2019 15:59:43 +0200 Subject: [PATCH 18/20] adds associations in specs between the offers and listing, deletes irrelevant step definition, deletes background steps in feature --- features/host_can_make_offer_on_listing.feature | 7 +------ features/step_definitions/assertion_steps.rb | 4 ---- spec/models/listing_spec.rb | 4 ++++ spec/models/offer_spec.rb | 4 ++++ 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/features/host_can_make_offer_on_listing.feature b/features/host_can_make_offer_on_listing.feature index b5185c9..698e913 100644 --- a/features/host_can_make_offer_on_listing.feature +++ b/features/host_can_make_offer_on_listing.feature @@ -10,14 +10,9 @@ Feature: Host can make an offer on a listing | Carla | Stockholm | I love cats! | 2019-05-28 | 2019-06-01 | picture2 | When I visit the landing page - Then I should see "Zane" - And I should see "Gothenburg" within "Zane" section - And I should see "I'm nice" within "Zane" section - And I should see "2019-06-28" within "Zane" section - And I should see "2019-06-29" within "Zane" section - And I should see "picture1" within "Zane" section Scenario: Host can successfully create an offer + Then I should see "Zane" When I click "Make an offer" within "Zane" section Then I should be on the "Zane" listing page Then I should see "Create your offer" diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index 25dab61..f6da066 100644 --- a/features/step_definitions/assertion_steps.rb +++ b/features/step_definitions/assertion_steps.rb @@ -22,10 +22,6 @@ expect(current_path).to eq root_path end -Then("I should be on offer page") do - expect(current_path).to eq new_listing_offer_path -end - Then("I should be on the {string} listing page") do |listing_name| name = Listing.find_by(pet_name: listing_name) visit listing_path(name) diff --git a/spec/models/listing_spec.rb b/spec/models/listing_spec.rb index 795f43e..4c3ad14 100644 --- a/spec/models/listing_spec.rb +++ b/spec/models/listing_spec.rb @@ -20,6 +20,10 @@ it { is_expected.to validate_presence_of :pet_picture } end + describe 'Associations' do + it { is_expected.to have_many(:offers)} + end + describe 'Factory' do it 'should have a valid Factory' do expect(FactoryBot.create(:listing)).to be_valid diff --git a/spec/models/offer_spec.rb b/spec/models/offer_spec.rb index d7f639b..87098af 100644 --- a/spec/models/offer_spec.rb +++ b/spec/models/offer_spec.rb @@ -15,6 +15,10 @@ it { is_expected.to validate_presence_of :location } it { is_expected.to validate_presence_of :price } end + + describe 'Associations' do + it { is_expected.to belong_to(:listing)} + end describe 'Factory' do it 'should have a valid Factory' do From 1458b1c95160358f723817dcb8ca530c3e09560d Mon Sep 17 00:00:00 2001 From: Carrosen Date: Fri, 10 May 2019 16:21:44 +0200 Subject: [PATCH 19/20] changes assertion step to expect page to be listing_path --- features/step_definitions/assertion_steps.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index f6da066..c6436cb 100644 --- a/features/step_definitions/assertion_steps.rb +++ b/features/step_definitions/assertion_steps.rb @@ -24,5 +24,5 @@ Then("I should be on the {string} listing page") do |listing_name| name = Listing.find_by(pet_name: listing_name) - visit listing_path(name) + expect(current_path).to eq listing_path(name) end \ No newline at end of file From 24bec19093b4f3b318317c4100f0bf35275a8e26 Mon Sep 17 00:00:00 2001 From: Carrosen Date: Fri, 10 May 2019 17:02:09 +0200 Subject: [PATCH 20/20] took away instance variable in method for new, changed naming in feature test --- app/controllers/offers_controller.rb | 2 +- features/host_can_make_offer_on_listing.feature | 7 +++---- features/step_definitions/basic_steps.rb | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/controllers/offers_controller.rb b/app/controllers/offers_controller.rb index 89eba2f..4f9d85c 100644 --- a/app/controllers/offers_controller.rb +++ b/app/controllers/offers_controller.rb @@ -4,7 +4,7 @@ def index end def new - @offer = Offer.new(offer_params) + offer = Offer.new(offer_params) end def create diff --git a/features/host_can_make_offer_on_listing.feature b/features/host_can_make_offer_on_listing.feature index 698e913..d1fb116 100644 --- a/features/host_can_make_offer_on_listing.feature +++ b/features/host_can_make_offer_on_listing.feature @@ -12,11 +12,10 @@ Feature: Host can make an offer on a listing When I visit the landing page Scenario: Host can successfully create an offer - Then I should see "Zane" When I click "Make an offer" within "Zane" section Then I should be on the "Zane" listing page - Then I should see "Create your offer" - And I fill in "Name" with "Steffe" + And I should see "Create your offer" + When I fill in "Name" with "Steffe" And I fill in "Email" with "steffe@gmail.com" And I fill in "Location" with "Gothenburg" And I fill in "Price" with "100kr" @@ -26,7 +25,7 @@ Feature: Host can make an offer on a listing Scenario: Host can not create an offer when not all the fields are filled in. When I click "Make an offer" within "Zane" section Then I should be on the "Zane" listing page - Then I should see "Create your offer" + And I should see "Create your offer" And I fill in "Name" with "Steffe" And I fill in "Location" with "Gothenburg" And I fill in "Price" with "100kr" diff --git a/features/step_definitions/basic_steps.rb b/features/step_definitions/basic_steps.rb index 11b5bb0..75a13ac 100644 --- a/features/step_definitions/basic_steps.rb +++ b/features/step_definitions/basic_steps.rb @@ -19,10 +19,10 @@ end When("I click on {string} within {string} section") do |content, section| -name = Listing.find_by(pet_name: section) -dom_section = "#listing_#{name.id}" -within(dom_section) do - expect(page).to have_content content + name = Listing.find_by(pet_name: section) + dom_section = "#listing_#{name.id}" + within(dom_section) do + expect(page).to have_content content end end