diff options
-rw-r--r-- | Gemfile | 20 | ||||
-rw-r--r-- | Gemfile.lock | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb | 16 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb | 6 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/mysql2/connection_test.rb | 21 | ||||
-rw-r--r-- | activerecord/test/cases/attribute_methods/read_test.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/enum_test.rb | 40 | ||||
-rw-r--r-- | activerecord/test/cases/migration/column_attributes_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/quoting_test.rb | 8 | ||||
-rw-r--r-- | activerecord/test/fixtures/books.yml | 1 | ||||
-rw-r--r-- | activerecord/test/models/book.rb | 1 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 1 | ||||
-rw-r--r-- | guides/rails_guides/levenshtein.rb | 4 | ||||
-rw-r--r-- | guides/source/action_view_overview.md | 14 | ||||
-rw-r--r-- | railties/lib/rails/generators.rb | 4 |
15 files changed, 102 insertions, 49 deletions
@@ -25,10 +25,10 @@ gem "bcrypt", "~> 3.1.11", require: false gem "uglifier", ">= 1.3.0", require: false # Track stable branch of sass because it doesn't have circular require warnings. -gem "sass", github: "sass/sass", branch: "stable", require: false +gem "sass", git: "https://github.com/sass/sass", branch: "stable", require: false # FIXME: Remove this fork after https://github.com/nex3/rb-inotify/pull/49 is fixed. -gem "rb-inotify", github: "matthewd/rb-inotify", branch: "close-handling", require: false +gem "rb-inotify", git: "https://github.com/matthewd/rb-inotify", branch: "close-handling", require: false group :doc do gem "sdoc", "~> 0.4.0" @@ -43,19 +43,19 @@ gem "listen", "~> 3.0.5", require: false # Active Job. group :job do - gem "resque", github: "resque/resque", require: false + gem "resque", git: "https://github.com/resque/resque", require: false gem "resque-scheduler", require: false gem "sidekiq", require: false gem "sucker_punch", require: false - gem "delayed_job", require: false, github: "collectiveidea/delayed_job" - gem "queue_classic", github: "QueueClassic/queue_classic", branch: "master", require: false, platforms: :ruby + gem "delayed_job", require: false, git: "https://github.com/collectiveidea/delayed_job" + gem "queue_classic", git: "https://github.com/QueueClassic/queue_classic", branch: "master", require: false, platforms: :ruby gem "sneakers", require: false gem "que", require: false gem "backburner", require: false #TODO: add qu after it support Rails 5.1 # gem 'qu-rails', github: "bkeepers/qu", branch: "master", require: false gem "qu-redis", require: false - gem "delayed_job_active_record", require: false, github: "collectiveidea/delayed_job_active_record" + gem "delayed_job_active_record", require: false, git: "https://github.com/collectiveidea/delayed_job_active_record" gem "sequel", require: false end @@ -109,10 +109,10 @@ end platforms :jruby do if ENV["AR_JDBC"] - gem "activerecord-jdbcsqlite3-adapter", github: "jruby/activerecord-jdbc-adapter", branch: "master" + gem "activerecord-jdbcsqlite3-adapter", git: "https://github.com/jruby/activerecord-jdbc-adapter", branch: "master" group :db do - gem "activerecord-jdbcmysql-adapter", github: "jruby/activerecord-jdbc-adapter", branch: "master" - gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter", branch: "master" + gem "activerecord-jdbcmysql-adapter", git: "https://github.com/jruby/activerecord-jdbc-adapter", branch: "master" + gem "activerecord-jdbcpostgresql-adapter", git: "https://github.com/jruby/activerecord-jdbc-adapter", branch: "master" end else gem "activerecord-jdbcsqlite3-adapter", ">= 1.3.0" @@ -134,7 +134,7 @@ if ENV["ORACLE_ENHANCED"] platforms :ruby do gem "ruby-oci8", "~> 2.2" end - gem "activerecord-oracle_enhanced-adapter", github: "rsim/oracle-enhanced", branch: "master" + gem "activerecord-oracle_enhanced-adapter", git: "https://github.com/rsim/oracle-enhanced", branch: "master" end # A gem necessary for Active Record tests with IBM DB. diff --git a/Gemfile.lock b/Gemfile.lock index cf8bb0fec9..c42815d915 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,5 @@ GIT - remote: git://github.com/QueueClassic/queue_classic.git + remote: https://github.com/QueueClassic/queue_classic revision: c26f2c9f6f6133b946fbcdd7b7ec905a4aca9f94 branch: master specs: @@ -7,14 +7,14 @@ GIT pg (>= 0.17, < 0.19) GIT - remote: git://github.com/collectiveidea/delayed_job.git + remote: https://github.com/collectiveidea/delayed_job revision: 71f1d5faf934d3057abca942f0d410327bc69087 specs: delayed_job (4.1.1) activesupport (>= 3.0, < 5.1) GIT - remote: git://github.com/collectiveidea/delayed_job_active_record.git + remote: https://github.com/collectiveidea/delayed_job_active_record revision: 61e688e03b2ef4004b08de6d1e0a123fda8fffad specs: delayed_job_active_record (4.1.0) @@ -22,7 +22,7 @@ GIT delayed_job (>= 3.0, < 5) GIT - remote: git://github.com/matthewd/rb-inotify.git + remote: https://github.com/matthewd/rb-inotify revision: 90553518d1fb79aedc98a3036c59bd2b6731ac40 branch: close-handling specs: @@ -30,7 +30,7 @@ GIT ffi (>= 0.5.0) GIT - remote: git://github.com/resque/resque.git + remote: https://github.com/resque/resque revision: 06036388ec61e573c761ac5a25a2ef3c76537ec7 specs: resque (1.27.0) @@ -41,7 +41,7 @@ GIT vegas (~> 0.1.2) GIT - remote: git://github.com/sass/sass.git + remote: https://github.com/sass/sass revision: 3fda1cbe70d615e7ef96e28db4fd1f8a3ebb5505 branch: stable specs: diff --git a/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb index c8238eb266..56800f7590 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb @@ -24,11 +24,9 @@ module ActiveRecord # Executes the SQL statement in the context of this connection. def execute(sql, name = nil) - if @connection - # make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been - # made since we established the connection - @connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone - end + # make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been + # made since we established the connection + @connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone super end @@ -71,11 +69,9 @@ module ActiveRecord end def exec_stmt_and_free(sql, name, binds, cache_stmt: false) - if @connection - # make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been - # made since we established the connection - @connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone - end + # make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been + # made since we established the connection + @connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone type_casted_binds = type_casted_binds(binds) diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb index 0130b4ef62..a3e2c913c5 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb @@ -90,7 +90,6 @@ module ActiveRecord #++ def active? - return false unless @connection @connection.ping end @@ -105,10 +104,7 @@ module ActiveRecord # Otherwise, this method does nothing. def disconnect! super - unless @connection.nil? - @connection.close - @connection = nil - end + @connection.close end private diff --git a/activerecord/test/cases/adapters/mysql2/connection_test.rb b/activerecord/test/cases/adapters/mysql2/connection_test.rb index 9ede57d395..e014229650 100644 --- a/activerecord/test/cases/adapters/mysql2/connection_test.rb +++ b/activerecord/test/cases/adapters/mysql2/connection_test.rb @@ -63,6 +63,27 @@ class Mysql2ConnectionTest < ActiveRecord::Mysql2TestCase assert @connection.active? end + def test_execute_after_disconnect + @connection.disconnect! + error = assert_raise(ActiveRecord::StatementInvalid) do + @connection.execute("SELECT 1") + end + assert_match /closed MySQL connection/, error.message + end + + def test_quote_after_disconnect + @connection.disconnect! + error = assert_raise(Mysql2::Error) do + @connection.quote("string") + end + assert_match /closed MySQL connection/, error.message + end + + def test_active_after_disconnect + @connection.disconnect! + assert_equal false, @connection.active? + end + def test_mysql_connection_collation_is_configured assert_equal "utf8_unicode_ci", @connection.show_variable("collation_connection") assert_equal "utf8_general_ci", ARUnit2Model.connection.show_variable("collation_connection") diff --git a/activerecord/test/cases/attribute_methods/read_test.rb b/activerecord/test/cases/attribute_methods/read_test.rb index 2d2ecb4079..074cfe7ffb 100644 --- a/activerecord/test/cases/attribute_methods/read_test.rb +++ b/activerecord/test/cases/attribute_methods/read_test.rb @@ -1,5 +1,4 @@ require "cases/helper" -require "thread" module ActiveRecord module AttributeMethods diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb index c2009843f0..b7641fcf32 100644 --- a/activerecord/test/cases/enum_test.rb +++ b/activerecord/test/cases/enum_test.rb @@ -18,6 +18,7 @@ class EnumTest < ActiveRecord::TestCase assert @book.author_visibility_visible? assert @book.illustrator_visibility_visible? assert @book.with_medium_font_size? + assert @book.medium_to_read? end test "query state with strings" do @@ -26,6 +27,7 @@ class EnumTest < ActiveRecord::TestCase assert_equal "english", @book.language assert_equal "visible", @book.author_visibility assert_equal "visible", @book.illustrator_visibility + assert_equal "medium", @book.difficulty end test "find via scope" do @@ -34,6 +36,7 @@ class EnumTest < ActiveRecord::TestCase assert_equal @book, Book.in_english.first assert_equal @book, Book.author_visibility_visible.first assert_equal @book, Book.illustrator_visibility_visible.first + assert_equal @book, Book.medium_to_read.first end test "find via where with values" do @@ -422,6 +425,43 @@ class EnumTest < ActiveRecord::TestCase assert_not @book.in_french? end + test "query state by predicate with custom suffix" do + assert @book.medium_to_read? + assert_not @book.easy_to_read? + assert_not @book.hard_to_read? + end + + test "enum methods with custom suffix defined" do + assert @book.class.respond_to?(:easy_to_read) + assert @book.class.respond_to?(:medium_to_read) + assert @book.class.respond_to?(:hard_to_read) + + assert @book.respond_to?(:easy_to_read?) + assert @book.respond_to?(:medium_to_read?) + assert @book.respond_to?(:hard_to_read?) + + assert @book.respond_to?(:easy_to_read!) + assert @book.respond_to?(:medium_to_read!) + assert @book.respond_to?(:hard_to_read!) + end + + test "update enum attributes with custom suffix" do + @book.medium_to_read! + assert_not @book.easy_to_read? + assert @book.medium_to_read? + assert_not @book.hard_to_read? + + @book.easy_to_read! + assert @book.easy_to_read? + assert_not @book.medium_to_read? + assert_not @book.hard_to_read? + + @book.hard_to_read! + assert_not @book.easy_to_read? + assert_not @book.medium_to_read? + assert @book.hard_to_read? + end + test "uses default status when no status is provided in fixtures" do book = books(:tlg) assert book.proposed?, "expected fixture to default to proposed status" diff --git a/activerecord/test/cases/migration/column_attributes_test.rb b/activerecord/test/cases/migration/column_attributes_test.rb index ab8229dbae..03d781d3d2 100644 --- a/activerecord/test/cases/migration/column_attributes_test.rb +++ b/activerecord/test/cases/migration/column_attributes_test.rb @@ -63,8 +63,6 @@ module ActiveRecord # Do a manual insertion if current_adapter?(:OracleAdapter) connection.execute "insert into test_models (id, wealth) values (people_seq.nextval, 12345678901234567890.0123456789)" - elsif current_adapter?(:PostgreSQLAdapter) - connection.execute "insert into test_models (wealth) values (12345678901234567890.0123456789)" else connection.execute "insert into test_models (wealth) values (12345678901234567890.0123456789)" end diff --git a/activerecord/test/cases/quoting_test.rb b/activerecord/test/cases/quoting_test.rb index 1c276aa765..296dafacc2 100644 --- a/activerecord/test/cases/quoting_test.rb +++ b/activerecord/test/cases/quoting_test.rb @@ -133,16 +133,12 @@ module ActiveRecord end def test_quote_string_no_column - assert_equal "'lo\\\\l'", @quoter.quote('lo\l', nil) + assert_equal "'lo\\\\l'", @quoter.quote('lo\l') end def test_quote_as_mb_chars_no_column string = ActiveSupport::Multibyte::Chars.new('lo\l') - assert_equal "'lo\\\\l'", @quoter.quote(string, nil) - end - - def test_string_with_crazy_column - assert_equal "'lo\\\\l'", @quoter.quote('lo\l') + assert_equal "'lo\\\\l'", @quoter.quote(string) end def test_quote_duration diff --git a/activerecord/test/fixtures/books.yml b/activerecord/test/fixtures/books.yml index a304fba399..b3625ee72e 100644 --- a/activerecord/test/fixtures/books.yml +++ b/activerecord/test/fixtures/books.yml @@ -9,6 +9,7 @@ awdr: author_visibility: :visible illustrator_visibility: :visible font_size: :medium + difficulty: :medium rfr: author_id: 1 diff --git a/activerecord/test/models/book.rb b/activerecord/test/models/book.rb index 4c275fdebb..17bf3fbcb4 100644 --- a/activerecord/test/models/book.rb +++ b/activerecord/test/models/book.rb @@ -14,6 +14,7 @@ class Book < ActiveRecord::Base enum author_visibility: [:visible, :invisible], _prefix: true enum illustrator_visibility: [:visible, :invisible], _prefix: true enum font_size: [:small, :medium, :large], _prefix: :with, _suffix: true + enum difficulty: [:easy, :medium, :hard], _suffix: :to_read enum cover: { hard: "hard", soft: "soft" } def published! diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 9997ddee77..a4756ec75a 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -98,6 +98,7 @@ ActiveRecord::Schema.define do t.column :author_visibility, :integer, default: 0 t.column :illustrator_visibility, :integer, default: 0 t.column :font_size, :integer, default: 0 + t.column :difficulty, :integer, default: 0 t.column :cover, :string, default: "hard" end diff --git a/guides/rails_guides/levenshtein.rb b/guides/rails_guides/levenshtein.rb index a3e7620444..e947150364 100644 --- a/guides/rails_guides/levenshtein.rb +++ b/guides/rails_guides/levenshtein.rb @@ -1,6 +1,8 @@ module RailsGuides module Levenshtein - # This code is based directly on the Text gem implementation + # This code is based directly on the Text gem implementation. + # Copyright (c) 2006-2013 Paul Battley, Michael Neumann, Tim Fletcher. + # # Returns a value representing the "cost" of transforming str1 into str2 def self.distance(str1, str2) s = str1 diff --git a/guides/source/action_view_overview.md b/guides/source/action_view_overview.md index e11466e79f..ff0127522b 100644 --- a/guides/source/action_view_overview.md +++ b/guides/source/action_view_overview.md @@ -254,12 +254,6 @@ as if we had written: <%= render partial: "product", locals: { product: @product } %> ``` -With the `as` option we can specify a different name for the local variable. For example, if we wanted it to be `item` instead of `product` we would do: - -```erb -<%= render partial: "product", as: "item" %> -``` - The `object` option can be used to directly specify which object is rendered into the partial; useful when the template's object is elsewhere (e.g. in a different instance variable or in a local variable). For example, instead of: @@ -274,12 +268,18 @@ we would do: <%= render partial: "product", object: @item %> ``` -The `object` and `as` options can also be used together: +With the `as` option we can specify a different name for the said local variable. For example, if we wanted it to be `item` instead of `product` we would do: ```erb <%= render partial: "product", object: @item, as: "item" %> ``` +This is equivalent to + +```erb +<%= render partial: "product", locals: { item: @item } %> +``` + #### Rendering Collections It is very common that a template will need to iterate over a collection and render a sub-template for each of the elements. This pattern has been implemented as a single method that accepts an array and renders a partial for each one of the elements in the array. diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 6a112fc710..fd35dfd1a2 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -277,7 +277,9 @@ module Rails protected - # This code is based directly on the Text gem implementation + # This code is based directly on the Text gem implementation. + # Copyright (c) 2006-2013 Paul Battley, Michael Neumann, Tim Fletcher. + # # Returns a value representing the "cost" of transforming str1 into str2 def self.levenshtein_distance(str1, str2) s = str1 |