-
-
Save nuclearsandwich/3055431 to your computer and use it in GitHub Desktop.
Method help
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
# models/debate.rb | |
class Debate < ActiveRecord::Base | |
attr_accessible :opposition_id, :proposition_id, :title | |
validates :proposition_user_id, presence: true | |
validates :proposition_id, presence: true | |
validates :title, presence: true | |
has_many :users | |
has_one :proposition | |
has_one :opposition | |
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 'spec_helper' | |
describe Debate do | |
#let(:prop_user) { FactoryGirl.create(:user) } | |
#let(:opp_user) { FactoryGirl.create(:user) } | |
before do | |
@prop_user = User.new(name: "Prop User", email: "[email protected]") | |
@opp_user = User.new(name: "Opp User", email: "[email protected]") | |
@debate = Debate.new(title: "Test Debate") | |
@prop_argument = @prop_user.proposition.build(title: "Prop Title") | |
@opp_argument = @opp_user.opposition.build(title: "Opp Title") | |
end | |
subject { @debate } | |
it { should respond_to(:title) } | |
it { should respond_to(:proposition_id) } | |
it { should respond_to(:opposition_id) } | |
describe "when the debate has no title" do | |
before { @debate.title = " " } | |
it { should_not be_valid } | |
end | |
describe "when the debate has no prop id" do | |
before { @debate.proposition_id = nil } | |
it { should_not be_valid } | |
end | |
describe "when the debate has no opp id" do | |
before { @debate.opposition_id = nil } | |
it { should_not be_valid } | |
end | |
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
# models/proposition.rb | |
class Proposition < ActiveRecord::Base | |
attr_accessible :footnotes, :response, :slide, :title | |
belongs_to :user | |
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
# User model as requested. | |
# models/user.rb --> | |
class User < ActiveRecord::Base | |
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i | |
attr_accessible :email, :name, :password, :password_confirmation | |
has_secure_password | |
has_many :propositions | |
has_many :oppositions | |
before_save { |user| user.email = email.downcase } | |
validates :email, presence: true, | |
format: { with: VALID_EMAIL_REGEX }, | |
uniqueness: { case_sensitive: false } | |
validates :name, presence: true, length: { maximum: 49 } | |
validates :password, presence: true, length: { minimum: 6 } | |
validates :password_confirmation, presence: true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks