mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Added basic test coverage for a model that invokes for protection from mass assignment.
This commit is contained in:
parent
99805aa23f
commit
01a1be4438
2 changed files with 44 additions and 0 deletions
3
test/dummy/app/models/protected_widget.rb
Normal file
3
test/dummy/app/models/protected_widget.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class ProtectedWidget < Widget
|
||||
attr_accessible :name, :a_text
|
||||
end
|
41
test/unit/protected_attrs_test.rb
Normal file
41
test/unit/protected_attrs_test.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ProtectedAttrsTest < ActiveSupport::TestCase
|
||||
subject { ProtectedWidget.new }
|
||||
|
||||
accessible_attrs = ProtectedWidget.accessible_attributes.to_a
|
||||
accessible_attrs.each do |attr_name|
|
||||
should allow_mass_assignment_of(attr_name.to_sym)
|
||||
end
|
||||
ProtectedWidget.column_names.reject { |column_name| accessible_attrs.include?(column_name) }.each do |attr_name|
|
||||
should_not allow_mass_assignment_of(attr_name.to_sym)
|
||||
end
|
||||
|
||||
context 'A model with `attr_accessible` created' do
|
||||
setup do
|
||||
@widget = ProtectedWidget.create! :name => 'Henry'
|
||||
@initial_attributes = @widget.attributes
|
||||
end
|
||||
|
||||
should 'be `nil` in its previous version' do
|
||||
assert_nil @widget.previous_version
|
||||
end
|
||||
|
||||
context 'which is then updated' do
|
||||
setup do
|
||||
@widget.assign_attributes(:name => 'Jeff', :a_text => 'Short statement')
|
||||
@widget.an_integer = 42
|
||||
@widget.save!
|
||||
end
|
||||
|
||||
should 'not be `nil` in its previous version' do
|
||||
assert_not_nil @widget.previous_version
|
||||
end
|
||||
|
||||
should 'the previous version should contain right attributes' do
|
||||
assert_equal @widget.previous_version.attributes, @initial_attributes
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue