Skip to content

Commit

Permalink
Adding shared ability tests for Fields, Positions, and Templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
bamnet committed Apr 18, 2012
1 parent 29828d3 commit dc76b5a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/fixtures/templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ two:
name: MyString
author: MyString
is_hidden: false

hidden:
name: Hidden Template
author: No one
is_hidden: true
25 changes: 25 additions & 0 deletions test/unit/abilities/shared/field_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'test_helper'

class SharedFieldAbilityTest < ActiveSupport::TestCase
def setup
@user = users(:kristen)
@screen = screens(:one)
@field = fields(:one)
end

test "anyone can read fields" do
[@user, @screen].each do |thing|
ability = Ability.new(thing)
assert ability.can?(:read, @field)
end
end

test "no one can update / delete fields" do
[@user, @screen].each do |thing|
ability = Ability.new(thing)
assert ability.cannot?(:update, @field)
assert ability.cannot?(:delete, @field)
end
end
end

25 changes: 25 additions & 0 deletions test/unit/abilities/shared/position_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'test_helper'

class SharedPositionAbilityTest < ActiveSupport::TestCase
def setup
@user = users(:kristen)
@screen = screens(:one)
@position = positions(:one)
end

test "anyone can read positions" do
[@user, @screen].each do |thing|
ability = Ability.new(thing)
assert ability.can?(:read, @position)
end
end

test "no one can update / delete positions" do
[@user, @screen].each do |thing|
ability = Ability.new(thing)
assert ability.cannot?(:update, @position)
assert ability.cannot?(:delete, @position)
end
end
end

33 changes: 33 additions & 0 deletions test/unit/abilities/shared/template_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'test_helper'

class SharedTemplateAbilityTest < ActiveSupport::TestCase
def setup
@user = users(:kristen)
@screen = screens(:one)
@template = templates(:one)
end

test "anyone can read public templates" do
[@user, @screen].each do |thing|
ability = Ability.new(thing)
assert ability.can?(:read, @template)
end
end

test "noone can read public templates" do
template = templates(:hidden)
[@user, @screen].each do |thing|
ability = Ability.new(thing)
assert ability.cannot?(:read, template)
end
end

test "no one can update / delete templates" do
[@user, @screen].each do |thing|
ability = Ability.new(thing)
assert ability.cannot?(:update, @template)
assert ability.cannot?(:delete, @template)
end
end
end

0 comments on commit dc76b5a

Please sign in to comment.