Skip to content

Commit 1a3c66c

Browse files
committed
create housing
1 parent fb1f024 commit 1a3c66c

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

app/models/housing.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Housing < ApplicationRecord
2+
belongs_to :city
3+
belongs_to :location
4+
5+
enum housing_type: { hotel: 0, air_bnb_shared: 1, air_bnb_full: 2, cottage: 3, other: 4 }
6+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class CreateHousings < ActiveRecord::Migration[6.1]
2+
def change
3+
create_table :housings do |t|
4+
t.boolean :breakfast, null: false
5+
t.text :url, null: false
6+
t.integer :housing_type, null: false
7+
8+
t.belongs_to :city, null: false, foreign_key: true
9+
t.belongs_to :location, null: false, foreign_key: true
10+
11+
t.timestamps
12+
end
13+
end
14+
end

db/schema.rb

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/factories.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
FactoryBot.define do
2+
factory :housing do
3+
breakfast { [true, false].sample }
4+
association :city
5+
association :location
6+
url { FFaker::Internet.http_url }
7+
housing_type { 1 }
8+
end
9+
210
factory :restaurant do
311
name { FFaker::NameFR.name }
412
kitchen { FFaker::Lorem.name }

spec/models/housing_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Housing, type: :model do
4+
let(:housing) { create(:housing) }
5+
6+
it { expect(housing).to be_valid }
7+
it { should belong_to(:city) }
8+
it { should belong_to(:location) }
9+
it { should define_enum_for(:housing_type).with_values([:hotel, :air_bnb_shared ,:air_bnb_full, :cottage, :other]) }
10+
end

0 commit comments

Comments
 (0)