0
@@ -58,19 +58,19 @@ class AttributeMethodsTest < ActiveRecord::TestCase
0
def test_kernel_methods_not_implemented_in_activerecord
0
%w(test name display y).each do |method|
0
- assert
_equal false, ActiveRecord::Base.instance_method_already_implemented?(method), "##{method} is defined"
0
+ assert
!ActiveRecord::Base.instance_method_already_implemented?(method), "##{method} is defined"
0
def test_primary_key_implemented
0
- assert
_equal true, Class.new(ActiveRecord::Base).instance_method_already_implemented?('id')
0
+ assert
Class.new(ActiveRecord::Base).instance_method_already_implemented?('id')
0
def test_defined_kernel_methods_implemented_in_model
0
%w(test name display y).each do |method|
0
klass = Class.new ActiveRecord::Base
0
klass.class_eval "def #{method}() 'defined #{method}' end"
0
- assert
_equal true, klass.instance_method_already_implemented?(method), "##{method} is not defined"
0
+ assert
klass.instance_method_already_implemented?(method), "##{method} is not defined"
0
@@ -80,7 +80,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
0
abstract.class_eval "def #{method}() 'defined #{method}' end"
0
abstract.abstract_class = true
0
klass = Class.new abstract
0
- assert
_equal true, klass.instance_method_already_implemented?(method), "##{method} is not defined"
0
+ assert
klass.instance_method_already_implemented?(method), "##{method} is not defined"
0
@@ -228,6 +228,40 @@ class AttributeMethodsTest < ActiveRecord::TestCase
0
assert_equal [:field_b], Minimalistic.skip_time_zone_conversion_for_attributes
0
+ def test_read_attributes_respect_access_control
+ topic = @target.new(:title => "The pros and cons of programming naked.")
0
+ assert !topic.respond_to?(:title)
0
+ assert_raise(NoMethodError) { topic.title }
0
+ def test_write_attributes_respect_access_control
0
+ privatize("title=(value)")
0
+ assert !topic.respond_to?(:title=)
0
+ assert_raise(NoMethodError) { topic.title = "Pants"}
0
+ topic.send(:title=, "Very large pants")
0
+ def test_question_attributes_respect_access_control
0
+ topic = @target.new(:title => "Isaac Newton's pants")
0
+ assert !topic.respond_to?(:title?)
0
+ assert_raise(NoMethodError) { topic.title? }
0
+ assert topic.send(:title?)
0
+ def test_bulk_update_respects_access_control
0
+ privatize("title=(value)")
0
+ assert_raise(ActiveRecord::UnknownAttributeError) { topic = @target.new(:title => "Rants about pants") }
0
+ assert_raise(ActiveRecord::UnknownAttributeError) { @target.new.attributes = { :title => "Ants in pants" } }
0
def time_related_columns_on_topic
0
Topic.columns.select{|c| [:time, :date, :datetime, :timestamp].include?(c.type)}.map(&:name)
0
@@ -244,4 +278,13 @@ class AttributeMethodsTest < ActiveRecord::TestCase
0
ActiveRecord::Base.time_zone_aware_attributes = old_tz
0
+ def privatize(method_signature)
0
+ @target.class_eval <<-private_method
0
+ def #{method_signature}
Oh, there are cons?
Indeed, it’s frowned upon at community code drives or in the enterprise.
Programming naked isn’t enterprise ready
Cons: moment of panic as you rush to get clothed when the doorbell rings.
Cons: the look you receive from your wife when she returns home from work at the end of the day, and there you are.
Cons: forgetting that your skype was set to video chat….
Cons: pair programming and standup meetings
Cons: a vinyl chair
cons: crack-sweat + chair.
I win.
(Being non-enterprise-ready is a pro, in my book.)
Cons: having adeona running, your macbook gets stolen and police look at photos taken to identify the thief.
Cons: Near nuclear temperatures emanating from the bottom of your MacBook Pro when Time Machine kicks in.
Pros: air flow!
Someone had to.
Pros: My plugin hit your mencache. Cons: It was a miss.
Cons:
def test_something send :something end
describe ‘something’ do before do @obj.module_eval { public :something } end it ‘is a pain in the ass to test’ { true.should.eql(true) } it …. end
;-P
Pros: Makes tabbing to porn sites when tests are running a lot more convenient
leethal: Those are supposed to be swords: http://xkcd.com/303/
Cons: pubes in your keyboard! Pros: Easier to have sex during tests!