Skip to content

Commit

Permalink
More role tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjy committed Oct 7, 2013
1 parent aa2c428 commit ad84c8b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/models/role.rb
@@ -1,10 +1,10 @@
class Role < ActiveRecord::Base

acts_as_list scope: [:role_object_type, :role_object_id]

belongs_to :role_object, polymorphic: :true
acts_as_list scope: [ :role_object_id, :role_object_type]
belongs_to :person

validates_presence_of :person_id, :type, :role_object_id, :role_object_type, :position
# Note acts_as_list adds :position in a manner that it can not be validated with validate_presence_of
validates_presence_of :person_id, :type, :role_object_id, :role_object_type

end
18 changes: 12 additions & 6 deletions spec/models/role_spec.rb
Expand Up @@ -7,22 +7,28 @@
before do
role.valid?
end

context "required fields" do
specify "person_id" do
expect(role.errors.include?(:person_id)).to be_true
end
specify "type" do
specify "type" do
expect(role.errors.include?(:type)).to be_true
end
specify "role_object_id" do
expect(role.errors.include?(:role_object_id)).to be_true
end
specify "role_object_type" do
expect(role.errors.include?(:role_object_type)).to be_true
end
specify "position" do
expect(role.errors.include?(:position)).to be_true
end
end
end

context "after save" do
author_role = FactoryGirl.create(:source_author_role)

specify "position is speciefied by acts_as_list" do
expect(author_role.position).to eq(1)
end
end
end

Expand All @@ -31,7 +37,7 @@
specify "person" do
expect(role).to respond_to(:person)
end
end
end
end

end

0 comments on commit ad84c8b

Please sign in to comment.