From a9cd39c7ea51ff14a20954d0e49a0fc1b5f55b59 Mon Sep 17 00:00:00 2001 From: boa Date: Thu, 9 May 2019 12:17:28 +0200 Subject: [PATCH 01/19] creates features steps for owner can view offers. adds step_definitions. --- db/schema.rb | 25 +++++++++++++++++++++++- features/owner_can_view_offer.feature | 9 +++++++++ features/step_definitions/basic_steps.rb | 8 ++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 features/owner_can_view_offer.feature diff --git a/db/schema.rb b/db/schema.rb index 5688d75..58a6739 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_08_182912) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -26,4 +26,27 @@ t.string "pet_picture" end + create_table "profiles", force: :cascade do |t| + t.string "create" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "name" + t.string "location" + t.integer "price" + t.string "description" + t.string "picture" + end + + create_table "users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + end + end diff --git a/features/owner_can_view_offer.feature b/features/owner_can_view_offer.feature new file mode 100644 index 0000000..41d621b --- /dev/null +++ b/features/owner_can_view_offer.feature @@ -0,0 +1,9 @@ +Feature: Owner can view offers on Listing page + As a cat owner, + In order to choose host for my cat + I need to be able to view the offers for my listing + + Scenario: Owner can click on listing and see correct offers in that listing + Given I visit the landing page + When I click "show" within "Leif" + Then I should be on the "Leif" listing page \ No newline at end of file diff --git a/features/step_definitions/basic_steps.rb b/features/step_definitions/basic_steps.rb index fe545fd..c38b259 100644 --- a/features/step_definitions/basic_steps.rb +++ b/features/step_definitions/basic_steps.rb @@ -20,4 +20,12 @@ Then "stop" do binding.pry +end + +When("I click {string} within {string}") do |string, string2| + pending # Write code here that turns the phrase above into concrete actions +end + +Then("I should be on the {string} listing page") do |string| + pending # Write code here that turns the phrase above into concrete actions end \ No newline at end of file From 91e421581a29840b25204bba1f36271c035e0ee6 Mon Sep 17 00:00:00 2001 From: felix_bonnier Date: Thu, 9 May 2019 13:27:56 +0200 Subject: [PATCH 02/19] adds scenario steps and background for offers already existing. Adds missing step definitions to basic_steps, assertion_steps and object_creation_steps. --- db/schema.rb | 25 +------------------ features/owner_can_view_offer.feature | 17 +++++++++++-- features/step_definitions/assertion_steps.rb | 5 ++++ features/step_definitions/basic_steps.rb | 6 +---- .../step_definitions/object_creation_steps.rb | 6 +++++ 5 files changed, 28 insertions(+), 31 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 58a6739..5688d75 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_182912) do +ActiveRecord::Schema.define(version: 2019_05_08_150729) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -26,27 +26,4 @@ t.string "pet_picture" end - create_table "profiles", force: :cascade do |t| - t.string "create" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "name" - t.string "location" - t.integer "price" - t.string "description" - t.string "picture" - end - - create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["email"], name: "index_users_on_email", unique: true - t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true - end - end diff --git a/features/owner_can_view_offer.feature b/features/owner_can_view_offer.feature index 41d621b..1577457 100644 --- a/features/owner_can_view_offer.feature +++ b/features/owner_can_view_offer.feature @@ -3,7 +3,20 @@ Feature: Owner can view offers on Listing page In order to choose host for my cat I need to be able to view the offers for my listing + Background: Listing and offer exists + # Given the following listings exist + # | pet_name | pet_location | pet_description | start_date | end_date | pet_picture | + # | Leif | Gothenburg | I'm nice | 2019-06-28 | 2019-06-29 | picture1 | + + Given the following offers exists on a listing + | name | email | price | listing ID | + | Felix | Gothenburg | 100 | 1 | + Scenario: Owner can click on listing and see correct offers in that listing Given I visit the landing page - When I click "show" within "Leif" - Then I should be on the "Leif" listing page \ No newline at end of file + When I click "Show" within "Leif" offer + Then I should be on the "Leif" listing page + And I should see "Felix" + And I should see "Gothenburg" + And I should see "100 kr" + And I should see "Accept offer" \ No newline at end of file diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index 128a3b0..37cb0e0 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 the {string} listing page") do |string| + 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 c38b259..26385e2 100644 --- a/features/step_definitions/basic_steps.rb +++ b/features/step_definitions/basic_steps.rb @@ -22,10 +22,6 @@ binding.pry end -When("I click {string} within {string}") do |string, string2| - pending # Write code here that turns the phrase above into concrete actions -end - -Then("I should be on the {string} listing page") do |string| +When("I click {string} within {string} offer") do |string, string2| pending # Write code here that turns the phrase above into concrete actions end \ No newline at end of file diff --git a/features/step_definitions/object_creation_steps.rb b/features/step_definitions/object_creation_steps.rb index 91a52d3..1515829 100644 --- a/features/step_definitions/object_creation_steps.rb +++ b/features/step_definitions/object_creation_steps.rb @@ -2,4 +2,10 @@ table.hashes.each do |listing| FactoryBot.create(:listing, listing) end +end + +Given("the following offers exists on a listing") do |table| + table.hashes.each do |offer| + Offer.create!(offer) + end end \ No newline at end of file From 3ef66eb0519a6df00cf0f71e27e95e001c03b8b7 Mon Sep 17 00:00:00 2001 From: boa Date: Thu, 9 May 2019 13:49:46 +0200 Subject: [PATCH 03/19] generates offer model. --- app/models/offer.rb | 2 ++ db/migrate/20190509114546_create_offers.rb | 12 ++++++++ db/schema.rb | 34 +++++++++++++++++++++- spec/factories/offers.rb | 8 +++++ spec/models/offer_spec.rb | 5 ++++ 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 app/models/offer.rb create mode 100644 db/migrate/20190509114546_create_offers.rb create mode 100644 spec/factories/offers.rb create mode 100644 spec/models/offer_spec.rb 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/db/migrate/20190509114546_create_offers.rb b/db/migrate/20190509114546_create_offers.rb new file mode 100644 index 0000000..fa06fc4 --- /dev/null +++ b/db/migrate/20190509114546_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..fdae53d 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_114546) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -26,4 +26,36 @@ 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 + + create_table "profiles", force: :cascade do |t| + t.string "create" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "name" + t.string "location" + t.integer "price" + t.string "description" + t.string "picture" + end + + create_table "users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + 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 9861b732d96384b5e786443a70d51e71177d2e8c Mon Sep 17 00:00:00 2001 From: felix_bonnier Date: Thu, 9 May 2019 14:34:59 +0200 Subject: [PATCH 04/19] generates reference to listing in Offer model. Adds nested routes, association and factory bot for Offer. 2/9 tests green --- app/models/listing.rb | 1 + app/models/offer.rb | 1 + config/routes.rb | 6 +++- .../20190509121618_add_listing_to_offers.rb | 5 ++++ db/schema.rb | 28 +++---------------- features/owner_can_view_offer.feature | 11 +++----- .../step_definitions/object_creation_steps.rb | 5 +++- spec/factories/offers.rb | 1 + 8 files changed, 25 insertions(+), 33 deletions(-) create mode 100644 db/migrate/20190509121618_add_listing_to_offers.rb diff --git a/app/models/listing.rb b/app/models/listing.rb index ce2f2ed..ef65d40 100644 --- a/app/models/listing.rb +++ b/app/models/listing.rb @@ -1,3 +1,4 @@ class Listing < ApplicationRecord + has_many :offers validates_presence_of :pet_name, :pet_location, :pet_description, :start_date, :end_date, :pet_picture 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/config/routes.rb b/config/routes.rb index 1fd0c3f..a943859 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,8 @@ 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/20190509121618_add_listing_to_offers.rb b/db/migrate/20190509121618_add_listing_to_offers.rb new file mode 100644 index 0000000..fef522d --- /dev/null +++ b/db/migrate/20190509121618_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 fdae53d..bea9d07 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_114546) do +ActiveRecord::Schema.define(version: 2019_05_09_121618) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -33,29 +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 - create_table "profiles", force: :cascade do |t| - t.string "create" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "name" - t.string "location" - t.integer "price" - t.string "description" - t.string "picture" - end - - create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["email"], name: "index_users_on_email", unique: true - t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true - end - + add_foreign_key "offers", "listings" end diff --git a/features/owner_can_view_offer.feature b/features/owner_can_view_offer.feature index 1577457..00b33b6 100644 --- a/features/owner_can_view_offer.feature +++ b/features/owner_can_view_offer.feature @@ -3,20 +3,17 @@ Feature: Owner can view offers on Listing page In order to choose host for my cat I need to be able to view the offers for my listing - Background: Listing and offer exists - # Given the following listings exist - # | pet_name | pet_location | pet_description | start_date | end_date | pet_picture | - # | Leif | Gothenburg | I'm nice | 2019-06-28 | 2019-06-29 | picture1 | - + Background: Offers exists on a listing Given the following offers exists on a listing - | name | email | price | listing ID | - | Felix | Gothenburg | 100 | 1 | + | name | email | location | price | listing | + | Felix | felix@craft.se | Gothenburg | 100 | Leif | Scenario: Owner can click on listing and see correct offers in that listing Given I visit the landing page When I click "Show" within "Leif" offer Then I should be on the "Leif" listing page And I should see "Felix" + And I should see "felix@craft.se" And I should see "Gothenburg" And I should see "100 kr" And I should see "Accept offer" \ No newline at end of file diff --git a/features/step_definitions/object_creation_steps.rb b/features/step_definitions/object_creation_steps.rb index 1515829..c3218e8 100644 --- a/features/step_definitions/object_creation_steps.rb +++ b/features/step_definitions/object_creation_steps.rb @@ -6,6 +6,9 @@ Given("the following offers exists on a listing") do |table| table.hashes.each do |offer| - Offer.create!(offer) + listing_offer = Listing.find_or_create_by(pet_name: offer[:listing]) + FactoryBot.create(:offer, offer + .except('listing') + .merge(listing: listing_offer)) end end \ No newline at end of file diff --git a/spec/factories/offers.rb b/spec/factories/offers.rb index 99730aa..74eee26 100644 --- a/spec/factories/offers.rb +++ b/spec/factories/offers.rb @@ -4,5 +4,6 @@ email { "MyString" } location { "MyString" } price { 1 } + listing end end From 4817b46715a493d4ba9d7b8a6794922f902f6867 Mon Sep 17 00:00:00 2001 From: boa Date: Thu, 9 May 2019 14:49:24 +0200 Subject: [PATCH 05/19] adds unit test for Assosciations btw offers and listing --- db/schema.rb | 23 +++++++++++++++++++++++ spec/models/listing_spec.rb | 3 +++ spec/models/offer_spec.rb | 4 +++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index bea9d07..f2129f3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -37,5 +37,28 @@ t.index ["listing_id"], name: "index_offers_on_listing_id" end + create_table "profiles", force: :cascade do |t| + t.string "create" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "name" + t.string "location" + t.integer "price" + t.string "description" + t.string "picture" + end + + create_table "users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + end + add_foreign_key "offers", "listings" end diff --git a/spec/models/listing_spec.rb b/spec/models/listing_spec.rb index 795f43e..2bafec6 100644 --- a/spec/models/listing_spec.rb +++ b/spec/models/listing_spec.rb @@ -19,6 +19,9 @@ it { is_expected.to validate_presence_of :end_date } it { is_expected.to validate_presence_of :pet_picture } end + describe 'Asssociations' do + it { should have_many(:offers)} + end describe 'Factory' do it 'should have a valid Factory' do diff --git a/spec/models/offer_spec.rb b/spec/models/offer_spec.rb index c75384e..c046da5 100644 --- a/spec/models/offer_spec.rb +++ b/spec/models/offer_spec.rb @@ -1,5 +1,7 @@ require 'rails_helper' RSpec.describe Offer, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + describe 'Associations' do + it { should belong_to(:listing)} + end end From d410d232d9ef82987067d1a69327a857983aa79d Mon Sep 17 00:00:00 2001 From: felix_bonnier Date: Thu, 9 May 2019 15:56:58 +0200 Subject: [PATCH 06/19] adds Show listing to index view for listings. Adds background step for already created listing. Adds step definition for finding 'Show listing' link within the right section, in basic_steps. 5/12 steps green --- app/controllers/listings_controller.rb | 4 ++++ app/views/listings/index.html.haml | 2 ++ config/routes.rb | 2 +- db/schema.rb | 23 -------------------- features/owner_can_view_offer.feature | 17 ++++++++++----- features/step_definitions/assertion_steps.rb | 1 - features/step_definitions/basic_steps.rb | 8 +++++-- 7 files changed, 24 insertions(+), 33 deletions(-) diff --git a/app/controllers/listings_controller.rb b/app/controllers/listings_controller.rb index b0d2c6b..a7f7ec6 100644 --- a/app/controllers/listings_controller.rb +++ b/app/controllers/listings_controller.rb @@ -3,6 +3,10 @@ def index @listings = Listing.all end + def show + @listing = Listing.find(params[:id]) + end + def new @listing = Listing.new end diff --git a/app/views/listings/index.html.haml b/app/views/listings/index.html.haml index 4bf7960..a395872 100644 --- a/app/views/listings/index.html.haml +++ b/app/views/listings/index.html.haml @@ -7,3 +7,5 @@ %p= listing.start_date %p= listing.end_date %p= listing.pet_picture + %p= listing.pet_picture + %p= link_to "Show listing", listing_path(listing) diff --git a/config/routes.rb b/config/routes.rb index a943859..bab5ac8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ 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 diff --git a/db/schema.rb b/db/schema.rb index f2129f3..bea9d07 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -37,28 +37,5 @@ t.index ["listing_id"], name: "index_offers_on_listing_id" end - create_table "profiles", force: :cascade do |t| - t.string "create" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "name" - t.string "location" - t.integer "price" - t.string "description" - t.string "picture" - end - - create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["email"], name: "index_users_on_email", unique: true - t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true - end - add_foreign_key "offers", "listings" end diff --git a/features/owner_can_view_offer.feature b/features/owner_can_view_offer.feature index 00b33b6..92d0c54 100644 --- a/features/owner_can_view_offer.feature +++ b/features/owner_can_view_offer.feature @@ -4,13 +4,18 @@ Feature: Owner can view offers on Listing page I need to be able to view the offers for my listing Background: Offers exists on a listing - Given the following offers exists on a listing - | name | email | location | price | listing | - | Felix | felix@craft.se | Gothenburg | 100 | Leif | + Given the following listings exist + | pet_name | pet_location | pet_description | start_date | end_date | pet_picture | + | Leif | Gothenburg | I'm nice | 2019-06-28 | 2019-06-29 | picture1 | + And the following offers exists on a listing + | name | email | location | price | listing | + | Felix | felix@craft.se | Gothenburg | 100 | Leif | + And I visit the landing page + And I should see "Leif" + And I should see "Show listing" within "Leif" section - Scenario: Owner can click on listing and see correct offers in that listing - Given I visit the landing page - When I click "Show" within "Leif" offer + Scenario: Owner can click on listing and see correct offers in that listing + When I click "Show listing" within "Leif" section Then I should be on the "Leif" listing page And I should see "Felix" And I should see "felix@craft.se" diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index 37cb0e0..cbbbd67 100644 --- a/features/step_definitions/assertion_steps.rb +++ b/features/step_definitions/assertion_steps.rb @@ -22,7 +22,6 @@ expect(current_path).to eq root_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 end diff --git a/features/step_definitions/basic_steps.rb b/features/step_definitions/basic_steps.rb index 26385e2..4ac0939 100644 --- a/features/step_definitions/basic_steps.rb +++ b/features/step_definitions/basic_steps.rb @@ -22,6 +22,10 @@ binding.pry end -When("I click {string} within {string} offer") do |string, string2| - pending # Write code here that turns the phrase above into concrete actions +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 \ No newline at end of file From 341392ae38f0cdb08d84d3a2811a8200a9742635 Mon Sep 17 00:00:00 2001 From: boa Date: Thu, 9 May 2019 16:09:00 +0200 Subject: [PATCH 07/19] creates show view for listing to make listing path valid. 6/12 tests passing. --- app/views/listings/show.html.haml | 2 ++ db/schema.rb | 23 +++++++++++++++++++++++ spec/models/listing_spec.rb | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 app/views/listings/show.html.haml diff --git a/app/views/listings/show.html.haml b/app/views/listings/show.html.haml new file mode 100644 index 0000000..a6dd442 --- /dev/null +++ b/app/views/listings/show.html.haml @@ -0,0 +1,2 @@ +%h1 Listings#show + diff --git a/db/schema.rb b/db/schema.rb index bea9d07..f2129f3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -37,5 +37,28 @@ t.index ["listing_id"], name: "index_offers_on_listing_id" end + create_table "profiles", force: :cascade do |t| + t.string "create" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "name" + t.string "location" + t.integer "price" + t.string "description" + t.string "picture" + end + + create_table "users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + end + add_foreign_key "offers", "listings" end diff --git a/spec/models/listing_spec.rb b/spec/models/listing_spec.rb index 2bafec6..b8c488e 100644 --- a/spec/models/listing_spec.rb +++ b/spec/models/listing_spec.rb @@ -18,7 +18,7 @@ it { is_expected.to validate_presence_of :start_date } it { is_expected.to validate_presence_of :end_date } it { is_expected.to validate_presence_of :pet_picture } - end + end describe 'Asssociations' do it { should have_many(:offers)} end From ce80e3375a9353628a7a418ae1889c06935c9258 Mon Sep 17 00:00:00 2001 From: felix_bonnier Date: Thu, 9 May 2019 16:13:31 +0200 Subject: [PATCH 08/19] adds step definition to check for correct listing by name. 7/12 tests green --- db/schema.rb | 23 -------------------- features/step_definitions/assertion_steps.rb | 5 +++-- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index f2129f3..bea9d07 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -37,28 +37,5 @@ t.index ["listing_id"], name: "index_offers_on_listing_id" end - create_table "profiles", force: :cascade do |t| - t.string "create" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "name" - t.string "location" - t.integer "price" - t.string "description" - t.string "picture" - end - - create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["email"], name: "index_users_on_email", unique: true - t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true - end - add_foreign_key "offers", "listings" end diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index cbbbd67..aed5b6d 100644 --- a/features/step_definitions/assertion_steps.rb +++ b/features/step_definitions/assertion_steps.rb @@ -22,6 +22,7 @@ expect(current_path).to eq root_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 From a626344bead960f276475e03afca69155a5d9395 Mon Sep 17 00:00:00 2001 From: boa Date: Thu, 9 May 2019 16:33:40 +0200 Subject: [PATCH 09/19] adds offer info to be rendered in the listing show page. 11/12 tests passing. --- app/views/listings/show.html.haml | 8 +++++++- db/schema.rb | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/views/listings/show.html.haml b/app/views/listings/show.html.haml index a6dd442..11788dd 100644 --- a/app/views/listings/show.html.haml +++ b/app/views/listings/show.html.haml @@ -1,2 +1,8 @@ -%h1 Listings#show +%h1 Listings#show +- @listing.offers.each do |offer| + .offer{id: dom_id(offer)} + %p= offer.name + %p= offer.email + %p= offer.location + %p #{offer.price} kr diff --git a/db/schema.rb b/db/schema.rb index bea9d07..f2129f3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -37,5 +37,28 @@ t.index ["listing_id"], name: "index_offers_on_listing_id" end + create_table "profiles", force: :cascade do |t| + t.string "create" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "name" + t.string "location" + t.integer "price" + t.string "description" + t.string "picture" + end + + create_table "users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + end + add_foreign_key "offers", "listings" end From 68c725ac2ba93eac9ac7022df8dd1e988b248cb3 Mon Sep 17 00:00:00 2001 From: felix_bonnier Date: Thu, 9 May 2019 16:45:46 +0200 Subject: [PATCH 10/19] adds accept button on show view for listing. 12/12 steps green --- app/views/listings/show.html.haml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/listings/show.html.haml b/app/views/listings/show.html.haml index 11788dd..b1d21df 100644 --- a/app/views/listings/show.html.haml +++ b/app/views/listings/show.html.haml @@ -1,8 +1,8 @@ -%h1 Listings#show +%h1= @listing.pet_name - @listing.offers.each do |offer| .offer{id: dom_id(offer)} %p= offer.name %p= offer.email %p= offer.location - %p #{offer.price} kr - + %p #{offer.price} kr + %button= link_to "Accept offer", "#" \ No newline at end of file From 199a724accc251b223c147c67b7001129442e100 Mon Sep 17 00:00:00 2001 From: boa Date: Thu, 9 May 2019 20:08:29 +0200 Subject: [PATCH 11/19] adds date intervals in the show page for listings; adds features test for the intervals. Test failing... --- app/views/listings/index.html.haml | 1 - app/views/listings/show.html.haml | 2 ++ features/owner_can_view_offer.feature | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/listings/index.html.haml b/app/views/listings/index.html.haml index a395872..2c52c68 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 - %p= listing.pet_picture %p= link_to "Show listing", listing_path(listing) diff --git a/app/views/listings/show.html.haml b/app/views/listings/show.html.haml index b1d21df..a73b5d9 100644 --- a/app/views/listings/show.html.haml +++ b/app/views/listings/show.html.haml @@ -1,4 +1,6 @@ %h1= @listing.pet_name +%p Dates: #{@listing.start_date} - #{@listing.end_date} + - @listing.offers.each do |offer| .offer{id: dom_id(offer)} %p= offer.name diff --git a/features/owner_can_view_offer.feature b/features/owner_can_view_offer.feature index 92d0c54..9d346e4 100644 --- a/features/owner_can_view_offer.feature +++ b/features/owner_can_view_offer.feature @@ -17,6 +17,8 @@ Feature: Owner can view offers on Listing page Scenario: Owner can click on listing and see correct offers in that listing When I click "Show listing" within "Leif" section Then I should be on the "Leif" listing page + And I should see "Leif" + And I should see "Dates: 2019-06-28 to 2019-06-29" And I should see "Felix" And I should see "felix@craft.se" And I should see "Gothenburg" From 9b1020206508b1169a80b608463290ecca72c07b Mon Sep 17 00:00:00 2001 From: felix_bonnier Date: Thu, 9 May 2019 20:21:16 +0200 Subject: [PATCH 12/19] adds test for checking headline for Offers, and pet picture, in the show page for listing. Adds corresponding information in the show view. 16/16 steps green --- app/views/listings/show.html.haml | 4 +++- features/owner_can_view_offer.feature | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/views/listings/show.html.haml b/app/views/listings/show.html.haml index a73b5d9..6de1d7e 100644 --- a/app/views/listings/show.html.haml +++ b/app/views/listings/show.html.haml @@ -1,6 +1,8 @@ %h1= @listing.pet_name -%p Dates: #{@listing.start_date} - #{@listing.end_date} +%p=@listing.pet_picture +%p Dates: #{@listing.start_date} to #{@listing.end_date} +%h2 Offers - @listing.offers.each do |offer| .offer{id: dom_id(offer)} %p= offer.name diff --git a/features/owner_can_view_offer.feature b/features/owner_can_view_offer.feature index 9d346e4..39209a5 100644 --- a/features/owner_can_view_offer.feature +++ b/features/owner_can_view_offer.feature @@ -17,8 +17,10 @@ Feature: Owner can view offers on Listing page Scenario: Owner can click on listing and see correct offers in that listing When I click "Show listing" within "Leif" section Then I should be on the "Leif" listing page - And I should see "Leif" + And I should see "Leif" + And I should see "picture1" And I should see "Dates: 2019-06-28 to 2019-06-29" + And I should see "Offers" And I should see "Felix" And I should see "felix@craft.se" And I should see "Gothenburg" From b5b96fe9e90a7e0d881657350f15be54debe2adc Mon Sep 17 00:00:00 2001 From: felix_bonnier Date: Thu, 9 May 2019 20:50:34 +0200 Subject: [PATCH 13/19] adds unit test for validating DB columns and presence of all attributes for Offer model. Adds unit test for validating FactoryBot. Adds validation in Offer model for presence of all attributes, meaning name, email, location, price. All unit tests green --- app/models/offer.rb | 1 + spec/models/listing_spec.rb | 3 ++- spec/models/offer_spec.rb | 23 ++++++++++++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) 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/spec/models/listing_spec.rb b/spec/models/listing_spec.rb index b8c488e..f418db0 100644 --- a/spec/models/listing_spec.rb +++ b/spec/models/listing_spec.rb @@ -18,7 +18,8 @@ it { is_expected.to validate_presence_of :start_date } it { is_expected.to validate_presence_of :end_date } it { is_expected.to validate_presence_of :pet_picture } - end + end + describe 'Asssociations' do it { should have_many(:offers)} end diff --git a/spec/models/offer_spec.rb b/spec/models/offer_spec.rb index c046da5..0acefe2 100644 --- a/spec/models/offer_spec.rb +++ b/spec/models/offer_spec.rb @@ -1,7 +1,28 @@ require 'rails_helper' RSpec.describe Offer, type: :model do + 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 'Associations' do it { should belong_to(:listing)} end -end + + describe 'Factory' do + it 'should have a valid Factory' do + expect(FactoryBot.create(:offer)).to be_valid + end + end +end \ No newline at end of file From 4166a47121ae1e6b53b1e657a232ad63c7a124c2 Mon Sep 17 00:00:00 2001 From: felix_bonnier Date: Fri, 10 May 2019 09:54:21 +0200 Subject: [PATCH 14/19] adds sad path test for when there are no offers on a listing it should show message for the owner. Adds if statement and message in show.haml for listing. 24/24 tests green --- app/views/listings/show.html.haml | 9 ++++++--- features/owner_can_view_offer.feature | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/views/listings/show.html.haml b/app/views/listings/show.html.haml index 6de1d7e..e8c1863 100644 --- a/app/views/listings/show.html.haml +++ b/app/views/listings/show.html.haml @@ -3,10 +3,13 @@ %p Dates: #{@listing.start_date} to #{@listing.end_date} %h2 Offers -- @listing.offers.each do |offer| - .offer{id: dom_id(offer)} +- if @listing.offers.any? + - @listing.offers.each do |offer| + .offer{id: dom_id(offer)} %p= offer.name %p= offer.email %p= offer.location %p #{offer.price} kr - %button= link_to "Accept offer", "#" \ No newline at end of file + %button= link_to "Accept offer", "#" + +.message There are no offers on this listing \ No newline at end of file diff --git a/features/owner_can_view_offer.feature b/features/owner_can_view_offer.feature index 39209a5..8407775 100644 --- a/features/owner_can_view_offer.feature +++ b/features/owner_can_view_offer.feature @@ -7,6 +7,7 @@ Feature: Owner can view offers on Listing page Given the following listings exist | pet_name | pet_location | pet_description | start_date | end_date | pet_picture | | Leif | Gothenburg | I'm nice | 2019-06-28 | 2019-06-29 | picture1 | + | Ace | Stockholm | I'm nice | 2019-06-28 | 2019-06-29 | picture2 | And the following offers exists on a listing | name | email | location | price | listing | | Felix | felix@craft.se | Gothenburg | 100 | Leif | @@ -25,4 +26,9 @@ Feature: Owner can view offers on Listing page And I should see "felix@craft.se" And I should see "Gothenburg" And I should see "100 kr" - And I should see "Accept offer" \ No newline at end of file + And I should see "Accept offer" + + Scenario: Owner can click on listing and see "There are no offers for this listing" if that is the case + When I click "Show listing" within "Ace" section + Then I should be on the "Ace" listing page + And I should see "There are no offers on this listing" \ No newline at end of file From b8187a692b14f3db30bb054be7a16626c82ba387 Mon Sep 17 00:00:00 2001 From: felix_bonnier Date: Fri, 10 May 2019 15:32:22 +0200 Subject: [PATCH 15/19] changes feature test to check for correct message if no offers exists on a listing. Changes show.haml for listing to show correct information if no offers exists. Changed indentation for show page paragraphs to be correctly nested inside offers div. Tests 25/25 green --- app/views/listings/show.html.haml | 14 ++++++------ db/schema.rb | 23 -------------------- features/owner_can_view_offer.feature | 3 ++- features/step_definitions/assertion_steps.rb | 9 ++++---- 4 files changed, 14 insertions(+), 35 deletions(-) diff --git a/app/views/listings/show.html.haml b/app/views/listings/show.html.haml index e8c1863..33f634c 100644 --- a/app/views/listings/show.html.haml +++ b/app/views/listings/show.html.haml @@ -6,10 +6,10 @@ - if @listing.offers.any? - @listing.offers.each do |offer| .offer{id: dom_id(offer)} - %p= offer.name - %p= offer.email - %p= offer.location - %p #{offer.price} kr - %button= link_to "Accept offer", "#" - -.message There are no offers on this listing \ No newline at end of file + %p= offer.name + %p= offer.email + %p= offer.location + %p #{offer.price} kr + %p= link_to "Accept offer", "#" +- else + .message There are no offers on this listing \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index f2129f3..bea9d07 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -37,28 +37,5 @@ t.index ["listing_id"], name: "index_offers_on_listing_id" end - create_table "profiles", force: :cascade do |t| - t.string "create" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "name" - t.string "location" - t.integer "price" - t.string "description" - t.string "picture" - end - - create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["email"], name: "index_users_on_email", unique: true - t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true - end - add_foreign_key "offers", "listings" end diff --git a/features/owner_can_view_offer.feature b/features/owner_can_view_offer.feature index 8407775..c9a12b7 100644 --- a/features/owner_can_view_offer.feature +++ b/features/owner_can_view_offer.feature @@ -14,7 +14,7 @@ Feature: Owner can view offers on Listing page And I visit the landing page And I should see "Leif" And I should see "Show listing" within "Leif" section - + @javascript Scenario: Owner can click on listing and see correct offers in that listing When I click "Show listing" within "Leif" section Then I should be on the "Leif" listing page @@ -27,6 +27,7 @@ Feature: Owner can view offers on Listing page And I should see "Gothenburg" And I should see "100 kr" And I should see "Accept offer" + And I should not see "There are no offers on this listing" Scenario: Owner can click on listing and see "There are no offers for this listing" if that is the case When I click "Show listing" within "Ace" section diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index aed5b6d..149846b 100644 --- a/features/step_definitions/assertion_steps.rb +++ b/features/step_definitions/assertion_steps.rb @@ -2,6 +2,11 @@ expect(page).to have_content content end +Then("I should not see {string}") do |content| + expect(page).not_to have_content content +end + + Then("I should see {string} link") do |link| expect(page).to have_link(link) end @@ -14,10 +19,6 @@ end end -Then("I should see {string} button") do |button| - expect(page).to have_button(button) -end - Then("I should be on landing page") do expect(current_path).to eq root_path end From 05d406dc19009bebf44623656cc343b38353e711 Mon Sep 17 00:00:00 2001 From: boa Date: Fri, 10 May 2019 15:47:24 +0200 Subject: [PATCH 16/19] adds steps def for viewing button --- features/step_definitions/assertion_steps.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/features/step_definitions/assertion_steps.rb b/features/step_definitions/assertion_steps.rb index 149846b..24e02a5 100644 --- a/features/step_definitions/assertion_steps.rb +++ b/features/step_definitions/assertion_steps.rb @@ -19,6 +19,10 @@ end end +Then("I should see {string} button") do |button| + expect(page).to have_button(button) +end + Then("I should be on landing page") do expect(current_path).to eq root_path end @@ -27,3 +31,6 @@ name = Listing.find_by(pet_name: listing_name) visit listing_path(name) end + + + From 8335382d4717554df1e74b386030623628b36477 Mon Sep 17 00:00:00 2001 From: felix_bonnier Date: Fri, 10 May 2019 15:52:38 +0200 Subject: [PATCH 17/19] removes assertion steps from background. 18/18 tests green --- features/owner_can_view_offer.feature | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/features/owner_can_view_offer.feature b/features/owner_can_view_offer.feature index c9a12b7..1ce4158 100644 --- a/features/owner_can_view_offer.feature +++ b/features/owner_can_view_offer.feature @@ -12,9 +12,7 @@ Feature: Owner can view offers on Listing page | name | email | location | price | listing | | Felix | felix@craft.se | Gothenburg | 100 | Leif | And I visit the landing page - And I should see "Leif" - And I should see "Show listing" within "Leif" section - @javascript + Scenario: Owner can click on listing and see correct offers in that listing When I click "Show listing" within "Leif" section Then I should be on the "Leif" listing page From d4ceb6a7f0f93983659edac75b125736d3b608d6 Mon Sep 17 00:00:00 2001 From: felix_bonnier Date: Fri, 10 May 2019 15:56:57 +0200 Subject: [PATCH 18/19] changes should matcher do the new expected syntax for offer_spec.rb and listing_spec.rb. All unit tests green --- spec/models/listing_spec.rb | 4 ++-- spec/models/offer_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/models/listing_spec.rb b/spec/models/listing_spec.rb index f418db0..a9dd9c9 100644 --- a/spec/models/listing_spec.rb +++ b/spec/models/listing_spec.rb @@ -20,8 +20,8 @@ it { is_expected.to validate_presence_of :pet_picture } end - describe 'Asssociations' do - it { should have_many(:offers)} + describe 'Associations' do + it { is_expected.to have_many(:offers)} end describe 'Factory' do diff --git a/spec/models/offer_spec.rb b/spec/models/offer_spec.rb index 0acefe2..1e7a21e 100644 --- a/spec/models/offer_spec.rb +++ b/spec/models/offer_spec.rb @@ -17,7 +17,7 @@ end describe 'Associations' do - it { should belong_to(:listing)} + it { is_expected.to belong_to(:listing)} end describe 'Factory' do @@ -25,4 +25,4 @@ expect(FactoryBot.create(:offer)).to be_valid end end -end \ No newline at end of file +endgit stat \ No newline at end of file From 925b6e7c2747d79d09d12145e0e898af1d3276a7 Mon Sep 17 00:00:00 2001 From: felix_bonnier Date: Fri, 10 May 2019 16:02:40 +0200 Subject: [PATCH 19/19] fixes smal error in offer_spec file to make all tests pass --- spec/models/offer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/offer_spec.rb b/spec/models/offer_spec.rb index 1e7a21e..58d0c6d 100644 --- a/spec/models/offer_spec.rb +++ b/spec/models/offer_spec.rb @@ -25,4 +25,4 @@ expect(FactoryBot.create(:offer)).to be_valid end end -endgit stat \ No newline at end of file +end \ No newline at end of file