Skip to content

Instantly share code, notes, and snippets.

@NimaBoscarino
Created July 15, 2019 19:29
Show Gist options
  • Save NimaBoscarino/553809efae443fa9a12c26285e0c5a45 to your computer and use it in GitHub Desktop.
Save NimaBoscarino/553809efae443fa9a12c26285e0c5a45 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment