Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
add base models
Browse files Browse the repository at this point in the history
  • Loading branch information
kopchak committed Jun 7, 2016
1 parent dbd83f0 commit 7d8d5cf
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,4 @@ DEPENDENCIES
shoulda-matchers (~> 3.1)

BUNDLED WITH
1.12.4
1.12.5
2 changes: 2 additions & 0 deletions app/models/shareconomy/listing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module Shareconomy
class Listing < ActiveRecord::Base
belongs_to :user
belongs_to :category
has_one :location
has_many :ratings
has_many :orders

validates :title, :description, :price, :user, :category, presence: true
Expand Down
7 changes: 7 additions & 0 deletions app/models/shareconomy/location.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Shareconomy
class Location < ActiveRecord::Base
belongs_to :listing

validates :state, :city, :district, :street, :zip_code, :listing, presence: true
end
end
7 changes: 7 additions & 0 deletions app/models/shareconomy/rating.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Shareconomy
class Rating < ActiveRecord::Base
belongs_to :listing

validates :title, :content, :value, :listing, presence: true
end
end
14 changes: 14 additions & 0 deletions db/migrate/20160606110034_create_shareconomy_locations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateShareconomyLocations < ActiveRecord::Migration
def change
create_table :shareconomy_locations do |t|
t.string :state
t.string :city
t.string :district
t.string :street
t.string :zip_code
t.integer :listing_id, index: true

t.timestamps null: false
end
end
end
13 changes: 13 additions & 0 deletions db/migrate/20160606112140_create_shareconomy_ratings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateShareconomyRatings < ActiveRecord::Migration
def change
create_table :shareconomy_ratings do |t|
t.string :title
t.text :content
t.integer :value
t.integer :listing_id, index: true
t.integer :user_id, index: true

t.timestamps null: false
end
end
end
6 changes: 6 additions & 0 deletions spec/dummy/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ default: &default
development:
<<: *default
database: dummy_development
host: localhost
user: postgres
password: root

# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
Expand Down Expand Up @@ -58,6 +61,9 @@ development:
test:
<<: *default
database: dummy_test
host: localhost
user: postgres
password: root

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
Expand Down
26 changes: 26 additions & 0 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@
add_index "shareconomy_listings", ["category_id"], name: "index_shareconomy_listings_on_category_id", using: :btree
add_index "shareconomy_listings", ["user_id"], name: "index_shareconomy_listings_on_user_id", using: :btree

create_table "shareconomy_locations", force: :cascade do |t|
t.string "state"
t.string "city"
t.string "district"
t.string "street"
t.string "zip_code"
t.integer "listing_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "shareconomy_locations", ["listing_id"], name: "index_shareconomy_locations_on_listing_id", using: :btree

create_table "shareconomy_messages", force: :cascade do |t|
t.integer "sender_id"
t.integer "recipient_id"
Expand All @@ -61,6 +74,19 @@
add_index "shareconomy_orders", ["listing_id"], name: "index_shareconomy_orders_on_listing_id", using: :btree
add_index "shareconomy_orders", ["seller_id"], name: "index_shareconomy_orders_on_seller_id", using: :btree

create_table "shareconomy_ratings", force: :cascade do |t|
t.string "title"
t.text "content"
t.integer "value"
t.integer "listing_id"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "shareconomy_ratings", ["listing_id"], name: "index_shareconomy_ratings_on_listing_id", using: :btree
add_index "shareconomy_ratings", ["user_id"], name: "index_shareconomy_ratings_on_user_id", using: :btree

create_table "shareconomy_users", force: :cascade do |t|
t.string "provider", default: "email", null: false
t.string "uid", default: "", null: false
Expand Down
13 changes: 13 additions & 0 deletions spec/models/category_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'rails_helper'

module Shareconomy
RSpec.describe Category, type: :model do
context 'relation' do
it { should have_many(:listings) }
end

context 'validations' do
it { should validate_presence_of(:title) }
end
end
end
21 changes: 21 additions & 0 deletions spec/models/listing_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'rails_helper'

module Shareconomy
RSpec.describe Listing, type: :model do
context 'relation' do
it { should belong_to(:user) }
it { should belong_to(:category) }
it { should have_one(:location) }
it { should have_many(:ratings) }
it { should have_many(:orders) }
end

context 'validations' do
it { should validate_presence_of(:user) }
it { should validate_presence_of(:title) }
it { should validate_presence_of(:price) }
it { should validate_presence_of(:category) }
it { should validate_presence_of(:description) }
end
end
end
18 changes: 18 additions & 0 deletions spec/models/location_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'rails_helper'

module Shareconomy
RSpec.describe Location, type: :model do
context 'relation' do
it { should belong_to(:listing) }
end

context 'validations' do
it { should validate_presence_of(:state) }
it { should validate_presence_of(:city) }
it { should validate_presence_of(:district) }
it { should validate_presence_of(:street) }
it { should validate_presence_of(:zip_code) }
it { should validate_presence_of(:listing) }
end
end
end
16 changes: 16 additions & 0 deletions spec/models/rating_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'rails_helper'

module Shareconomy
RSpec.describe Rating, type: :model do
context 'relation' do
it { should belong_to(:listing) }
end

context 'validations' do
it { should validate_presence_of(:title) }
it { should validate_presence_of(:listing) }
it { should validate_presence_of(:content) }
it { should validate_presence_of(:value) }
end
end
end
6 changes: 0 additions & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,16 @@
# get run.
config.filter_run :focus
config.run_all_when_everything_filtered = true
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. We recommend
# you configure your source control system to ignore this file.
config.example_status_persistence_file_path = "spec/examples.txt"
# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
config.disable_monkey_patching!
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
Expand All @@ -71,18 +68,15 @@
# (e.g. via a command-line flag).
config.default_formatter = 'doc'
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
Expand Down

0 comments on commit 7d8d5cf

Please sign in to comment.