Permalink
Browse files

deck tests. associations beautiful factory

  • Loading branch information...
1 parent 3bf32b8 commit c1332f01df477dabc6e0e40e8e8ff9519b17ee0d @patrickdet patrickdet committed Apr 12, 2012
Showing with 19 additions and 3 deletions.
  1. +3 −0 app/models/deck.rb
  2. +2 −0 app/models/user.rb
  3. +2 −2 spec/factories/decks.rb
  4. +11 −1 spec/models/deck_spec.rb
  5. +1 −0 spec/models/user_spec.rb
View
@@ -1,2 +1,5 @@
class Deck < ActiveRecord::Base
+ belongs_to :user
+
+ attr_accessible :title, :description
end
View
@@ -8,4 +8,6 @@ class User < ActiveRecord::Base
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
validates :username, :email, presence: true, uniqueness: true
+
+ has_many :decks
end
@@ -3,7 +3,7 @@
FactoryGirl.define do
factory :deck do
user_id 1
- title "MyString"
- description "MyText"
+ title "Flux capacitor"
+ description "The flux capacitor, which consists of a regularly squared compartment with three flashing Geissler style-tubes (arranged in a \"Y\" configuration), is described by Doc as \"what makes time travel possible.\" The device is the core component of the time machine."
end
end
@@ -1,5 +1,15 @@
require 'spec_helper'
describe Deck do
- pending "add some examples to (or delete) #{__FILE__}"
+ it { should_not allow_mass_assignment_of :created_at }
+ it { should_not allow_mass_assignment_of :updated_at }
+ it { should belong_to(:user) }
+ it { should allow_mass_assignment_of :title }
+ it { should allow_mass_assignment_of :description }
+
+ context "fresh out of the factory" do
+ subject { FactoryGirl.create(:deck) }
+
+ it { should be_valid }
+ end
end
@@ -5,6 +5,7 @@
it { should_not allow_mass_assignment_of :updated_at }
it { should validate_presence_of(:username) }
it { should validate_presence_of(:email) }
+ it { should have_many(:decks) }
context "given there exist already some other" do
# validate_uniqueness_of requires at least one database entry

0 comments on commit c1332f0

Please sign in to comment.