0
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
0
describe Association do
0
- :foreign_model_id => "1",
0
- :association_type => "has_many"
0
- @association = Association.new
0
- it "should create a new instance given valid attributes" do
0
- Association.create!(@valid_attributes)
0
- it "should belong to model" do
0
- @association.should belong_to(:model)
0
- it "should belong to foreign_model" do
0
- @association.should belong_to(:foreign_model)
0
+ it_should_be_createable :with => {:model_id => 1, :foreign_model_id => 1, :association_type => 'has_many'}
0
- it "should validate presence of association_type" do
0
- @association.should validate_presence_of(:association_type)
0
+ it_should_validate_presence_of :model_id, :foreign_model_id, :association_type
0
+ it_should_validate_inclusion_of :association_type, :in => %w(has_many has_one belongs_to has_and_belongs_to_many)
0
- describe "the association_type" do
0
- @association = Association.new(:model_id => "1", :foreign_model_id => "2")
0
- #TODO: Write a custom matcher for these
0
- it "may be has_many" do
0
- @association.should_not be_valid
0
- @association.association_type = "has_many"
0
- @association.should be_valid
0
- it "may be has_one" do
0
- @association.should_not be_valid
0
- @association.association_type = "has_one"
0
- @association.should be_valid
0
- it "may be belongs_to" do
0
- @association.should_not be_valid
0
- @association.association_type = "belongs_to"
0
- @association.should be_valid
0
- it "may be has_and_belongs_to_many" do
0
- @association.should_not be_valid
0
- @association.association_type = "has_and_belongs_to_many"
0
- @association.should be_valid
0
- it "should not be any other value" do
0
- #FIXME: There must be a better way to do all this
0
- %w(some other values which are not allowed).each do |bad_value|
0
- @association.association_type = bad_value
0
- @association.should_not be_valid
0
+ it_should_belong_to :model, :foreign_model
Comments
No one has commented yet.