Commit 1d1c4570c7d1ef8d9cf45974ba61898c0b97c177
- Date: Sun Aug 19 15:13:41 +0000 2007
- Committer: Johan Sørensen (johan@johansorensen.com)
- Author: Johan Sørensen (johan@johansorensen.com)
- Commit SHA1: 1d1c4570c7d1ef8d9cf45974ba61898c0b97c177
- Tree SHA1: 2ff16219a7e4cc9fa66b91aa78d15ac5061c5e08
* added spec_dsl file for custom matchers
* Added basic Project model
* remove public/index.html
Revert "* added spec_dsl file for custom matchers"
This reverts commit b153a5399928578f8b88a7840b65e02257c696ef.
Conflicts:
Commit diff
| |   |
| 1 | class Project < ActiveRecord::Base |
| 2 | belongs_to :user |
| 3 | |
| 4 | validates_presence_of :name |
| 5 | end |
| toggle raw diff |
--- /dev/null
+++ b/app/models/project.rb
@@ -0,0 +1,5 @@
+class Project < ActiveRecord::Base
+ belongs_to :user
+
+ validates_presence_of :name
+end |
| |   |
| 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
| 2 | one: |
| 3 | id: 1 |
| 4 | name: MyString |
| 5 | description: MyText |
| 6 | user_id: 1 |
| 7 | created_at: 2007-08-19 16:56:36 |
| 8 | updated_at: 2007-08-19 16:56:36 |
| 9 | two: |
| 10 | id: 2 |
| 11 | name: MyString |
| 12 | description: MyText |
| 13 | user_id: 1 |
| 14 | created_at: 2007-08-19 16:56:36 |
| 15 | updated_at: 2007-08-19 16:56:36 |
| toggle raw diff |
--- /dev/null
+++ b/spec/fixtures/projects.yml
@@ -0,0 +1,15 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+ id: 1
+ name: MyString
+ description: MyText
+ user_id: 1
+ created_at: 2007-08-19 16:56:36
+ updated_at: 2007-08-19 16:56:36
+two:
+ id: 2
+ name: MyString
+ description: MyText
+ user_id: 1
+ created_at: 2007-08-19 16:56:36
+ updated_at: 2007-08-19 16:56:36 |
| |   |
| 1 | require File.dirname(__FILE__) + '/../spec_helper' |
| 2 | |
| 3 | describe Project do |
| 4 | before(:each) do |
| 5 | @project = Project.new(:name => "foo project") |
| 6 | end |
| 7 | |
| 8 | it "should have valid associations" do |
| 9 | @project.should have_valid_associations |
| 10 | end |
| 11 | |
| 12 | it "should have a name to be valid" do |
| 13 | project = Project.new |
| 14 | project.should_not be_valid |
| 15 | project.name = "foo" |
| 16 | project.should be_valid |
| 17 | end |
| 18 | end |
| toggle raw diff |
--- /dev/null
+++ b/spec/models/project_spec.rb
@@ -0,0 +1,18 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe Project do
+ before(:each) do
+ @project = Project.new(:name => "foo project")
+ end
+
+ it "should have valid associations" do
+ @project.should have_valid_associations
+ end
+
+ it "should have a name to be valid" do
+ project = Project.new
+ project.should_not be_valid
+ project.name = "foo"
+ project.should be_valid
+ end
+end |
| |   |
| 1 | module KeyserSource |
| 2 | module SpecDSL |
| 3 | # original code by caboose court3nay (?) |
| 4 | class HaveValidAssociations |
| 5 | def matches?(model) |
| 6 | @failed_association = nil |
| 7 | @model_class = model.class |
| 8 | |
| 9 | model.class.reflect_on_all_associations.each do |assoc| |
| 10 | model.send(assoc.name, true) rescue @failed_association = assoc.name |
| 11 | end |
| 12 | !@failed_association |
| 13 | end |
| 14 | |
| 15 | def failure_message |
| 16 | "invalid association \"#{@failed_association}\" on #{@model_class}" |
| 17 | end |
| 18 | end |
| 19 | |
| 20 | def have_valid_associations |
| 21 | HaveValidAssociations.new |
| 22 | end |
| 23 | end |
| 24 | end |
| toggle raw diff |
--- /dev/null
+++ b/spec/spec_dsl.rb
@@ -0,0 +1,24 @@
+module KeyserSource
+ module SpecDSL
+ # original code by caboose court3nay (?)
+ class HaveValidAssociations
+ def matches?(model)
+ @failed_association = nil
+ @model_class = model.class
+
+ model.class.reflect_on_all_associations.each do |assoc|
+ model.send(assoc.name, true) rescue @failed_association = assoc.name
+ end
+ !@failed_association
+ end
+
+ def failure_message
+ "invalid association \"#{@failed_association}\" on #{@model_class}"
+ end
+ end
+
+ def have_valid_associations
+ HaveValidAssociations.new
+ end
+ end
+end
\ No newline at end of file |