Skip to content

Instantly share code, notes, and snippets.

@keppy
Created July 3, 2012 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save keppy/3042484 to your computer and use it in GitHub Desktop.
Save keppy/3042484 to your computer and use it in GitHub Desktop.
Method help
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: "prop@email.com")
@opp_user = User.new(name: "Opp User", email: "opp@email.com")
@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
# 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
# models/proposition.rb
class Proposition < ActiveRecord::Base
attr_accessible :footnotes, :response, :slide, :title
belongs_to :user
end
# 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
@nuclearsandwich
Copy link

Can you add your User model code to this gist? It's likely a missing has_many/belongs_to.

@keppy
Copy link
Author

keppy commented Jul 5, 2012

@nuclearsandwich there ya go. thanks

@nuclearsandwich
Copy link

FYI you can specify multiple files per gist and use filenames for type detection: https://gist.github.com/3055431

you are getting a NoMethodError for Debate#proposition right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment