Commit Graph

34079 Commits

Author SHA1 Message Date
Rafael Mendonça França
3ec443086b Merge pull request #8312 from senny/make_active_model_parts_individually_loadable
make sure that individual parts `ActiveModel` can be required by itself
2012-11-26 04:11:17 -08:00
Andrew White
be2a3b0a93 Improve clarity of routing tests
Move the routes for each test inside the test method so that
it's easier to see which routes are applicable to which test.

To ensure that each test wasn't invalidated the changes were
done by first removing all of the routes, ensuring that all
of the tests failed and then adding the routes back to each
test one by one. One test for `assert_recognizes` was
removed as it wasn't actually testing the defined routes and
is now tested more thoroughly in routing_assertions_test.rb.

One downside is that the test suite takes about 1s longer
due to having to using `method_missing` for handling the url
helpers as using `include url_helpers` isn't isolated
for each test.
2012-11-26 11:28:05 +00:00
Carlos Antonio da Silva
3da1649828 Require active_model/railtie directly instead of rails/all
Use Class.new with a block instead of tap to configure it.
2012-11-26 09:19:57 -02:00
Carlos Antonio da Silva
02c30c6426 Merge pull request #8316 from roberto/assert_template_validate_options
assert_template: validating option keys

It only handles the keys locals, partial, layout and count.

    assert_template(foo: "bar") # raises ArgumentError
    assert_template(leiaute: "test") # raises ArgumentError
2012-11-26 02:41:45 -08:00
David Heinemeier Hansson
1081ae20fb Merge pull request #8317 from latortuga/cache-digest-opt-out
Add explicit opt-out for fragment cache digesting
2012-11-26 00:59:48 -08:00
Aaron Patterson
dc973e7856 schema cache already has the columns as a hash, so use that 2012-11-25 22:53:46 -08:00
Aaron Patterson
c99e34e90d speed up fixture loading by querying the schema cache for column names 2012-11-25 22:49:48 -08:00
Drew Ulmer
7fb8c67047 Add explicit opt-out for fragment cache digesting
This add support for sending an explicit opt-out of the "Russian-doll"
cache digest feature on a case-by-case basis. This is useful when cache-
expiration needs to be performed manually and it would be otherwise
difficult to know the exact name of a digested cache key.

More information: https://github.com/rails/cache_digests/pull/16
2012-11-25 22:10:44 -06:00
Roberto Soares
3f2c011d31 assert_template: validating option keys 2012-11-25 23:39:08 -03:00
Carlos Antonio da Silva
4d0dc53249 Merge pull request #8302 from roberto/assert_template_empty_string
assert_template("") will now fail no matter whether a template has been rendered or not.
2012-11-25 16:45:55 -08:00
Carlos Antonio da Silva
0a7ba19dcc Merge pull request #8311 from alisdair/dirty-nullable-datetime
Don't call will_change! for datetime nil->"".
2012-11-25 14:29:34 -08:00
Yves Senn
22598ee599 cleanup, removed dispensable require statements from ActiveModel 2012-11-25 17:08:57 +01:00
Yves Senn
b7edbc718b cleanup, remove broken whitespace 2012-11-25 16:57:29 +01:00
Alisdair McDiarmid
fc4e387d7a Don't call will_change! for datetime nil->"".
Setting a nil datetime attribute to a blank string should not cause the
attribute to be dirty.

Fix #8310
2012-11-25 11:24:27 +00:00
Carlos Antonio da Silva
e95b9d6c68 Merge pull request #8306 from senny/documentation_for_hidden_field_id
Document :hidden_field_id option for fields_for [ci skip]
2012-11-24 09:59:03 -08:00
Yves Senn
47b4ed90f5 document :hidden_field_id option for fields_for 2012-11-24 18:12:23 +01:00
Carlos Antonio da Silva
d23c761f5a Fix changelog entry about fast_string_to_time fix
Introduced in 53ca22f2e11cd3050d75385bc31b6bb5055a2738.
Thanks @rochefort. [ci skip]
2012-11-24 09:30:18 -02:00
Carlos Antonio da Silva
ccdf54d6fc Refector a bit to remove extra slice iteration and splat call
This yields a small bit of performance improvement when building the
defaults from constraints, specially considering that it's rather common
for constraints to be empty.

Also, there's a bit of duplicated code in here that I have to check
before extracting.
2012-11-24 09:19:21 -02:00
Carlos Antonio da Silva
d98014cbcb Use merge! in some places to avoid creating extra hashes 2012-11-24 09:19:21 -02:00
Carlos Antonio da Silva
2b64e9b1bd Simplify scope options recovery by using merge!
Instead of iterating again over the options and setting one by one, we
can just merge the recover hash back to the scope one since all keys
match.
2012-11-24 09:19:21 -02:00
Carlos Antonio da Silva
beeb9529b8 Normalize scope recovering :blocks option name
Use the same :blocks key in the recover hash to revert the scope options
later.
2012-11-24 09:19:20 -02:00
Carlos Antonio da Silva
5b9f983c65 Simplify constraints condition in scope when checking for Hash 2012-11-24 09:19:20 -02:00
Carlos Antonio da Silva
b69fd477e5 Move initialize_copy method around to let new method / build alias closer 2012-11-24 09:19:20 -02:00
Roberto Soares
2d6c4ec731 assert_template fails with empty string. 2012-11-23 18:14:35 -03:00
Roberto Soares
20723ca498 assert_template fails with empty string when a template has been rendered
For instance, it prevents false positive in this case:

    file = nil
    get :index
    assert_template("#{file}")
2012-11-23 16:15:17 -03:00
Vijay Dev
36ee5802a5 Merge branch 'master' of github.com:lifo/docrails 2012-11-23 22:26:53 +05:30
Rafael Mendonça França
b313bcba07 Merge pull request #8291 from senny/8265_build_with_polymorphic_association
prevent mass assignment of polymorphic type when using `build`

Conflicts:
	activerecord/CHANGELOG.md
2012-11-22 11:52:01 -02:00
Carlos Antonio da Silva
43dd9c87fd Indent changelog markdown code to highlight correctly
[ci skip]
2012-11-22 08:42:17 -02:00
Andrew White
9f68d524ba Merge pull request #8114 from guilleiguaran/use-symbols-in-scope
Allow setting a symbol as path in scope on routes
2012-11-22 01:27:14 -08:00
Yves Senn
053bfa2304 prevent mass assignment of polymorphic type when using build
Closes #8265
2012-11-22 08:58:00 +01:00
Guillermo Iguaran
0d3a9e8a6b Allow setting a symbol as path in scope on routes
Was surprising found that this example doesn't work:

  scope :api do
    resources :users
  end

and the right form to use it is:

  scope 'api' do
    resources :users
  end

I think this should work similary as `namespace` where both are allowed.
These two are equivalent:

  namespace :api do
    resources :users
  end

  namespace 'api' do
    resources :user
  end
2012-11-21 22:59:00 -05:00
Carlos Antonio da Silva
0134ca6a01 Remove private partial/template renderer methods
Since now these objects are not cached anymore, there's no need to have
these private methods, just instantiate each of them in the necessary
place.
2012-11-21 23:32:43 -02:00
Carlos Antonio da Silva
a9aeba671d Merge branch 'deprecate-calculations-with-block'
Follow up of the discussion from the original merge commit:
f9cb645dfc (commitcomment-1414561)

We want to avoid people's mistakes with methods like count and sum when
called with a block, that can easily lead to code performing poorly and
that could be way better written with a db query.

Please check the discussion there for more background.
Closes #8268
2012-11-21 22:23:41 -02:00
Carlos Antonio da Silva
fd1c45761e Remove the #sum method from CollectionAssociation
Since edd94cee9af1688dd036fc58fd405adb30a5e0da, CollectionProxy
delegates all calculation methods - except count - to the scope,
which does basically what this method was doing, but since we're
delegating from the proxy, the association method was never called.
2012-11-21 22:21:04 -02:00
Carlos Antonio da Silva
ad9983f625 Deprecate Relation#sum with a block.
To perform a sum calculation over the array of elements, use to_a.sum(&block).

Please check the discussion in f9cb645dfcb5cc89f59d2f8b58a019486c828c73
for more context.
2012-11-21 22:21:01 -02:00
Carlos Antonio da Silva
76a6bfd6c8 Revert "Yield only one argument instead of splatting."
This reverts commit f9cb645dfcb5cc89f59d2f8b58a019486c828c73.

Conflicts:
	activerecord/CHANGELOG.md

Revert "Allow blocks for count with ActiveRecord::Relation. Document and test that sum allows blocks"

This reverts commit 9cc2bf69ce296b7351dc612a8366193390a305f3.

Conflicts:
	activerecord/lib/active_record/relation/calculations.rb
2012-11-21 22:18:51 -02:00
Jon Leighton
ae934aef4a Don't allocate new strings in compiled attribute methods
This improves memory and performance without having to use symbols which
present DoS problems. Thanks @headius and @tenderlove for the
suggestion.

This was originally committed in
f1765019ce9b6292f2264b4601dad5daaffe3a89, and then reverted in
d3494903719682abc0948bef290af0d3d7b5a440 due to it causing problems in a
real application. This second attempt should solve that.

Benchmark
---------

require 'active_record'
require 'benchmark/ips'

ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')

class Post < ActiveRecord::Base
  connection.create_table :posts, force: true do |t|
    t.string :name
  end
end

post = Post.create name: 'omg'

Benchmark.ips do |r|
  r.report('Post.new')          { Post.new name: 'omg' }
  r.report('post.name')         { post.name }
  r.report('post.name=')        { post.name = 'omg' }
  r.report('Post.find(1).name') { Post.find(1).name }
end

Before
------

Calculating -------------------------------------
            Post.new      1419 i/100ms
           post.name      7538 i/100ms
          post.name=      3024 i/100ms
   Post.find(1).name       243 i/100ms
-------------------------------------------------
            Post.new    20637.6 (±12.7%) i/s -     102168 in   5.039578s
           post.name  1167897.7 (±18.2%) i/s -    5186144 in   4.983077s
          post.name=    64305.6 (±9.6%) i/s -     317520 in   4.998720s
   Post.find(1).name     2678.8 (±10.8%) i/s -      13365 in   5.051265s

After
-----

Calculating -------------------------------------
            Post.new      1431 i/100ms
           post.name      7790 i/100ms
          post.name=      3181 i/100ms
   Post.find(1).name       245 i/100ms
-------------------------------------------------
            Post.new    21308.8 (±12.2%) i/s -     105894 in   5.053879s
           post.name  1534103.8 (±2.1%) i/s -    7634200 in   4.979405s
          post.name=    67441.0 (±7.5%) i/s -     337186 in   5.037871s
   Post.find(1).name     2681.9 (±10.6%) i/s -      13475 in   5.084511s
2012-11-21 21:59:09 +00:00
Carlos Antonio da Silva
96106a1493 Move migration test together with other join table tests 2012-11-21 19:34:55 -02:00
Carlos Antonio da Silva
c2c1ecb05e Use secure password min cost option in its own tests for a speed up
Around 0.564359s => 0.092244s speed up in my machine.
2012-11-21 19:34:55 -02:00
Jon Leighton
293c121fee Merge pull request #8183 from jcoglan/objectless_sessions
Store FlashHashes in the session as plain hashes
2012-11-21 11:50:27 -08:00
Rafael Mendonça França
b6793ba110 Merge pull request #7716 from steveklabnik/issue_7715
Coerce strings in create_join_table.
2012-11-21 11:35:49 -08:00
Steve Klabnik
48a035712e Coerce strings in create_join_table.
If you accidentally pass a string and a symbol, this breaks. So
we coerce them both to strings.

Fixes #7715
2012-11-21 13:21:18 -06:00
Carlos Antonio da Silva
0cf3092e60 Merge pull request #8290 from cpatuzzo/master
Fixed a typo
2012-11-21 10:17:46 -08:00
Chris Patuzzo
104f4fde1d Typo 2012-11-21 18:04:08 +00:00
Rafael Mendonça França
1c0e7ab2f8 Merge pull request #6245 from bogdan/bc_timestamp
Postgresql adapter: fix handling of BC timestamps
2012-11-21 09:34:55 -08:00
Rafael Mendonça França
6b266c21b2 Merge pull request #8289 from semaperepelitsa/pg_adapter_refactoring_squashed
Refactoring, testing and documenting pg_connection.distinct
2012-11-21 09:33:41 -08:00
Semyon Perepelitsa
2197e1f365 Refactoring, testing and documenting pg_connection.distinct 2012-11-21 23:51:32 +08:00
Bogdan Gusiev
fa73cf7275 Fix postgresql adapter to handle bc timestamps correctly 2012-11-21 16:11:14 +02:00
Rafael Mendonça França
f058e565c1 Remove return guard and use code convetions 2012-11-20 22:44:33 -02:00
Rafael Mendonça França
f042b4e88e Merge pull request #8280 from asanghi/fix_guide_field_with_error_proc
fix guide with field_with_error proc example
2012-11-20 14:59:50 -08:00