Skip to content

Commit

Permalink
add messages resource
Browse files Browse the repository at this point in the history
  • Loading branch information
gouravthakur39 committed Sep 6, 2019
1 parent 089c750 commit 48f1f7e
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/models/message.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Message < ApplicationRecord
belongs_to :user
validates :body, presence: true
end
4 changes: 3 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class User < ApplicationRecord
validates :username, presence: true, length: {minimum: 3, maximum: 15}
validates :username, presence: true, length: {minimum: 3, maximum: 15},
uniqueness: {case_sensitive: false}
has_many :messages
has_secure_password
end
9 changes: 9 additions & 0 deletions db/migrate/20190906082549_create_messages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateMessages < ActiveRecord::Migration[5.2]
def change
create_table :messages do |t|
t.text :body
t.integer :user_id
t.timestamps
end
end
end
9 changes: 8 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_09_06_062434) do
ActiveRecord::Schema.define(version: 2019_09_06_082549) do

create_table "messages", force: :cascade do |t|
t.text "body"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "users", force: :cascade do |t|
t.string "username"
Expand Down
11 changes: 10 additions & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@
User.create(username: "Sourav", password: "password")
User.create(username: "Sonia", password: "password")
User.create(username: "Manisha", password: "password")
User.create(username: "Chintu", password: "password")
User.create(username: "Chintu", password: "password")


Message.create(body: "Test message from 1", user: User.find(1))
Message.create(body: "Test message from 2 again ", user: User.find(2))
Message.create(body: "Test message 3", user: User.find(3))
Message.create(body: "Test message 4", user: User.find(4))
Message.create(body: "Test message 5", user: User.find(5))
Message.create(body: "Test message 6", user: User.find(6))
Message.create(body: "Test message 7", user: User.find(7))
11 changes: 11 additions & 0 deletions test/fixtures/messages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
7 changes: 7 additions & 0 deletions test/models/message_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class MessageTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 48f1f7e

Please sign in to comment.