Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests run, and remember which bundle made it possible #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ pkg

## PROJECT::SPECIFIC
tmp

Gemfile.lock
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
source 'http://rubygems.org'
gemspec

gem 'shoulda', '~> 2.10.2'
gem 'mocha', '~> 0.9.8'
gem 'shoulda'
gem 'mocha'
gem 'yard', '>= 0'
gem 'rake', '0.8.7'
gem 'activesupport'
gem 'i18n'
gem 'i18n'
43 changes: 43 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
PATH
remote: .
specs:
canable (0.3.0)

GEM
remote: http://rubygems.org/
specs:
activesupport (4.1.0)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
i18n (0.6.9)
json (1.8.1)
metaclass (0.0.4)
minitest (5.3.3)
mocha (1.0.0)
metaclass (~> 0.0.1)
rake (0.8.7)
shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (>= 1.4.1, < 3.0)
shoulda-context (1.2.1)
shoulda-matchers (2.6.1)
activesupport (>= 3.0.0)
thread_safe (0.3.3)
tzinfo (1.1.0)
thread_safe (~> 0.1)
yard (0.8.7.4)

PLATFORMS
ruby

DEPENDENCIES
activesupport
canable!
i18n
mocha
rake (= 0.8.7)
shoulda
yard
6 changes: 3 additions & 3 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require 'test/unit'
require 'mocha'
require 'minitest/autorun'
require 'mocha/setup'
require 'shoulda'
require 'active_support/all'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'canable'

class Test::Unit::TestCase
class Minitest::Test
def Doc(name=nil, &block)
klass = Struct.new(:name)
klass.class_eval(&block) if block_given?
Expand Down
12 changes: 6 additions & 6 deletions test/test_ables.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'helper'

class AblesTest < Test::Unit::TestCase
class AblesTest < Minitest::Test
context "Class with Canable::Ables included" do
setup do
klass = Doc do
Expand All @@ -27,25 +27,25 @@ class AblesTest < Test::Unit::TestCase
assert @resource.destroyable_by?(@user)
end
end

context "Class that overrides an able method" do
setup do
klass = Doc do
include Canable::Ables

def viewable_by?(user)
user.name == 'John'
end
end

@resource = klass.new
@john = mock('user', :name => 'John')
@steve = mock('user', :name => 'Steve')
end

should "use the overriden method and not default to true" do
assert @resource.viewable_by?(@john)
assert ! @resource.viewable_by?(@steve)
end
end
end
end
9 changes: 5 additions & 4 deletions test/test_canable.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'helper'

class TestCanable < Test::Unit::TestCase
class TestCanable < Minitest::Test
context "Canable" do
should "have view action by default" do
assert_equal :viewable, Canable.actions[:view]
Expand All @@ -17,14 +17,15 @@ class TestCanable < Test::Unit::TestCase
should "have destroy action by default" do
assert_equal :destroyable, Canable.actions[:destroy]
end

should "be able to add another action" do
Canable.add(:publish, :publishable)
assert_equal :publishable, Canable.actions[:publish]
end

should "know cans" do
assert_equal %w(create destroy publish update view),
Canable.add(:publish, :publishable)
assert_equal %w(create destroy publish update view),
Canable.cans.map(&:to_s).sort
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/test_cans.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'helper'

class CansTest < Test::Unit::TestCase
class CansTest < Minitest::Test
context "Class with Canable::Cans included" do
setup do
klass = Doc do
include Canable::Cans
end

@user = klass.new(:name => 'John')
end

Expand Down Expand Up @@ -78,4 +78,4 @@ class CansTest < Test::Unit::TestCase
end
end
end
end
end
11 changes: 6 additions & 5 deletions test/test_enforcers.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'helper'

class EnforcersTest < Test::Unit::TestCase
class EnforcersTest < Minitest::Test
context "Including Canable::Enforcers in a class" do
setup do
klass = Class.new do
Expand Down Expand Up @@ -35,19 +35,20 @@ def edit

should "not raise error if can" do
@user.expects(:can_view?).with(@article).returns(true)
assert_nothing_raised { @controller.show }
@controller.show
# Got this far, so no exception was raised
end

should "raise error if cannot" do
@user.expects(:can_view?).with(@article).returns(false)
assert_raises(Canable::Transgression) { @controller.show }
end

should "raise error whenever current_user nil" do
@controller.current_user = nil
assert_raises(Canable::Transgression) { @controller.show }
end

should "be able to override can_xx? method" do
@user.expects(:banned?).returns(true)
assert_raises(Canable::Transgression) { @controller.update }
Expand All @@ -62,4 +63,4 @@ def edit
end
end
end
end
end