Last active
February 3, 2018 21:01
-
-
Save sicktastic/29cbdc55aa82ec9c364d6e3b2242e593 to your computer and use it in GitHub Desktop.
Clean, Organized, Mirror
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create_table "students", id: :serial, force: :cascade do |t| | |
t.string "birth_year", limit: 255, null: false | |
t.string "country", limit: 255, null: false | |
t.string "first_name", limit: 255, null: false | |
t.string "last_name", limit: 255, null: false | |
t.string "student_status", limit: 255 | |
t.text "story", null: false | |
t.integer "organization_id" | |
t.index ["organization_id"], name: "index_students_on_organization_id" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student < ApplicationRecord | |
belongs_to :organization | |
has_many :payments | |
has_many :student_timelines | |
has_many :subscriptions | |
has_many :users, through: :subscriptions | |
validates :birth_year, :first_name, :last_name, :country, length: {maximum: 255}, presence: true | |
validates :story, presence: true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rails_helper" | |
describe Student do | |
context "associations" do | |
it { should belong_to(:organization) } | |
it { should have_many(:payments) } | |
it { should have_many(:student_timelines) } | |
it { should have_many(:subscriptions) } | |
it { should have_many(:users).through(:subscriptions) } | |
end | |
context "validations" do | |
it { should validate_presence_of(:birth_year) } | |
it { should validate_presence_of(:country) } | |
it { should validate_presence_of(:first_name) } | |
it { should validate_presence_of(:last_name) } | |
it { should validate_presence_of(:story) } | |
it { should validate_length_of(:birth_year).is_at_most(255) } | |
it { should validate_length_of(:country).is_at_most(255) } | |
it { should validate_length_of(:first_name).is_at_most(255) } | |
it { should validate_length_of(:last_name).is_at_most(255) } | |
end | |
end |
Author
sicktastic
commented
Feb 3, 2018
- Clean spaces to distinguish different aspects of code
- Alphabetically ordered
- Model validation reflects database constraints.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment