Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a9cd39c
creates features steps for owner can view offers.
boamatule May 9, 2019
91e4215
adds scenario steps and background for offers already existing. Adds …
leiter007 May 9, 2019
3ef66eb
generates offer model.
boamatule May 9, 2019
9861b73
generates reference to listing in Offer model. Adds nested routes, as…
leiter007 May 9, 2019
4817b46
adds unit test for Assosciations btw offers and listing
boamatule May 9, 2019
d410d23
adds Show listing to index view for listings. Adds background step fo…
leiter007 May 9, 2019
341392a
creates show view for listing to make listing path valid.
boamatule May 9, 2019
ce80e33
adds step definition to check for correct listing by name. 7/12 tests…
leiter007 May 9, 2019
a626344
adds offer info to be rendered in the listing show page.
boamatule May 9, 2019
68c725a
adds accept button on show view for listing. 12/12 steps green
leiter007 May 9, 2019
199a724
adds date intervals in the show page for listings;
boamatule May 9, 2019
9b10202
adds test for checking headline for Offers, and pet picture, in the s…
leiter007 May 9, 2019
b5b96fe
adds unit test for validating DB columns and presence of all attribu…
leiter007 May 9, 2019
4166a47
adds sad path test for when there are no offers on a listing it shoul…
leiter007 May 10, 2019
b8187a6
changes feature test to check for correct message if no offers exists…
leiter007 May 10, 2019
05d406d
adds steps def for viewing button
boamatule May 10, 2019
8335382
removes assertion steps from background. 18/18 tests green
leiter007 May 10, 2019
d4ceb6a
changes should matcher do the new expected syntax for offer_spec.rb a…
leiter007 May 10, 2019
925b6e7
fixes smal error in offer_spec file to make all tests pass
leiter007 May 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/listings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ def index
@listings = Listing.all
end

def show
@listing = Listing.find(params[:id])
end

def new
@listing = Listing.new
end
Expand Down
1 change: 1 addition & 0 deletions app/models/listing.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions app/models/offer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Offer < ApplicationRecord
belongs_to :listing
validates_presence_of :name, :email, :location, :price
end
1 change: 1 addition & 0 deletions app/views/listings/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
%p= listing.start_date
%p= listing.end_date
%p= listing.pet_picture
%p= link_to "Show listing", listing_path(listing)
15 changes: 15 additions & 0 deletions app/views/listings/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%h1= @listing.pet_name
%p=@listing.pet_picture
%p Dates: #{@listing.start_date} to #{@listing.end_date}

%h2 Offers
- if @listing.offers.any?
- @listing.offers.each do |offer|
.offer{id: dom_id(offer)}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the elements below supposed to be within the `.offer? div? Check the indentation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they are supposed to be nested - and with current indentation they are not.. Changing the indentation now.

%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
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Rails.application.routes.draw do
root controller: :listings, action: :index
resources :listings, only: [:new, :create]

resources :listings, only: [:new, :show, :create] do
resources :offers
end

end
12 changes: 12 additions & 0 deletions db/migrate/20190509114546_create_offers.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions db/migrate/20190509121618_add_listing_to_offers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddListingToOffers < ActiveRecord::Migration[5.2]
def change
add_reference :offers, :listing, foreign_key: true
end
end
14 changes: 13 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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_121618) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -26,4 +26,16 @@
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
t.bigint "listing_id"
t.index ["listing_id"], name: "index_offers_on_listing_id"
end

add_foreign_key "offers", "listings"
end
33 changes: 33 additions & 0 deletions features/owner_can_view_offer.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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

Background: Offers exists on a listing
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 |
And I visit the landing 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 "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"
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
Then I should be on the "Ace" listing page
And I should see "There are no offers on this listing"
13 changes: 13 additions & 0 deletions features/step_definitions/assertion_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,3 +26,11 @@
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 |listing_name|
name = Listing.find_by(pet_name: listing_name)
visit listing_path(name)
end



8 changes: 8 additions & 0 deletions features/step_definitions/basic_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@

Then "stop" do
binding.pry
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
9 changes: 9 additions & 0 deletions features/step_definitions/object_creation_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@
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|
listing_offer = Listing.find_or_create_by(pet_name: offer[:listing])
FactoryBot.create(:offer, offer
.except('listing')
.merge(listing: listing_offer))
end
end
9 changes: 9 additions & 0 deletions spec/factories/offers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FactoryBot.define do
factory :offer do
name { "MyString" }
email { "MyString" }
location { "MyString" }
price { 1 }
listing
end
end
4 changes: 4 additions & 0 deletions spec/models/listing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
it { is_expected.to validate_presence_of :end_date }
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
Expand Down
28 changes: 28 additions & 0 deletions spec/models/offer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +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 { is_expected.to belong_to(:listing)}
end

describe 'Factory' do
it 'should have a valid Factory' do
expect(FactoryBot.create(:offer)).to be_valid
end
end
end