Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow code conventions on ActiveRecord tests #523

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions activerecord/test/cases/associations/eager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,25 @@ def test_duplicate_middle_objects

def test_preloading_has_many_in_multiple_queries_with_more_ids_than_database_can_handle
Post.connection.expects(:in_clause_length).at_least_once.returns(5)
posts = Post.find(:all, :include=>:comments)
posts = Post.find(:all, :include => :comments)
assert_equal 11, posts.size
end

def test_preloading_has_many_in_one_queries_when_database_has_no_limit_on_ids_it_can_handle
Post.connection.expects(:in_clause_length).at_least_once.returns(nil)
posts = Post.find(:all, :include=>:comments)
posts = Post.find(:all, :include => :comments)
assert_equal 11, posts.size
end

def test_preloading_habtm_in_multiple_queries_with_more_ids_than_database_can_handle
Post.connection.expects(:in_clause_length).at_least_once.returns(5)
posts = Post.find(:all, :include=>:categories)
posts = Post.find(:all, :include => :categories)
assert_equal 11, posts.size
end

def test_preloading_habtm_in_one_queries_when_database_has_no_limit_on_ids_it_can_handle
Post.connection.expects(:in_clause_length).at_least_once.returns(nil)
posts = Post.find(:all, :include=>:categories)
posts = Post.find(:all, :include => :categories)
assert_equal 11, posts.size
end

Expand Down Expand Up @@ -662,21 +662,21 @@ def test_eager_with_multi_table_conditional_properly_counts_the_records_when_usi

def test_eager_with_invalid_association_reference
assert_raise(ActiveRecord::ConfigurationError, "Association was not found; perhaps you misspelled it? You specified :include => :monkeys") {
Post.find(6, :include=> :monkeys )
Post.find(6, :include => :monkeys )
}
assert_raise(ActiveRecord::ConfigurationError, "Association was not found; perhaps you misspelled it? You specified :include => :monkeys") {
Post.find(6, :include=>[ :monkeys ])
Post.find(6, :include => [ :monkeys ])
}
assert_raise(ActiveRecord::ConfigurationError, "Association was not found; perhaps you misspelled it? You specified :include => :monkeys") {
Post.find(6, :include=>[ 'monkeys' ])
Post.find(6, :include => [ 'monkeys' ])
}
assert_raise(ActiveRecord::ConfigurationError, "Association was not found; perhaps you misspelled it? You specified :include => :monkeys, :elephants") {
Post.find(6, :include=>[ :monkeys, :elephants ])
Post.find(6, :include => [ :monkeys, :elephants ])
}
end

def find_all_ordered(className, include=nil)
className.find(:all, :order=>"#{className.table_name}.#{className.primary_key}", :include=>include)
className.find(:all, :order => "#{className.table_name}.#{className.primary_key}", :include => include)
end

def test_limited_eager_with_order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,14 @@ def test_adding_using_create
def test_create_with_bang_on_has_many_when_parent_is_new_raises
assert_raise(ActiveRecord::RecordNotSaved) do
firm = Firm.new
firm.plain_clients.create! :name=>"Whoever"
firm.plain_clients.create! :name => "Whoever"
end
end

def test_regular_create_on_has_many_when_parent_is_new_raises
assert_raise(ActiveRecord::RecordNotSaved) do
firm = Firm.new
firm.plain_clients.create :name=>"Whoever"
firm.plain_clients.create :name => "Whoever"
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def test_associate_with_create
# 1 query for the new record, 1 for the join table record
# No need to update the actual collection yet!
assert_queries(2) do
posts(:thinking).people.create(:first_name=>"Jeb")
posts(:thinking).people.create(:first_name => "Jeb")
end

# *Now* we actually need the collection so it's loaded
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/attribute_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def test_array_content
end

def test_read_attributes_before_type_cast
category = Category.new({:name=>"Test categoty", :type => nil})
category_attrs = {"name"=>"Test categoty", "id" => nil, "type" => nil, "categorizations_count" => nil}
category = Category.new({:name => "Test categoty", :type => nil})
category_attrs = {"name" => "Test categoty", "id" => nil, "type" => nil, "categorizations_count" => nil}
assert_equal category_attrs , category.attributes_before_type_cast
end

Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/autosave_association_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_callbacks_firing_order_on_update
eye = Eye.create(:iris_attributes => {:color => 'honey'})
eye.update_attributes(:iris_attributes => {:color => 'green'})
assert_equal [true, false], eye.after_update_callbacks_stack
end
end

def test_callbacks_firing_order_on_save
eye = Eye.create(:iris_attributes => {:color => 'honey'})
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_save_fails_for_invalid_belongs_to

def test_save_succeeds_for_invalid_belongs_to_with_validate_false
# Oracle saves empty string as NULL therefore :message changed to one space
assert log = AuditLog.create(:developer_id => 0, :message=> " ")
assert log = AuditLog.create(:developer_id => 0, :message => " ")

log.unvalidated_developer = Developer.new
assert !log.unvalidated_developer.valid?
Expand Down
6 changes: 3 additions & 3 deletions activerecord/test/cases/nested_attributes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ def test_validate_presence_of_parent_works_with_inverse_of
assert_difference 'Man.count' do
assert_difference 'Interest.count', 2 do
man = Man.create!(:name => 'John',
:interests_attributes => [{:topic=>'Cars'}, {:topic=>'Sports'}])
:interests_attributes => [{:topic => 'Cars'}, {:topic => 'Sports'}])
assert_equal 2, man.interests.count
end
end
Expand All @@ -746,7 +746,7 @@ def test_validate_presence_of_parent_fails_without_inverse_of
Interest.validates_presence_of(:man)
assert_no_difference ['Man.count', 'Interest.count'] do
man = Man.create(:name => 'John',
:interests_attributes => [{:topic=>'Cars'}, {:topic=>'Sports'}])
:interests_attributes => [{:topic => 'Cars'}, {:topic => 'Sports'}])
assert !man.errors[:"interests.man"].empty?
end
end
Expand Down Expand Up @@ -868,7 +868,7 @@ def test_attr_accessor_of_child_should_be_value_provided_during_update_attribute
attributes = {:pets_attributes => { "1"=> { :id => @pet1.id,
:name => "Foo2",
:current_user => "John",
:_destroy=>true }}}
:_destroy => true }}}
@owner.update_attributes(attributes)
assert_equal 'John', Pet.after_destroy_output
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_validates_associated_one
end

def test_validates_associated_with_custom_message_using_quotes
Reply.validates_associated :topic, :message=> "This string contains 'single' and \"double\" quotes"
Reply.validates_associated :topic, :message => "This string contains 'single' and \"double\" quotes"
Topic.validates_presence_of :content
r = Reply.create("title" => "A reply", "content" => "with content!")
r.topic = Topic.create("title" => "uhohuhoh")
Expand Down
14 changes: 7 additions & 7 deletions activerecord/test/cases/xml_serialization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_should_serialize_default_root
end

def test_should_serialize_default_root_with_namespace
@xml = Contact.new.to_xml :namespace=>"http://xml.rubyonrails.org/contact"
@xml = Contact.new.to_xml :namespace => "http://xml.rubyonrails.org/contact"
assert_match %r{^<contact xmlns="http://xml.rubyonrails.org/contact">}, @xml
assert_match %r{</contact>$}, @xml
end
Expand Down Expand Up @@ -163,22 +163,22 @@ def test_modules
end

def test_passing_hash_shouldnt_reuse_builder
options = {:include=>:posts}
options = {:include => :posts}
david = authors(:david)
first_xml_size = david.to_xml(options).size
second_xml_size = david.to_xml(options).size
assert_equal first_xml_size, second_xml_size
end

def test_include_uses_association_name
xml = authors(:david).to_xml :include=>:hello_posts, :indent => 0
xml = authors(:david).to_xml :include => :hello_posts, :indent => 0
assert_match %r{<hello-posts type="array">}, xml
assert_match %r{<hello-post type="Post">}, xml
assert_match %r{<hello-post type="StiPost">}, xml
end

def test_included_associations_should_skip_types
xml = authors(:david).to_xml :include=>:hello_posts, :indent => 0, :skip_types => true
xml = authors(:david).to_xml :include => :hello_posts, :indent => 0, :skip_types => true
assert_match %r{<hello-posts>}, xml
assert_match %r{<hello-post>}, xml
assert_match %r{<hello-post>}, xml
Expand All @@ -190,7 +190,7 @@ def test_methods_are_called_on_object
end

def test_should_not_call_methods_on_associations_that_dont_respond
xml = authors(:david).to_xml :include=>:hello_posts, :methods => :label, :indent => 2
xml = authors(:david).to_xml :include => :hello_posts, :methods => :label, :indent => 2
assert !authors(:david).hello_posts.first.respond_to?(:label)
assert_match %r{^ <label>.*</label>}, xml
assert_no_match %r{^ <label>}, xml
Expand Down Expand Up @@ -231,14 +231,14 @@ def test_procs_on_included_associations_are_called

def test_should_include_empty_has_many_as_empty_array
authors(:david).posts.delete_all
xml = authors(:david).to_xml :include=>:posts, :indent => 2
xml = authors(:david).to_xml :include => :posts, :indent => 2

assert_equal [], Hash.from_xml(xml)['author']['posts']
assert_match %r{^ <posts type="array"/>}, xml
end

def test_should_has_many_array_elements_should_include_type_when_different_from_guessed_value
xml = authors(:david).to_xml :include=>:posts_with_comments, :indent => 2
xml = authors(:david).to_xml :include => :posts_with_comments, :indent => 2

assert Hash.from_xml(xml)
assert_match %r{^ <posts-with-comments type="array">}, xml
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/models/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Firm < Company

has_one :account, :foreign_key => "firm_id", :dependent => :destroy, :validate => true
has_one :unvalidated_account, :foreign_key => "firm_id", :class_name => 'Account', :validate => false
has_one :account_with_select, :foreign_key => "firm_id", :select => "id, firm_id", :class_name=>'Account'
has_one :account_with_select, :foreign_key => "firm_id", :select => "id, firm_id", :class_name => 'Account'
has_one :readonly_account, :foreign_key => "firm_id", :class_name => "Account", :readonly => true
# added order by id as in fixtures there are two accounts for Rails Core
# Oracle tests were failing because of that as the second fixture was selected
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/models/computer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Computer < ActiveRecord::Base
belongs_to :developer, :foreign_key=>'developer'
belongs_to :developer, :foreign_key => 'developer'
end
2 changes: 1 addition & 1 deletion activerecord/test/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def add_joins_and_select
has_many :readers_with_person, :include => :person, :class_name => "Reader"
has_many :people, :through => :readers
has_many :single_people, :through => :readers
has_many :people_with_callbacks, :source=>:person, :through => :readers,
has_many :people_with_callbacks, :source => :person, :through => :readers,
:before_add => lambda {|owner, reader| log(:added, :before, reader.first_name) },
:after_add => lambda {|owner, reader| log(:added, :after, reader.first_name) },
:before_remove => lambda {|owner, reader| log(:removed, :before, reader.first_name) },
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/schema/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def create_table(*args, &block)
end

create_table :audit_logs, :force => true do |t|
t.column :message, :string, :null=>false
t.column :developer_id, :integer, :null=>false
t.column :message, :string, :null => false
t.column :developer_id, :integer, :null => false
end

create_table :authors, :force => true do |t|
Expand Down