class Pyramid < ApplicationRecord validates :name, presence: true
has_many :mysteries end
| class Mystery < ApplicationRecord | |
| validates :title, presence: true | |
| belongs_to :pyramid | |
| # solve the mystery | |
| # tagline for the mystery | |
| def tagline | |
| "Come see #{title} at the #{pyramid.name}!" | |
| end | |
| def self.message | |
| 'Mysteries are scary!' | |
| end | |
| end |
| require 'rails_helper' | |
| RSpec.describe Mystery, type: :model do | |
| describe 'validations' do | |
| it 'should let you create a titled mystery' do | |
| pyramid = Pyramid.create name: 'Doesnt really matter' | |
| mystery = Mystery.create title: 'The Great Mystery of Water Erosion', pyramid: pyramid | |
| expect(mystery).to be_valid | |
| end | |
| it 'should not let you create a title-less mystery' do | |
| pyramid = Pyramid.create name: 'Doesnt really matter' | |
| mystery = Mystery.create pyramid: pyramid | |
| expect(mystery).to_not be_valid | |
| end | |
| it 'should not let you create a pyramid-less mystery' do | |
| mystery = Mystery.create title: 'the mystery' | |
| expect(mystery).to_not be_valid | |
| end | |
| end | |
| describe 'instance methods' do | |
| it 'should print out the mystery tagline' do | |
| pyramid = Pyramid.create name: 'Great Pyramid' | |
| mystery = Mystery.create title: 'The Great Mystery of Water Erosion', pyramid: pyramid | |
| expect(mystery.tagline).to eq 'Come see The Great Mystery of Water Erosion at the Great Pyramid!' | |
| mystery = Mystery.create title: "Won's Mystery of King Tut", pyramid: pyramid | |
| expect(mystery.tagline).to eq "Come see Won's Mystery of King Tut at the Great Pyramid!" | |
| end | |
| end | |
| describe 'class methods' do | |
| it 'Woooo mysteries are scary!' do | |
| expect(Mystery.message).to eq 'Mysteries are scary!' | |
| end | |
| end | |
| end |
class Pyramid < ApplicationRecord validates :name, presence: true
has_many :mysteries end
| require 'rails_helper' | |
| RSpec.describe Pyramid, type: :model do | |
| # pending "add some examples to (or delete) #{__FILE__}" | |
| describe 'creating a pyramid' do | |
| it 'should let you create a named pyramid' do | |
| pyramid = Pyramid.create name: 'Great Pyramid' | |
| # this should not be a valid pyramid | |
| # expect this pyramid to not be valid | |
| # make sure that this is not a valid pyramid | |
| expect(pyramid).to be_valid | |
| end | |
| it 'should not let you create a nameless pyramid' do | |
| pyramid = Pyramid.create | |
| expect(pyramid).to_not be_valid | |
| end | |
| end | |
| end |