aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/attribute_methods_test.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-08-06 18:38:23 +0200
committerXavier Noria <fxn@hashref.com>2016-08-06 18:38:23 +0200
commit4c208254573c3428d82bd8744860bd86e1c78acb (patch)
tree9c8194acb75552fdda62d527d5c2876da9161650 /activemodel/test/cases/attribute_methods_test.rb
parent18a2513729ab90b04b1c86963e7d5b9213270c81 (diff)
downloadrails-4c208254573c3428d82bd8744860bd86e1c78acb.tar.gz
rails-4c208254573c3428d82bd8744860bd86e1c78acb.tar.bz2
rails-4c208254573c3428d82bd8744860bd86e1c78acb.zip
applies new string literal convention in activemodel/test
The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
Diffstat (limited to 'activemodel/test/cases/attribute_methods_test.rb')
-rw-r--r--activemodel/test/cases/attribute_methods_test.rb80
1 files changed, 40 insertions, 40 deletions
diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb
index e81b7ac424..89166f2f1e 100644
--- a/activemodel/test/cases/attribute_methods_test.rb
+++ b/activemodel/test/cases/attribute_methods_test.rb
@@ -1,16 +1,16 @@
-require 'cases/helper'
+require "cases/helper"
class ModelWithAttributes
include ActiveModel::AttributeMethods
class << self
define_method(:bar) do
- 'original bar'
+ "original bar"
end
end
def attributes
- { foo: 'value of foo', baz: 'value of baz' }
+ { foo: "value of foo", baz: "value of baz" }
end
private
@@ -24,7 +24,7 @@ class ModelWithAttributes2
attr_accessor :attributes
- attribute_method_suffix '_test'
+ attribute_method_suffix "_test"
private
def attribute(name)
@@ -48,7 +48,7 @@ class ModelWithAttributesWithSpaces
include ActiveModel::AttributeMethods
def attributes
- { :'foo bar' => 'value of foo bar'}
+ { :'foo bar' => "value of foo bar"}
end
private
@@ -62,12 +62,12 @@ class ModelWithWeirdNamesAttributes
class << self
define_method(:'c?d') do
- 'original c?d'
+ "original c?d"
end
end
def attributes
- { :'a?b' => 'value of a?b' }
+ { :'a?b' => "value of a?b" }
end
private
@@ -80,7 +80,7 @@ class ModelWithRubyKeywordNamedAttributes
include ActiveModel::AttributeMethods
def attributes
- { begin: 'value of begin', end: 'value of end' }
+ { begin: "value of begin", end: "value of end" }
end
private
@@ -94,16 +94,16 @@ class ModelWithoutAttributesMethod
end
class AttributeMethodsTest < ActiveModel::TestCase
- test 'method missing works correctly even if attributes method is not defined' do
+ test "method missing works correctly even if attributes method is not defined" do
assert_raises(NoMethodError) { ModelWithoutAttributesMethod.new.foo }
end
- test 'unrelated classes should not share attribute method matchers' do
+ test "unrelated classes should not share attribute method matchers" do
assert_not_equal ModelWithAttributes.send(:attribute_method_matchers),
ModelWithAttributes2.send(:attribute_method_matchers)
end
- test '#define_attribute_method generates attribute method' do
+ test "#define_attribute_method generates attribute method" do
begin
ModelWithAttributes.define_attribute_method(:foo)
@@ -114,19 +114,19 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
end
- test '#define_attribute_method does not generate attribute method if already defined in attribute module' do
+ test "#define_attribute_method does not generate attribute method if already defined in attribute module" do
klass = Class.new(ModelWithAttributes)
klass.generated_attribute_methods.module_eval do
def foo
- '<3'
+ "<3"
end
end
klass.define_attribute_method(:foo)
- assert_equal '<3', klass.new.foo
+ assert_equal "<3", klass.new.foo
end
- test '#define_attribute_method generates a method that is already defined on the host' do
+ test "#define_attribute_method generates a method that is already defined on the host" do
klass = Class.new(ModelWithAttributes) do
def foo
super
@@ -134,21 +134,21 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
klass.define_attribute_method(:foo)
- assert_equal 'value of foo', klass.new.foo
+ assert_equal "value of foo", klass.new.foo
end
- test '#define_attribute_method generates attribute method with invalid identifier characters' do
+ test "#define_attribute_method generates attribute method with invalid identifier characters" do
begin
ModelWithWeirdNamesAttributes.define_attribute_method(:'a?b')
assert_respond_to ModelWithWeirdNamesAttributes.new, :'a?b'
- assert_equal "value of a?b", ModelWithWeirdNamesAttributes.new.send('a?b')
+ assert_equal "value of a?b", ModelWithWeirdNamesAttributes.new.send("a?b")
ensure
ModelWithWeirdNamesAttributes.undefine_attribute_methods
end
end
- test '#define_attribute_methods works passing multiple arguments' do
+ test "#define_attribute_methods works passing multiple arguments" do
begin
ModelWithAttributes.define_attribute_methods(:foo, :baz)
@@ -159,7 +159,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
end
- test '#define_attribute_methods generates attribute methods' do
+ test "#define_attribute_methods generates attribute methods" do
begin
ModelWithAttributes.define_attribute_methods(:foo)
@@ -170,7 +170,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
end
- test '#alias_attribute generates attribute_aliases lookup hash' do
+ test "#alias_attribute generates attribute_aliases lookup hash" do
klass = Class.new(ModelWithAttributes) do
define_attribute_methods :foo
alias_attribute :bar, :foo
@@ -179,7 +179,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
assert_equal({ "bar" => "foo" }, klass.attribute_aliases)
end
- test '#define_attribute_methods generates attribute methods with spaces in their names' do
+ test "#define_attribute_methods generates attribute methods with spaces in their names" do
begin
ModelWithAttributesWithSpaces.define_attribute_methods(:'foo bar')
@@ -190,7 +190,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
end
- test '#alias_attribute works with attributes with spaces in their names' do
+ test "#alias_attribute works with attributes with spaces in their names" do
begin
ModelWithAttributesWithSpaces.define_attribute_methods(:'foo bar')
ModelWithAttributesWithSpaces.alias_attribute(:'foo_bar', :'foo bar')
@@ -201,7 +201,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
end
- test '#alias_attribute works with attributes named as a ruby keyword' do
+ test "#alias_attribute works with attributes named as a ruby keyword" do
begin
ModelWithRubyKeywordNamedAttributes.define_attribute_methods([:begin, :end])
ModelWithRubyKeywordNamedAttributes.alias_attribute(:from, :begin)
@@ -214,7 +214,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
end
- test '#undefine_attribute_methods removes attribute methods' do
+ test "#undefine_attribute_methods removes attribute methods" do
ModelWithAttributes.define_attribute_methods(:foo)
ModelWithAttributes.undefine_attribute_methods
@@ -222,21 +222,21 @@ class AttributeMethodsTest < ActiveModel::TestCase
assert_raises(NoMethodError) { ModelWithAttributes.new.foo }
end
- test 'accessing a suffixed attribute' do
+ test "accessing a suffixed attribute" do
m = ModelWithAttributes2.new
- m.attributes = { 'foo' => 'bar' }
+ m.attributes = { "foo" => "bar" }
- assert_equal 'bar', m.foo
- assert_equal 'bar', m.foo_test
+ assert_equal "bar", m.foo
+ assert_equal "bar", m.foo_test
end
- test 'should not interfere with method_missing if the attr has a private/protected method' do
+ test "should not interfere with method_missing if the attr has a private/protected method" do
m = ModelWithAttributes2.new
- m.attributes = { 'private_method' => '<3', 'protected_method' => 'O_o' }
+ m.attributes = { "private_method" => "<3", "protected_method" => "O_o" }
# dispatches to the *method*, not the attribute
- assert_equal '<3 <3', m.send(:private_method)
- assert_equal 'O_o O_o', m.send(:protected_method)
+ assert_equal "<3 <3", m.send(:private_method)
+ assert_equal "O_o O_o", m.send(:protected_method)
# sees that a method is already defined, so doesn't intervene
assert_raises(NoMethodError) { m.private_method }
@@ -249,9 +249,9 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
end
- test 'should not interfere with respond_to? if the attribute has a private/protected method' do
+ test "should not interfere with respond_to? if the attribute has a private/protected method" do
m = ModelWithAttributes2.new
- m.attributes = { 'private_method' => '<3', 'protected_method' => 'O_o' }
+ m.attributes = { "private_method" => "<3", "protected_method" => "O_o" }
assert !m.respond_to?(:private_method)
assert m.respond_to?(:private_method, true)
@@ -264,9 +264,9 @@ class AttributeMethodsTest < ActiveModel::TestCase
assert m.respond_to?(:protected_method, true)
end
- test 'should use attribute_missing to dispatch a missing attribute' do
+ test "should use attribute_missing to dispatch a missing attribute" do
m = ModelWithAttributes2.new
- m.attributes = { 'foo' => 'bar' }
+ m.attributes = { "foo" => "bar" }
def m.attribute_missing(match, *args, &block)
match
@@ -274,8 +274,8 @@ class AttributeMethodsTest < ActiveModel::TestCase
match = m.foo_test
- assert_equal 'foo', match.attr_name
- assert_equal 'attribute_test', match.target
- assert_equal 'foo_test', match.method_name
+ assert_equal "foo", match.attr_name
+ assert_equal "attribute_test", match.target
+ assert_equal "foo_test", match.method_name
end
end