Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Feature set model display names #14

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/admin/answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
# permitted
# end

permit_params :text, :info, :question_id

end
2 changes: 1 addition & 1 deletion app/admin/ballot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
# permitted
# end

permit_params :date
permit_params :date, :admin_id

end
1 change: 1 addition & 0 deletions app/admin/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
# permitted
# end

permit_params :text, :summary, :friendly_name, :ballot_id

end
4 changes: 4 additions & 0 deletions app/models/admin_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ class AdminUser < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable

validates :email, uniqueness: true

def display_name
"#{email}"
end
end
7 changes: 7 additions & 0 deletions app/models/answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@

class Answer < ActiveRecord::Base
belongs_to :question

validates :question_id, presence: true
validates :text, presence: true

def display_name
"#{text}"
end
end
6 changes: 5 additions & 1 deletion app/models/ballot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ class Ballot < ActiveRecord::Base
belongs_to :admin_user

validates :date, presence: true
validates :admin_user, presence: true
validates :admin_user_id, presence: true

def display_name
"#{date}"
end
end
8 changes: 8 additions & 0 deletions app/models/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@

class Question < ActiveRecord::Base
belongs_to :ballot

# make sure ballot ID and text are present. Allows text, summary to be empty.
validates :ballot_id, presence: true
validates :text, presence: true

def display_name
"#{friendly_name}"
end
end
3 changes: 3 additions & 0 deletions spec/examples.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
example_id | status | run_time |
--------------------------------------- | ------ | --------------- |
./spec/models/admin_user_spec.rb[1:1:1] | passed | 0.0534 seconds |
./spec/models/answer_spec.rb[1:1] | passed | 0.10162 seconds |
./spec/models/answer_spec.rb[1:2:1] | passed | 0.01378 seconds |
./spec/models/answer_spec.rb[1:2:2] | passed | 0.01236 seconds |
./spec/models/ballot_spec.rb[1:1:1] | passed | 0.04902 seconds |
./spec/models/ballot_spec.rb[1:1:2] | passed | 0.0089 seconds |
22 changes: 22 additions & 0 deletions spec/factories/answer_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# == Schema Information
#
# Table name: answers
#
# id :integer not null, primary key
# text :text
# info :text
# question_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#

require 'faker'

FactoryGirl.define do
factory :answer do
text Faker::Lorem.sentence

# Associations
question
end
end
23 changes: 23 additions & 0 deletions spec/factories/question_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# == Schema Information
#
# Table name: questions
#
# id :integer not null, primary key
# text :text
# summary :text
# friendly_name :string
# ballot_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#

require 'faker'

FactoryGirl.define do
factory :question do
text Faker::Lorem.sentence

# Associations
ballot
end
end
17 changes: 17 additions & 0 deletions spec/models/answer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,21 @@
require 'spec_helper'

RSpec.describe Answer do
it "has a valid factory" do
expect(FactoryGirl.create(:answer)).to be_valid
end

describe 'validates' do
before(:each) { @answer = build(:answer) }

it "is invalid without an associated question id" do
@answer.question_id = nil
expect(@answer).not_to be_valid
end

it "is invalid without text" do
@answer.text = nil
expect(@answer).not_to be_valid
end
end
end
17 changes: 17 additions & 0 deletions spec/models/question_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,21 @@
require 'spec_helper'

RSpec.describe Question do
it "has a valid factory" do
expect(FactoryGirl.create(:question)).to be_valid
end

describe 'validates' do
before(:each) { @question = build(:question) }

it "is invalid without an associated ballot id" do
@question.ballot_id = nil
expect(@question).not_to be_valid
end

it "is invalid without text" do
@question.text = nil
expect(@question).not_to be_valid
end
end
end