diff --git a/.gitignore b/.gitignore index 89cd9ba..71e4d66 100644 --- a/.gitignore +++ b/.gitignore @@ -20,5 +20,3 @@ pkg ## PROJECT::SPECIFIC tmp - -Gemfile.lock \ No newline at end of file diff --git a/Gemfile b/Gemfile index 54c6481..b206702 100644 --- a/Gemfile +++ b/Gemfile @@ -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' \ No newline at end of file +gem 'i18n' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..94b8c73 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/test/helper.rb b/test/helper.rb index 2b26496..e8b2302 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,5 +1,5 @@ -require 'test/unit' -require 'mocha' +require 'minitest/autorun' +require 'mocha/setup' require 'shoulda' require 'active_support/all' @@ -7,7 +7,7 @@ $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? diff --git a/test/test_ables.rb b/test/test_ables.rb index 2b0e117..0d1bccd 100644 --- a/test/test_ables.rb +++ b/test/test_ables.rb @@ -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 @@ -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 \ No newline at end of file +end diff --git a/test/test_canable.rb b/test/test_canable.rb index 63eee85..612f451 100644 --- a/test/test_canable.rb +++ b/test/test_canable.rb @@ -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] @@ -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 diff --git a/test/test_cans.rb b/test/test_cans.rb index 981572c..564b1a1 100644 --- a/test/test_cans.rb +++ b/test/test_cans.rb @@ -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 @@ -78,4 +78,4 @@ class CansTest < Test::Unit::TestCase end end end -end \ No newline at end of file +end diff --git a/test/test_enforcers.rb b/test/test_enforcers.rb index bcd8e98..172e3ef 100644 --- a/test/test_enforcers.rb +++ b/test/test_enforcers.rb @@ -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 @@ -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 } @@ -62,4 +63,4 @@ def edit end end end -end \ No newline at end of file +end