Commit Graph

53097 Commits

Author SHA1 Message Date
claudiob
82239a995d Remove wrong doc line about AC::Parameters
AC::Parameters does not inherit from HashWithIndifferentAccess
since #20868 by @sikachu
2015-09-10 14:48:23 -07:00
Aaron Patterson
fecf9d729a ensure that mutating headers will impact the content_type method 2015-09-08 16:14:47 -07:00
Aaron Patterson
a27bb77482 mime_type will always return a string 2015-09-08 16:14:47 -07:00
Aaron Patterson
c10efc8386 remove parse_content_type parameter
This method is specifically about the content type so lets remove the
parameter.
2015-09-08 16:14:47 -07:00
Aaron Patterson
376cccbdc1 avoid allocations when there is no content type set
create a singleton content type that just has nils, so that we don't
have to allocate a content type object all the time.
2015-09-08 16:14:47 -07:00
Aaron Patterson
8301969df9 handle implicit rendering correctly
If someone sets just a charset, but depends on the implicit type from
rendering, this will store a strange content type header that looks like
this:  `; charset=blah`.  This is so that when the content type header
is parsed again, it will return nil for the actual type.
2015-09-08 16:14:47 -07:00
Aaron Patterson
bf8b22b392 remove mime type lookups when parsing the content type
It turns out that the response object never really cares what the mime
type object is, so just use the string.
2015-09-08 16:14:47 -07:00
Aaron Patterson
31b3294d49 refactor content type setting
pull content-type setting to a private method to dry it up.
2015-09-08 16:14:47 -07:00
Aaron Patterson
1cc315c83c make Content-Type header the canonical location for content-type info
Instead of storing content type information in an ivar and a header,
lets move to just store the content type info in just the header.
2015-09-08 16:14:47 -07:00
Aaron Patterson
25791b46dc pull content type parsing in to a method
we'll use this method later to lazily parse content type headers.
2015-09-08 16:14:46 -07:00
Aaron Patterson
f9ff4e591e ensure that content type defaults to text / html when setting charset 2015-09-08 16:14:41 -07:00
Aaron Patterson
cd8eb351fb push content_type assigment in to metal
everything above metal really doesn't care about setting the content
type, so lets rearrange these methods to be in metal.
2015-09-08 16:14:41 -07:00
Aaron Patterson
7056e2aa18 avoid useless string allocations
_set_content_type only does something when there is a request object,
otherwise the return value of _get_content_type is always ignored. This
commit moves everything to the module that has access to the request
object so we'll never to_s unless there is a reason
2015-09-08 16:14:41 -07:00
Aaron Patterson
b42c586365 use accessors instead of manipulating the hash
in the future I would like to make the header hash read only (or at
least remove guarantees that mutations will do anything).
2015-09-08 16:14:41 -07:00
Kasper Timm Hansen
3e55fd755a Merge pull request #21518 from codebaker95/activejob_logging_fix
Properly log nested parameters to Active Job
2015-09-08 23:53:37 +02:00
Marek Pieczyk
26f37f7c40 Properly log nested parameters to Active Job
Refactor arguments logging method for Active Job
2015-09-08 23:28:12 +02:00
Rafael Mendonça França
997acb9aad Merge pull request #21556 from artofhuman/master
Fix typo in activemodel changelog [ci skip]
2015-09-08 15:43:45 -03:00
Semyon Pupkov
aef6b79967 Fix typo in activemodel changelog 2015-09-08 23:37:17 +05:00
Kasper Timm Hansen
72889a6be4 Push key_generator into SerializedCookieJars
It's only used there.
2015-09-08 20:27:05 +02:00
Kasper Timm Hansen
57c4a58d02 Move the request method in to the AbstractCookieJar
`CookieJar` is only at the start of the chain and has its own
request method, so we don't need it in the module.
2015-09-08 20:27:05 +02:00
Kasper Timm Hansen
e05136ab41 Pull up parse to the legacy upgrading module
It was the same in both legacy versions of the signed and encrypted cookie jars.
2015-09-08 20:27:05 +02:00
Kasper Timm Hansen
c9efdb582a Call super to remove the decrypt_and_verify method
The `EncryptedCookieJar` already calls it for us, so just delegate to its `parse` implementation.
2015-09-08 20:27:05 +02:00
Kasper Timm Hansen
c17649e062 Call super to remove the verify method
`SignedCookieJar`'s parse method already attempts to verify the message,
so we can just call super and try the old verifier if it fails.
2015-09-08 20:27:05 +02:00
Kasper Timm Hansen
39882c49dc Add parse method to share deserialization logic.
Cuts down on the duplicated reading parts.
2015-09-08 20:27:05 +02:00
Kasper Timm Hansen
94b313db8d Add commit in the EncryptedCookieJar
Gets rid of the option parsing and makes what the encryptor does stand out.
2015-09-08 20:27:04 +02:00
Kasper Timm Hansen
b807ac7a7a Use commit in the SignedCookieJar
Lets us avoid worrying about parsing the options and doing just what we need.
2015-09-08 20:27:04 +02:00
Kasper Timm Hansen
379ddf54c0 Add commit method to share option normalization
Remove the clutter to make PermanentCookieJar's one change stand out.
2015-09-08 20:27:04 +02:00
Kasper Timm Hansen
143d047d65 Add AbstractCookieJar class.
Eventually this will be the superclass of all the chained jars.
2015-09-08 20:27:04 +02:00
Rafael Mendonça França
ed3d213eb6 Use released mysql2 2015-09-08 14:01:04 -03:00
Rafael Mendonça França
f883867dd6 Merge pull request #21502 from bernerdschaefer/bs-polymorphic-url_for-dups-arguments
`url_for` does not modify polymorphic options
2015-09-08 13:49:22 -03:00
Richard Schneeman
0c66326124 Merge pull request #21552 from ronakjangir47/fixed_docs
Fixed Time conversion example for UTC time zone [ci skip]
2015-09-08 11:46:42 -05:00
Ronak Jangir
8aa476869d Fixed Time conversion example for UTC time zone [ci skip] 2015-09-08 21:57:24 +05:30
Rafael Mendonça França
ff83868b10 Merge pull request #21535 from dmitry/feature/validate-multiple-contexts
Validate multiple contexts on `valid?` and `invalid?` at once
2015-09-08 13:12:05 -03:00
Yves Senn
8d1af2b10c Merge pull request #21512 from X0nic/guides-clarify-timeout-error
[Rails Guides] clarify `ActiveRecord::ConnectionTimeoutError`
2015-09-08 17:28:59 +02:00
Eileen M. Uchitelle
269050072d Merge pull request #21511 from rwz/ar-exceptions-no-args
Removes mandatory arguments from AR exceptions
2015-09-08 08:13:57 -04:00
Yves Senn
e0cdc7c29d Merge pull request #21548 from yui-knk/feature/define_tables_as_interface
Define `SchemaStatements#tables` as interface
2015-09-08 14:10:18 +02:00
yui-knk
1fbd954e6a Define SchemaStatements#tables as interface
These 3 methods expect `ConnectionAdapters` to have `tables` method,
so make it clear that `tables` method is interface.

* `ConnectionAdapters::SchemaCache#prepare_tables`
* `db:schema:cache:dump` task
* `SchemaDumper#tables`
2015-09-08 21:02:25 +09:00
Yves Senn
3e617bbf45 Merge pull request #21530 from arvindmehra/am-ar-to-activerecord
Replace AR with ActiveRecord to make it more readable [ci skip]
2015-09-08 13:47:31 +02:00
Yves Senn
8a639ffca6 Merge pull request #21528 from yui-knk/test/add_tests_for_mysql2_view
Add tests for test/cases/adapters/mysql2/view_test.rb
2015-09-08 13:28:44 +02:00
yui-knk
bb0d70788a Add view tests for MySQL
Basically view tests for MySQL are same with
`test/cases/adapters/postgresql/view_test.rb`.

So move `test/cases/adapters/postgresql/view_test.rb` to
`test/cases/view_test.rb` and make them only run if
`current_adapter` supports writable view.
2015-09-08 20:09:41 +09:00
arvind
dad0c2677c Replace AR with ActiveRecord to make it more readable [ci skip] 2015-09-08 16:02:16 +05:30
Kasper Timm Hansen
e75b92c032 Merge pull request #21519 from y-yagi/test_runner_raise_error
raise LoadError when a non-existent file or directory is specified to the test runner
2015-09-08 10:01:32 +02:00
Rafael Mendonça França
b4f82efddc 💣 2015-09-08 01:07:48 -03:00
Rafael Mendonça França
0675210c95 Memoized reflections accessor
Its value never change since associations are defined at class load time
so there is no need to build the hash everytime the method is called.

Before this change:

    Calculating -------------------------------------
             reflections   804.000  i/100ms
    -------------------------------------------------
             reflections      8.213k (±26.2%) i/s -     36.180k

After this change:

    Calculating -------------------------------------
             reflections    24.548k i/100ms
    -------------------------------------------------
             reflections      1.591M (±25.7%) i/s -      7.364M

Benchmark script:

    require 'bundler/setup'

    require 'active_record'
    require 'benchmark/ips'

    ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
    ActiveRecord::Migration.verbose = false

    ActiveRecord::Schema.define do
      100.times do |i|
        create_table "users#{i}", force: true
      end

      create_table :cars, force: true do |t|
        100.times do |i|
          t.references "users#{i}"
        end
      end
    end

    class Car < ActiveRecord::Base
      100.times do |i|
        belongs_to "users#{i}".to_sym
      end
    end

    Benchmark.ips do |x|
      x.report('reflections') { Car.reflections }
    end
2015-09-08 01:04:22 -03:00
Rafael Mendonça França
9bf772d936 Merge pull request #21537 from tgxworld/perf_reduce_allocation
PERF: Reduce allocation in `resolve_column_aliases`.
2015-09-07 23:59:55 -03:00
Guo Xiang Tan
607a4482f0 Reduce allocation in resolve_column_aliases.
Benchmark Script Used:
```
begin
  require 'bundler/inline'
rescue LoadError => e
  $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
  raise e
end

gemfile(true) do
  source 'https://rubygems.org'
  gem 'rails', path: '~/rails' # master against ref "f1f0a3f8d99aef8aacfa81ceac3880dcac03ca06"
  gem 'arel', github: 'rails/arel', branch: 'master'
  gem 'rack', github: 'rack/rack', branch: 'master'
  gem 'sass'
  gem 'sprockets-rails', github: 'rails/sprockets-rails', branch: 'master'
  gem 'sprockets', github: 'rails/sprockets', branch: 'master'
  gem 'pg'
  gem 'benchmark-ips'
end

require 'active_record'
require 'benchmark/ips'

ActiveRecord::Base.establish_connection('postgres://postgres@localhost:5432/rubybench')

ActiveRecord::Migration.verbose = false

ActiveRecord::Schema.define do
  create_table :users, force: true do |t|
    t.string :name, :email
    t.timestamps null: false
  end
end

class User < ActiveRecord::Base; end

attributes = {
  name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
  email: "foobar@email.com",
}

1000.times { User.create!(attributes) }

Benchmark.ips(5, 3) do |x|
  x.report('where with hash single') { User.where(name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.") }
  x.report('where with string single') { User.where("users.name = ?", "Lorem ipsum dolor sit amet, consectetur adipiscing elit.") }
  x.report('where with hash double') { User.where(name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", email: "foobar@email.com") }
  x.report('where with string double') { User.where("users.name = ? AND users.email = ?", "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "foobar@email.com") }
  x.compare!
end
```

Before:
```
Calculating -------------------------------------
where with hash single
                         3.300k i/100ms
where with string single
                         4.965k i/100ms
where with hash double
                         2.594k i/100ms
where with string double
                         4.400k i/100ms
-------------------------------------------------
where with hash single
                         35.161k (± 1.2%) i/s -    178.200k
where with string single
                         53.368k (± 2.9%) i/s -    268.110k
where with hash double
                         27.364k (± 1.1%) i/s -    137.482k
where with string double
                         46.876k (± 2.1%) i/s -    237.600k

Comparison:
where with string single:    53368.1 i/s
where with string double:    46875.5 i/s - 1.14x slower
where with hash single:    35160.8 i/s - 1.52x slower
where with hash double:    27364.0 i/s - 1.95x slower
```

After:
```
Calculating -------------------------------------
where with hash single
                         3.403k i/100ms
where with string single
                         5.167k i/100ms
where with hash double
                         2.659k i/100ms
where with string double
                         4.597k i/100ms
-------------------------------------------------
where with hash single
                         36.410k (± 1.3%) i/s -    183.762k
where with string single
                         55.009k (± 2.6%) i/s -    279.018k
where with hash double
                         27.951k (± 1.4%) i/s -    140.927k
where with string double
                         48.362k (± 2.6%) i/s -    243.641k

Comparison:
where with string single:    55008.6 i/s
where with string double:    48361.5 i/s - 1.14x slower
where with hash single:    36410.1 i/s - 1.51x slower
where with hash double:    27950.9 i/s - 1.97x slower
```
2015-09-08 09:28:58 +08:00
Jeremy Daer (Kemper)
a11571cec3 Merge pull request #21520 from jeremy/friendlier-force-ssl
Make `config.force_ssl` less dangerous to try and easier to disable
2015-09-07 18:08:54 -07:00
Jeremy Daer
f674922462 Make config.force_ssl less dangerous to try and easier to disable
SSL redirect:
* Move `:host` and `:port` options within `redirect: { … }`. Deprecate.
* Introduce `:status` and `:body` to customize the redirect response.
  The 301 permanent default makes it difficult to test the redirect and
  back out of it since browsers remember the 301. Test with a 302 or 307
  instead, then switch to 301 once you're confident that all is well.

HTTP Strict Transport Security (HSTS):
* Shorter max-age. Shorten the default max-age from 1 year to 180 days,
  the low end for https://www.ssllabs.com/ssltest/ grading and greater
  than the 18-week minimum to qualify for browser preload lists.
* Disabling HSTS. Setting `hsts: false` now sets `hsts: { expires: 0 }`
  instead of omitting the header. Omitting does nothing to disable HSTS
  since browsers hang on to your previous settings until they expire.
  Sending `{ hsts: { expires: 0 }}` flushes out old browser settings and
  actually disables HSTS:
    http://tools.ietf.org/html/rfc6797#section-6.1.1
* HSTS Preload. Introduce `preload: true` to set the `preload` flag,
  indicating that your site may be included in browser preload lists,
  including Chrome, Firefox, Safari, IE11, and Edge. Submit your site:
    https://hstspreload.appspot.com
2015-09-07 17:57:20 -07:00
Jeremy Daer (Kemper)
81dd387258 Merge pull request #21536 from jeremy/support-mysql2-0.4.0
Support mysql2 0.4.0, first release with prepared statements support
2015-09-07 17:51:55 -07:00
Jeremy Daer
5da5e3772c Support mysql2 0.4.0, first release with prepared statements support
Known failure on Ruby 2.3/trunk: brianmario/mysql2#671
2015-09-07 16:37:25 -07:00