diff options
18 files changed, 97 insertions, 64 deletions
diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index 976ae5a76d..3402343494 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -81,7 +81,7 @@ module Sprockets private def debug_assets? compile_assets? && (Rails.application.config.assets.debug || params[:debug_assets]) - rescue NoMethodError + rescue NameError false end diff --git a/activerecord/lib/rails/generators/active_record/migration/templates/migration.rb b/activerecord/lib/rails/generators/active_record/migration/templates/migration.rb index d084a00ed7..9ca63a209e 100644 --- a/activerecord/lib/rails/generators/active_record/migration/templates/migration.rb +++ b/activerecord/lib/rails/generators/active_record/migration/templates/migration.rb @@ -5,7 +5,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %> <%- if attribute.has_index? -%> add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %> - <%- end %> + <%- end -%> <%- end -%> end <%- else -%> @@ -24,6 +24,9 @@ class <%= migration_class_name %> < ActiveRecord::Migration <% attributes.reverse.each do |attribute| -%> <%- if migration_action -%> <%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><%= attribute.inject_options %><% end %> + <%- if attribute.has_index? && migration_action == 'remove' -%> + add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %> + <%- end -%> <%- end -%> <%- end -%> end diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index ead8eaf342..f7b2b42959 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -912,7 +912,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_clearing_updates_counter_cache - topic = Topic.first + topic = Topic.order(:id).first assert_difference 'topic.reload.replies_count', -1 do topic.replies.clear @@ -1001,14 +1001,14 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end def test_delete_all_association_with_primary_key_deletes_correct_records - firm = Firm.find(:first) + firm = Firm.order(:id).first # break the vanilla firm_id foreign key assert_equal 2, firm.clients.count firm.clients.first.update_column(:firm_id, nil) assert_equal 1, firm.clients(true).count assert_equal 1, firm.clients_using_primary_key_with_delete_all.count old_record = firm.clients_using_primary_key_with_delete_all.first - firm = Firm.find(:first) + firm = Firm.order(:id).first firm.destroy assert_nil Client.find_by_id(old_record.id) end @@ -1168,13 +1168,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase core = companies(:rails_core) assert_equal accounts(:rails_core_account), core.account - assert_equal companies(:leetsoft, :jadedpixel), core.companies + assert_equal companies(:leetsoft, :jadedpixel), core.companies.order(:id) core.destroy assert_nil accounts(:rails_core_account).reload.firm_id assert_nil companies(:leetsoft).reload.client_of assert_nil companies(:jadedpixel).reload.client_of - assert_equal num_accounts, Account.count end diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index 995afef796..6f5644ada0 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -403,7 +403,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase end def test_has_many_through_polymorphic_has_one - assert_equal Tagging.find(1,2).sort_by { |t| t.id }, authors(:david).tagging + assert_equal Tagging.find(1,2).sort_by { |t| t.id }, authors(:david).tagging.order(:id) end def test_has_many_through_polymorphic_has_many @@ -452,7 +452,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase end def test_has_many_through_uses_conditions_specified_on_the_has_many_association - author = Author.find(:first) + author = Author.order(:id).first assert_present author.comments assert_blank author.nonexistant_comments end @@ -649,7 +649,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase end def test_preload_polymorph_many_types - taggings = Tagging.find :all, :include => :taggable, :conditions => ['taggable_type != ?', 'FakeModel'] + taggings = Tagging.find :all, :include => :taggable, :conditions => ['taggable_type != ?', 'FakeModel'], :order => 'id' assert_no_queries do taggings.first.taggable.id taggings[1].taggable.id diff --git a/activerecord/test/cases/associations/nested_through_associations_test.rb b/activerecord/test/cases/associations/nested_through_associations_test.rb index f920e09410..5b551d8a9a 100644 --- a/activerecord/test/cases/associations/nested_through_associations_test.rb +++ b/activerecord/test/cases/associations/nested_through_associations_test.rb @@ -55,7 +55,7 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase end def test_has_many_through_has_many_with_has_many_through_source_reflection_preload - authors = assert_queries(5) { Author.includes(:tags).to_a } + authors = assert_queries(5) { Author.includes(:tags).order(:id).to_a } general = tags(:general) assert_no_queries do @@ -84,7 +84,7 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase def test_has_many_through_has_many_through_with_has_many_source_reflection_preload luke, david = subscribers(:first), subscribers(:second) - authors = assert_queries(4) { Author.includes(:subscribers).to_a } + authors = assert_queries(4) { Author.includes(:subscribers).order(:id).to_a } assert_no_queries do assert_equal [luke, david, david], authors.first.subscribers.sort_by(&:nick) end @@ -106,10 +106,10 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase end def test_has_many_through_has_one_with_has_one_through_source_reflection_preload - members = assert_queries(4) { Member.includes(:nested_member_types).to_a } + members = assert_queries(4) { Member.includes(:nested_member_types).order(:id).to_a } founding = member_types(:founding) assert_no_queries do - assert_equal [founding], members.first.nested_member_types + assert_equal [founding], members.first.nested_member_types.to_a end end @@ -128,10 +128,10 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase end def test_has_many_through_has_one_through_with_has_one_source_reflection_preload - members = assert_queries(4) { Member.includes(:nested_sponsors).to_a } + members = assert_queries(4) { Member.includes(:nested_sponsors).order(:id).to_a } mustache = sponsors(:moustache_club_sponsor_for_groucho) assert_no_queries do - assert_equal [mustache], members.first.nested_sponsors + assert_equal [mustache], members.first.nested_sponsors.to_a end end @@ -163,7 +163,7 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase def test_has_many_through_has_one_with_has_many_through_source_reflection_preload_via_joins assert_includes_and_joins_equal( - Member.where('member_details.id' => member_details(:groucho).id).order('member_details.id'), + Member.where('member_details.id' => member_details(:groucho).id).order('members.id'), [members(:groucho), members(:some_other_guy)], :organization_member_details ) @@ -193,7 +193,7 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase def test_has_many_through_has_one_through_with_has_many_source_reflection_preload_via_joins assert_includes_and_joins_equal( - Member.where('member_details.id' => member_details(:groucho).id).order('member_details.id'), + Member.where('member_details.id' => member_details(:groucho).id).order('members.id'), [members(:groucho), members(:some_other_guy)], :organization_member_details_2 ) @@ -285,7 +285,7 @@ class NestedThroughAssociationsTest < ActiveRecord::TestCase end def test_has_many_through_has_many_through_with_belongs_to_source_reflection_preload - authors = assert_queries(5) { Author.includes(:tagging_tags).to_a } + authors = assert_queries(5) { Author.includes(:tagging_tags).order(:id).to_a } general = tags(:general) assert_no_queries do diff --git a/activerecord/test/cases/clone_test.rb b/activerecord/test/cases/clone_test.rb index d91646efca..12d9e303bb 100644 --- a/activerecord/test/cases/clone_test.rb +++ b/activerecord/test/cases/clone_test.rb @@ -6,7 +6,7 @@ module ActiveRecord fixtures :topics def test_persisted - topic = Topic.first + topic = Topic.order(:id).first cloned = topic.clone assert topic.persisted?, 'topic persisted' assert cloned.persisted?, 'topic persisted' @@ -14,7 +14,7 @@ module ActiveRecord end def test_stays_frozen - topic = Topic.first + topic = Topic.order(:id).first topic.freeze cloned = topic.clone @@ -24,7 +24,7 @@ module ActiveRecord end def test_shallow - topic = Topic.first + topic = Topic.order(:id).first cloned = topic.clone topic.author_name = 'Aaron' assert_equal 'Aaron', cloned.author_name diff --git a/activerecord/test/cases/dup_test.rb b/activerecord/test/cases/dup_test.rb index 0236f9b0a1..303f616c61 100644 --- a/activerecord/test/cases/dup_test.rb +++ b/activerecord/test/cases/dup_test.rb @@ -10,14 +10,14 @@ module ActiveRecord end def test_not_readonly - topic = Topic.first + topic = Topic.order(:id).first duped = topic.dup assert !duped.readonly?, 'should not be readonly' end def test_is_readonly - topic = Topic.first + topic = Topic.order(:id).first topic.readonly! duped = topic.dup @@ -25,7 +25,7 @@ module ActiveRecord end def test_dup_not_persisted - topic = Topic.first + topic = Topic.order(:id).first duped = topic.dup assert !duped.persisted?, 'topic not persisted' @@ -33,20 +33,20 @@ module ActiveRecord end def test_dup_has_no_id - topic = Topic.first + topic = Topic.order(:id).first duped = topic.dup assert_nil duped.id end def test_dup_with_modified_attributes - topic = Topic.first + topic = Topic.order(:id).first topic.author_name = 'Aaron' duped = topic.dup assert_equal 'Aaron', duped.author_name end def test_dup_with_changes - dbtopic = Topic.first + dbtopic = Topic.order(:id).first topic = Topic.new topic.attributes = dbtopic.attributes @@ -61,7 +61,7 @@ module ActiveRecord end def test_dup_topics_are_independent - topic = Topic.first + topic = Topic.order(:id).first topic.author_name = 'Aaron' duped = topic.dup @@ -71,7 +71,7 @@ module ActiveRecord end def test_dup_attributes_are_independent - topic = Topic.first + topic = Topic.order(:id).first duped = topic.dup duped.author_name = 'meow' @@ -82,7 +82,7 @@ module ActiveRecord end def test_dup_timestamps_are_cleared - topic = Topic.first + topic = Topic.order(:id).first assert_not_nil topic.updated_at assert_not_nil topic.created_at @@ -98,6 +98,5 @@ module ActiveRecord assert_not_nil new_topic.updated_at assert_not_nil new_topic.created_at end - end end diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 4705252c05..c72a9dcb17 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -53,8 +53,8 @@ class FinderTest < ActiveRecord::TestCase def test_exists_with_nil_arg assert !Topic.exists?(nil) assert Topic.exists? - assert !Topic.first.replies.exists?(nil) - assert Topic.first.replies.exists? + assert !Topic.order(:id).first.replies.exists?(nil) + assert Topic.order(:id).first.replies.exists? end # ensures +exists?+ runs valid SQL by excluding order value diff --git a/activerecord/test/cases/identity_map_test.rb b/activerecord/test/cases/identity_map_test.rb index 3efc8bf559..24132c7617 100644 --- a/activerecord/test/cases/identity_map_test.rb +++ b/activerecord/test/cases/identity_map_test.rb @@ -301,20 +301,20 @@ class IdentityMapTest < ActiveRecord::TestCase posts = Post.find(:all, :select => 'distinct posts.*', :include => :author, :joins => [:comments], :conditions => "comments.body like 'Thank you%'", :order => 'posts.id') assert_equal [posts(:welcome)], posts assert_equal authors(:david), assert_no_queries { posts[0].author} - assert_same posts.first.author, Author.first + assert_same posts.first.author, Author.order(:id).first posts = Post.find(:all, :select => 'distinct posts.*', :include => :author, :joins => [:comments], :conditions => "comments.body like 'Thank you%'", :order => 'posts.id') assert_equal [posts(:welcome)], posts assert_equal authors(:david), assert_no_queries { posts[0].author} - assert_same posts.first.author, Author.first + assert_same posts.first.author, Author.order(:id).first posts = Post.find(:all, :include => :author, :joins => {:taggings => :tag}, :conditions => "tags.name = 'General'", :order => 'posts.id') assert_equal posts(:welcome, :thinking), posts - assert_same posts.first.author, Author.first + assert_same posts.first.author, Author.order(:id).first posts = Post.find(:all, :include => :author, :joins => {:taggings => {:tag => :taggings}}, :conditions => "taggings_tags.super_tag_id=2", :order => 'posts.id') assert_equal posts(:welcome, :thinking), posts - assert_same posts.first.author, Author.first + assert_same posts.first.author, Author.order(:id).first end def test_eager_loading_with_conditions_on_string_joined_table_preloads @@ -336,12 +336,12 @@ class IdentityMapTest < ActiveRecord::TestCase ############################################################################## def test_reload_object_if_save_failed - developer = Developer.first + developer = Developer.order(:id).first developer.salary = 0 assert !developer.save - same_developer = Developer.first + same_developer = Developer.order(:id).first assert_not_same developer, same_developer assert_not_equal 0, same_developer.salary @@ -349,12 +349,12 @@ class IdentityMapTest < ActiveRecord::TestCase end def test_reload_object_if_forced_save_failed - developer = Developer.first + developer = Developer.order(:id).first developer.salary = 0 assert_raise(ActiveRecord::RecordInvalid) { developer.save! } - same_developer = Developer.first + same_developer = Developer.order(:id).first assert_not_same developer, same_developer assert_not_equal 0, same_developer.salary @@ -362,12 +362,12 @@ class IdentityMapTest < ActiveRecord::TestCase end def test_reload_object_if_update_attributes_fails - developer = Developer.first + developer = Developer.order(:id).first developer.salary = 0 assert !developer.update_attributes(:salary => 0) - same_developer = Developer.first + same_developer = Developer.order(:id).first assert_not_same developer, same_developer assert_not_equal 0, same_developer.salary @@ -379,10 +379,10 @@ class IdentityMapTest < ActiveRecord::TestCase ############################################################################## def test_find_using_identity_map_respects_readonly_when_loading_associated_object_first - author = Author.first + author = Author.order(:id).first readonly_comment = author.readonly_comments.first - comment = Comment.first + comment = Comment.order(:id).first assert !comment.readonly? assert readonly_comment.readonly? @@ -392,10 +392,10 @@ class IdentityMapTest < ActiveRecord::TestCase end def test_find_using_identity_map_respects_readonly - comment = Comment.first + comment = Comment.order(:id).first assert !comment.readonly? - author = Author.first + author = Author.order(:id).first readonly_comment = author.readonly_comments.first assert readonly_comment.readonly? @@ -405,13 +405,13 @@ class IdentityMapTest < ActiveRecord::TestCase end def test_find_using_select_and_identity_map - author_id, author = Author.select('id').first, Author.first + author_id, author = Author.select('id').order(:id).first, Author.order(:id).first assert_equal author_id, author assert_same author_id, author assert_not_nil author.name - post, post_id = Post.first, Post.select('id').first + post, post_id = Post.order(:id).first, Post.select('id').order(:id).first assert_equal post_id, post assert_same post_id, post diff --git a/activerecord/test/cases/json_serialization_test.rb b/activerecord/test/cases/json_serialization_test.rb index d9e350abc0..7240616085 100644 --- a/activerecord/test/cases/json_serialization_test.rb +++ b/activerecord/test/cases/json_serialization_test.rb @@ -211,7 +211,7 @@ class DatabaseConnectedJsonEncodingTest < ActiveRecord::TestCase ['"name":"David"', '"posts":[', '{"id":1}', '{"id":2}', '{"id":4}', '{"id":5}', '{"id":6}', '"name":"Mary"', '"posts":[', '{"id":7}', '{"id":9}'].each do |fragment| assert json.include?(fragment), json - end + end end def test_should_allow_options_for_hash_of_authors @@ -223,7 +223,7 @@ class DatabaseConnectedJsonEncodingTest < ActiveRecord::TestCase end def test_should_be_able_to_encode_relation - authors_relation = Author.where(:id => [@david.id, @mary.id]) + authors_relation = Author.where(:id => [@david.id, @mary.id]).order(:id) json = ActiveSupport::JSON.encode authors_relation, :only => :name assert_equal '[{"author":{"name":"David"}},{"author":{"name":"Mary"}}]', json diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 15c45ca60e..817898f190 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -876,7 +876,7 @@ class TestNestedAttributesWithNonStandardPrimaryKeys < ActiveRecord::TestCase def test_should_update_existing_records_with_non_standard_primary_key @owner.update_attributes(@params) - assert_equal ['Foo', 'Bar'], @owner.pets.map(&:name) + assert_equal %w(Bar Foo), @owner.pets.map(&:name).sort end def test_attr_accessor_of_child_should_be_value_provided_during_update_attributes diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index adfd8e83a1..e4b8caae52 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -17,15 +17,16 @@ require 'rexml/document' require 'active_support/core_ext/exception' class PersistencesTest < ActiveRecord::TestCase + fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, + 'warehouse-things', :authors, :categorizations, :categories, :posts, :minivans - fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse-things', :authors, :categorizations, :categories, :posts, :minivans - - # Oracle UPDATE does not support ORDER BY - unless current_adapter?(:OracleAdapter) + # Skip databases that don't support UPDATE + ORDER BY + unless current_adapter?(:OracleAdapter, :PostgreSQLAdapter) def test_update_all_ignores_order_without_limit_from_association author = authors(:david) assert_nothing_raised do - assert_equal author.posts_with_comments_and_categories.length, author.posts_with_comments_and_categories.update_all([ "body = ?", "bulk update!" ]) + assert_equal author.posts_with_comments_and_categories.length, + author.posts_with_comments_and_categories.update_all([ "body = ?", "bulk update!" ]) end end diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 5e0caf5fce..bf2807c384 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -674,7 +674,7 @@ class RelationTest < ActiveRecord::TestCase def test_relation_merging_with_preload ActiveRecord::IdentityMap.without do [Post.scoped.merge(Post.preload(:author)), Post.preload(:author).merge(Post.scoped)].each do |posts| - assert_queries(2) { assert posts.first.author } + assert_queries(2) { assert posts.order(:id).first.author } end end end diff --git a/activerecord/test/cases/timestamp_test.rb b/activerecord/test/cases/timestamp_test.rb index 447aa29ffe..28543a5a3a 100644 --- a/activerecord/test/cases/timestamp_test.rb +++ b/activerecord/test/cases/timestamp_test.rb @@ -10,7 +10,7 @@ class TimestampTest < ActiveRecord::TestCase fixtures :developers, :owners, :pets, :toys, :cars, :tasks def setup - @developer = Developer.first + @developer = Developer.order(:id).first @developer.update_attribute(:updated_at, Time.now.prev_month) @previously_updated_at = @developer.updated_at end diff --git a/activerecord/test/cases/yaml_serialization_test.rb b/activerecord/test/cases/yaml_serialization_test.rb index 5a38f2c6ee..3b02526916 100644 --- a/activerecord/test/cases/yaml_serialization_test.rb +++ b/activerecord/test/cases/yaml_serialization_test.rb @@ -12,7 +12,7 @@ class YamlSerializationTest < ActiveRecord::TestCase end def test_roundtrip - topic = Topic.first + topic = Topic.order(:id).first assert topic t = YAML.load YAML.dump topic assert_equal topic, t @@ -24,7 +24,7 @@ class YamlSerializationTest < ActiveRecord::TestCase end def test_encode_with_coder - topic = Topic.first + topic = Topic.order(:id).first coder = {} topic.encode_with coder assert_equal({'attributes' => topic.attributes}, coder) @@ -34,7 +34,7 @@ class YamlSerializationTest < ActiveRecord::TestCase require 'psych' def test_psych_roundtrip - topic = Topic.first + topic = Topic.order(:id).first assert topic t = Psych.load Psych.dump topic assert_equal topic, t diff --git a/activerecord/test/models/company.rb b/activerecord/test/models/company.rb index 5c95b21428..f8e259fdfe 100644 --- a/activerecord/test/models/company.rb +++ b/activerecord/test/models/company.rb @@ -104,7 +104,7 @@ class Firm < Company end class DependentFirm < Company - has_one :account, :foreign_key => "firm_id", :dependent => :nullify + has_one :account, :foreign_key => "firm_id", :dependent => :nullify, :order => "accounts.id" has_many :companies, :foreign_key => 'client_of', :dependent => :nullify end diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index ad87d8b6ac..c864d70fa2 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -492,6 +492,18 @@ module ApplicationTests assert_match 'src="/sub/uri/assets/rails.png"', File.read("#{app_path}/public/assets/app.js") end + test "html assets are compiled when executing precompile" do + app_file "app/assets/pages/page.html.erb", "<%= javascript_include_tag :application %>" + ENV["RAILS_ENV"] = "production" + ENV["RAILS_GROUP"] = "assets" + + quietly do + Dir.chdir(app_path){ `bundle exec rake assets:precompile` } + end + + assert File.exists?("#{app_path}/public/assets/page.html") + end + private def app_with_assets_in_view diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 3f4e160988..16e4ac0881 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -37,6 +37,25 @@ class MigrationGeneratorTest < Rails::Generators::TestCase assert_method :change, content do |up| assert_match(/add_column :posts, :title, :string/, up) assert_match(/add_column :posts, :body, :text/, up) + assert_no_match(/\n\n/, up) + end + end + end + + def test_remove_migration_with_indexed_attribute + migration = "remove_title_body_from_posts" + run_generator [migration, "title:string:index", "body:text"] + + assert_migration "db/migrate/#{migration}.rb" do |content| + assert_method :up, content do |up| + assert_match(/remove_column :posts, :title/, up) + assert_match(/remove_column :posts, :body/, up) + end + + assert_method :down, content do |down| + assert_match(/add_column :posts, :title, :string/, down) + assert_match(/add_column :posts, :body, :text/, down) + assert_match(/add_index :posts, :title/, down) end end end |