Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Rakefile and fix tests
  • Loading branch information
guilleiguaran committed Sep 5, 2012
1 parent ab93650 commit 2f13d10
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 17 deletions.
10 changes: 10 additions & 0 deletions Rakefile
@@ -1 +1,11 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs = ["test"]
t.pattern = "test/**/*_test.rb"
t.ruby_opts = ['-w']
end

task :default => :test
2 changes: 1 addition & 1 deletion test/mass_assignment_security/black_list_test.rb
@@ -1,4 +1,4 @@
require "cases/helper"
require "test_helper"

class BlackListTest < ActiveModel::TestCase

Expand Down
2 changes: 1 addition & 1 deletion test/mass_assignment_security/permission_set_test.rb
@@ -1,4 +1,4 @@
require "cases/helper"
require "test_helper"

class PermissionSetTest < ActiveModel::TestCase

Expand Down
2 changes: 1 addition & 1 deletion test/mass_assignment_security/sanitizer_test.rb
@@ -1,4 +1,4 @@
require "cases/helper"
require "test_helper"
require 'active_support/logger'

class SanitizerTest < ActiveModel::TestCase
Expand Down
2 changes: 1 addition & 1 deletion test/mass_assignment_security/white_list_test.rb
@@ -1,4 +1,4 @@
require "cases/helper"
require "test_helper"

class WhiteListTest < ActiveModel::TestCase

Expand Down
16 changes: 8 additions & 8 deletions test/mass_assignment_security_test.rb
Expand Up @@ -71,11 +71,11 @@ def test_attributes_protected_by_default
end

def test_mass_assignment_protection_inheritance
assert_blank LoosePerson.accessible_attributes
assert_equal Set.new(['credit_rating', 'administrator']), LoosePerson.protected_attributes
assert_blank SpecialLoosePerson.accessible_attributes
assert_equal Set.new(['credit_rating', 'administrator']), SpecialLoosePerson.protected_attributes

assert_blank LoosePerson.accessible_attributes
assert_equal Set.new(['credit_rating']), LoosePerson.protected_attributes(:admin)
assert_blank SpecialLoosePerson.accessible_attributes
assert_equal Set.new(['credit_rating']), SpecialLoosePerson.protected_attributes(:admin)

assert_blank LooseDescendant.accessible_attributes
assert_equal Set.new(['credit_rating', 'administrator', 'phone_number']), LooseDescendant.protected_attributes
Expand All @@ -84,11 +84,11 @@ def test_mass_assignment_protection_inheritance
assert_equal Set.new(['credit_rating', 'administrator', 'phone_number', 'name']), LooseDescendantSecond.protected_attributes,
'Running attr_protected twice in one class should merge the protections'

assert_blank TightPerson.protected_attributes - TightPerson.attributes_protected_by_default
assert_equal Set.new(['name', 'address']), TightPerson.accessible_attributes
assert_blank SpecialTightPerson.protected_attributes - SpecialTightPerson.attributes_protected_by_default
assert_equal Set.new(['name', 'address']), SpecialTightPerson.accessible_attributes

assert_blank TightPerson.protected_attributes(:admin) - TightPerson.attributes_protected_by_default
assert_equal Set.new(['name', 'address', 'admin']), TightPerson.accessible_attributes(:admin)
assert_blank SpecialTightPerson.protected_attributes(:admin) - SpecialTightPerson.attributes_protected_by_default
assert_equal Set.new(['name', 'address', 'admin']), SpecialTightPerson.accessible_attributes(:admin)

assert_blank TightDescendant.protected_attributes - TightDescendant.attributes_protected_by_default
assert_equal Set.new(['name', 'address', 'phone_number']), TightDescendant.accessible_attributes
Expand Down
10 changes: 5 additions & 5 deletions test/models/mass_assignment_specific.rb
Expand Up @@ -45,22 +45,22 @@ class Task
public :sanitize_for_mass_assignment
end

class LoosePerson
class SpecialLoosePerson
include ActiveModel::MassAssignmentSecurity
attr_protected :credit_rating, :administrator
attr_protected :credit_rating, :as => :admin
end

class LooseDescendant < LoosePerson
class LooseDescendant < SpecialLoosePerson
attr_protected :phone_number
end

class LooseDescendantSecond< LoosePerson
class LooseDescendantSecond< SpecialLoosePerson
attr_protected :phone_number
attr_protected :name
end

class TightPerson
class SpecialTightPerson
include ActiveModel::MassAssignmentSecurity
attr_accessible :name, :address
attr_accessible :name, :address, :admin, :as => :admin
Expand All @@ -70,7 +70,7 @@ def self.attributes_protected_by_default
end
end

class TightDescendant < TightPerson
class TightDescendant < SpecialTightPerson
attr_accessible :phone_number
attr_accessible :super_powers, :as => :admin
end

0 comments on commit 2f13d10

Please sign in to comment.