Commit Graph

1441 Commits

Author SHA1 Message Date
Kir Shatrov
9cc8c6f373 Move ActiveRecord::Type to ActiveModel
The first step of bringing typecasting to ActiveModel
2015-09-21 10:12:13 -06:00
Jerry D'Antonio
56ac6e4768 Replaced ThreadSafe::Map with successor Concurrent::Map.
The thread_safe gem is being deprecated and all its code has been merged
into the concurrent-ruby gem. The new class, Concurrent::Map, is exactly
the same as its predecessor except for fixes to two bugs discovered
during the merge.
2015-09-19 09:56:26 -04:00
Akira Matsuda
dcecbb4234 File encoding is defaulted to utf-8 in Ruby >= 2.1 2015-09-18 17:05:05 +09:00
Dmitry Polushkin
e3d99e239d Validate multiple contexts on valid? and invalid? at once.
Example:

```ruby
class Person
  include ActiveModel::Validations

  attr_reader :name, :title
  validates_presence_of :name, on: :create
  validates_presence_of :title, on: :update
end

person = Person.new
person.valid?([:create, :update])    # => true
person.errors.messages               # => {:name=>["can't be blank"], :title=>["can't be blank"]}
```
2015-09-07 22:42:50 +01:00
Rafael Mendonça França
7b9b0b531f Revert "Merge pull request #21069 from dmitry/feature/validate-multiple-contexts-at-once"
This reverts commit 51dd2588433457960cca592d5b5dac6e0537feac, reversing
changes made to ecb4e4b21b3222b823fa24d4a0598b1f2f63ecfb.

This broke Active Record tests
2015-09-07 17:16:54 -03:00
Rafael Mendonça França
51dd258843 Merge pull request #21069 from dmitry/feature/validate-multiple-contexts-at-once
Validate multiple contexts on `valid?` and `invalid?` at once
2015-09-07 16:46:18 -03:00
Carlos Antonio da Silva
8ce0fdb5c4 Fix failure introduced by #17351 due to the new mocks implementation
It was not expecting the new `case_insensitive` option to be passed to
`generate_message`, instead of fixing the test we can just not pass this
option down since it is specific to the confirmation validator and not
necessary for the error message.
2015-09-01 08:53:29 -03:00
Jashank Jeremy
09f64873cd Fix syntax error introduced by #17351. 2015-09-01 19:11:26 +10:00
Rafael Mendonça França
57393957e1 Merge pull request #17351 from akshat-sharma/master
Add case_sensitive option for confirmation validation
2015-09-01 02:42:43 -03:00
Akshat Sharma
2438a1cf4e Add case_sensitive option for confirmation validation
Case :- 1. In case of email confirmation one needs case insensitive comparison
        2. In case of password confirmation one needs case sensitive comparison

[ci skip] Update Guides for case_sensitive option in confirmation validation
2015-09-01 10:42:51 +05:30
Robin Dupret
7a27de2bb0 Tiny documentation improvements [ci skip] 2015-08-28 15:33:48 +02:00
Gaurav Sharma
71ed339203 discard xml Serialization documentation that is no longer available [ci skip] 2015-08-22 04:06:14 +05:30
Marcin Olichwirowicz
3c6fc5892f Rename match_attribute_method? to matched_attribute_method
`match_attribute_method?` is a bit confusing because it suggest
that a return value is a boolean which is not true.
2015-08-12 00:23:12 +02:00
Zachary Scott
f7ebdb1ac5 Remove XML Serialization from core.
This includes the following classes:

- ActiveModel::Serializers::Xml
- ActiveRecord::Serialization::XmlSerializer
2015-08-07 11:01:48 -04:00
Dmitry Polushkin
86e3b047ba Validate multiple contexts on valid? and invalid? at once.
Example:

```ruby
class Person
  include ActiveModel::Validations

  attr_reader :name, :title
  validates_presence_of :name, on: :create
  validates_presence_of :title, on: :update
end

person = Person.new
person.valid?([:create, :update])    # => true
person.errors.messages               # => {:name=>["can't be blank"], :title=>["can't be blank"]}
```
2015-07-30 10:05:29 +01:00
schneems
5bb1d4d288 Freeze string literals when not mutated.
I wrote a utility that helps find areas where you could optimize your program using a frozen string instead of a string literal, it's called [let_it_go](https://github.com/schneems/let_it_go). After going through the output and adding `.freeze` I was able to eliminate the creation of 1,114 string objects on EVERY request to [codetriage](codetriage.com). How does this impact execution?

To look at memory:

```ruby
require 'get_process_mem'

mem = GetProcessMem.new
GC.start
GC.disable
1_114.times { " " }
before = mem.mb

after = mem.mb
GC.enable
puts "Diff: #{after - before} mb"

```

Creating 1,114 string objects results in `Diff: 0.03125 mb` of RAM allocated on every request. Or 1mb every 32 requests.

To look at raw speed:

```ruby
require 'benchmark/ips'

number_of_objects_reduced = 1_114

Benchmark.ips do |x|
  x.report("freeze")    { number_of_objects_reduced.times { " ".freeze } }
  x.report("no-freeze") { number_of_objects_reduced.times { " " } }
end
```

We get the results

```
Calculating -------------------------------------
              freeze     1.428k i/100ms
           no-freeze   609.000  i/100ms
-------------------------------------------------
              freeze     14.363k (± 8.5%) i/s -     71.400k
           no-freeze      6.084k (± 8.1%) i/s -     30.450k
```

Now we can do some maths:

```ruby
ips = 6_226k # iterations / 1 second
call_time_before = 1.0 / ips # seconds per iteration 

ips = 15_254 # iterations / 1 second
call_time_after = 1.0 / ips # seconds per iteration 

diff = call_time_before - call_time_after

number_of_objects_reduced * diff * 100

# => 0.4530373333993266 miliseconds saved per request
```

So we're shaving off 1 second of execution time for every 220 requests. 

Is this going to be an insane speed boost to any Rails app: nope. Should we merge it: yep. 

p.s. If you know of a method call that doesn't modify a string input such as [String#gsub](b0e2da69f0/lib/let_it_go/core_ext/string.rb (L37)) please [give me a pull request to the appropriate file](b0e2da69f0/lib/let_it_go/core_ext/string.rb (L37)), or open an issue in LetItGo so we can track and freeze more strings. 

Keep those strings Frozen

![](https://www.dropbox.com/s/z4dj9fdsv213r4v/let-it-go.gif?dl=1)
2015-07-19 17:45:10 -05:00
Guo Xiang Tan
beb07fbfae Revert "Revert "Reduce allocations when running AR callbacks.""
This reverts commit bdc1d329d4eea823d07cf010064bd19c07099ff3.

Before:
Calculating -------------------------------------
                        22.000  i/100ms
-------------------------------------------------
                        229.700  (± 0.4%) i/s -      1.166k
Total Allocated Object: 9939

After:
Calculating -------------------------------------
                        24.000  i/100ms
-------------------------------------------------
                        246.443  (± 0.8%) i/s -      1.248k
Total Allocated Object: 7939

```
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', github: 'rails/rails', ref: 'bdc1d329d4eea823d07cf010064bd19c07099ff3'
  gem 'rails', github: 'rails/rails', ref: 'd2876141d08341ec67cf6a11a073d1acfb920de7'
  gem 'arel', github: 'rails/arel'
  gem 'sqlite3'
  gem 'benchmark-ips'
end

require 'active_record'
require 'benchmark/ips'

ActiveRecord::Base.establish_connection('sqlite3::memory:')

ActiveRecord::Migration.verbose = false

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

class User < ActiveRecord::Base
  default_scope { where(admin: true) }
end

admin = true

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

  User.create!(attributes)

  admin = !admin
end

GC.disable

Benchmark.ips(5, 3) do |x|
  x.report { User.all.to_a }
end

key =
  if RUBY_VERSION < '2.2'
    :total_allocated_object
  else
    :total_allocated_objects
  end

before = GC.stat[key]
User.all.to_a
after = GC.stat[key]
puts "Total Allocated Object: #{after - before}"
```
2015-07-16 01:02:15 +08:00
Roque Pinel
7500daec69 Conditionally convert the raw_value received by the numeric validator.
This fixes the issue where you may be comparing (using a numeric
validator such as `greater_than`) numbers of a specific Numeric type
such as `BigDecimal`.

Previous behavior took the numeric value to be validated and
unconditionally converted to Float. For example, due to floating point
precision, this can cause issues when comparing a Float to a BigDecimal.

Consider the following:

```
    validates :sub_total, numericality: {
      greater_than: BigDecimal('97.18')
    }
```

If the `:sub_total` value BigDecimal.new('97.18') was validated against
the above, the following would be valid since `:sub_total` is converted
to a Float regardless of its original type. The result therefore becomes
Kernel.Float(97.18) > BigDecimal.new('97.18')

The above illustrated behavior is corrected with this patch by
conditionally converting the value to validate to float.

Use the post-type-cast version of the attribute to validate numericality

[Roque Pinel & Trevor Wistaff]
2015-07-11 14:40:14 -04:00
Yves Senn
4cc5917dce docs, clarify the meanaing of return values from validation methods.
[ci skip]

Closes #20792.

Custom validation methods are implemented in terms of
callbacks. The `validate` callback chain can't be halted using return
values of individual callbacks.
2015-07-07 14:39:58 +02:00
Yves Senn
b8962664ad docs, remove accidental :nodoc: of ActiveModel::Validations::ClassMethods methods.
[ci skip]

While this :nodoc: did hide the constant it also removed the following
methods from the API docs:

- #attribute_method?
- #clear_validators!
- #validate
- #validators
- #validators_on

Those are public API and should be visible.

Issue was caused by dee4fbc

/cc @zzak
2015-07-07 14:16:03 +02:00
Robin Dupret
bc71e43252 Separate the constraint and other options [ci skip]
Only one constraint option can be used at a time (except for the minimum
and maximum ones that can eventually be combined). However, other
options can be used with them (e.g. the validation failure message).
So let's make the distinction between these two different options
categories.

[Yves Senn, Matthew Draper & Robin Dupret]
2015-07-01 16:20:07 +02:00
Radan Skoric
e5a78aaaf8 Improve Validation Helpers' documentation comments and tests 2015-06-27 16:34:16 +02:00
Robin Dupret
e09129c94c A few documentation fixes [ci skip] 2015-06-23 17:55:37 +02:00
Mehmet Emin İNAÇ
5b36015830 Add nodoc to the Validations::Helpers [ci skip] 2015-06-22 20:06:42 +03:00
Yves Senn
ebc4c607a7 docs, ✂️ wrongly placed heading. [ci skip]
The heading "Active Model Length Validator" was shown on the
"ActiveModel::Validations" page without any text following it.
2015-06-22 15:52:47 +02:00
Roque Pinel
bfd4e6a0bc Move the validations HelperMethods to its own file
Closes #11209

[Roque Pinel & Steven Yang]
2015-06-21 19:56:53 -04:00
Rafael Mendonça França
96bb004fc6 Revert "Add code example for include option of AM::Serialization#serializable_hash"
This reverts commit 3d949f34816d6eca0a6b59cfa08d91f36e8e64dd.

This was already documented in other PR.
2015-06-10 08:50:39 -03:00
Radan Skoric
3d949f3481 Add code example for include option of AM::Serialization#serializable_hash 2015-06-09 17:41:14 -03:00
Robin Dupret
b10c3866d7 Tiny documentation edits [ci skip] 2015-06-07 16:01:09 +02:00
Robin Dupret
911f189f88 Merge pull request #20004 from rusikf/patch-1
add docs to include option at ActiveModel::Serialization [ci skip]
2015-06-07 15:53:53 +02:00
unknown
3833d4529f formatting changes 2015-05-29 16:27:23 -04:00
rusikf
47896b3d08 add docs to include option at ActiveModel::Serialization#serializable_hash [ci skip] 2015-05-11 13:10:30 +03:00
Gourav Tiwari
6b557ae709 minor rdoc syntax fix [ci skip] 2015-05-08 14:45:32 -07:00
Zamith
6f418a09d8
Adds/Corrects use case for adding an error message
I believe this is a use case that was supposed to be supported, and it's
a small fix.
2015-05-04 13:36:26 +01:00
Jay Elaraj
b2967999ae ensure method_missing called for non-existing methods passed to
`ActiveModel::Serialization#serializable_hash`
2015-04-28 21:06:30 -04:00
Zachary Scott
dee4fbc90b Don't document private internal constant [ci skip] 2015-04-26 15:47:29 -07:00
Tim Wade
f207d948c8
Fix grammar/style: assigns/declares -> assignments/declarations.
[ci skip]
2015-04-24 09:02:38 -04:00
Tim Wade
ed6de3afcc
Fix grammar/style: use (v) fall back (on).
[ci skip]
2015-04-24 08:52:51 -04:00
Tim Wade
37349f71ad
Fix grammar/style: break up long sentence.
A conjunction was needed to make these sentences correct. Breaking them
up seemed like a better option.

[ci skip]
2015-04-24 08:40:41 -04:00
Tim Wade
875f675284
Fix grammar/style: pluralize 'each of its method'
[ci skip]
2015-04-24 08:32:58 -04:00
Fernando Tapia Rico
f072db8e4f Add ActiveModel::Dirty#[attr_name]_previously_changed? and
`ActiveModel::Dirty#[attr_name]_previous_change` to improve access
to recorded changes after the model has been saved.

It makes the dirty-attributes query methods consistent before and after
saving.
2015-04-21 19:30:46 +02:00
Rafael Mendonça França
c539cc0061 Merge pull request #19448 from tgxworld/fix_activesupport_callbacks_clash_on_run
Fix AS::Callbacks raising an error when `:run` callback is defined.
2015-04-06 18:58:19 -03:00
Yves Senn
70b7e281de fix typo in deprecation message. [Robin Dupret] 2015-04-05 17:23:36 +02:00
Guillermo Iguaran
151aa690a2 Merge pull request #19594 from radar/require-module-delegation
Require Module#delegate core ext in ActiveModel::Naming
2015-03-30 19:56:57 -05:00
Ryan Bigg
b6bf58c220 Require Module#delegate core ext in ActiveModel::Naming 2015-03-31 11:41:16 +11:00
Rafael Mendonça França
7131f6ba22 Merge pull request #19021 from morgoth/activemodel-errors-refactoring
Simplify and alias ActiveModel::Errors methods where possible
2015-03-30 13:47:30 -03:00
Sean Griffin
1c341eb7cb Deprecate the :tokenizer option to validates_length_of
As demonstrated by #19570, this option is severely limited, and
satisfies an extremely specific use case. Realistically, there's not
much reason for this option to exist. Its functionality can be trivially
replicated with a normal Ruby method. Let's deprecate this option, in
favor of the simpler solution.
2015-03-29 16:34:01 -06:00
Radan Skoric
26b35a4096 Fix ActiveModel::Errors#delete return value to stay backward compatible
Rails 5.0 changes to ActiveModel::Errors include addition of `details`
that also accidentally changed the return value of `delete`. Since
there was no test for that behavior it went unnoticed. This commit
adds a test and fixes the regression.

Small improvements to comments have also been made. Since `get` is
getting deprecated it is better to use `[]` in other methods' code
examples. Also, in the module usage example, `def Person.method`
was replaced with a more commonly used `def self.method` code style.
2015-03-22 23:18:22 +01:00
Guo Xiang Tan
bdc1d329d4 Revert "Reduce allocations when running AR callbacks."
This reverts commit 796cab45561fce268aa74e6587cdb9cae3bb243e.
2015-03-22 11:21:02 +08:00
Radan Skoric
cf7fac7e29 Fix ActiveModel::Errors deprecation messages failing when used on its own
Deprecation messages in ActiveModel::Errors are using String#squish
from ActiveSupport but were not explicitly requiring it, causing failures
when used outside rails.
2015-03-21 12:35:25 +01:00
Melanie Gilman
9034938714 Fix spelling error in has_secure_password documentation [ci skip] 2015-03-03 20:05:02 -05:00
Sean Griffin
c0584ea034 Merge pull request #19077 from robin850/unknown-attribute-error
Move `UnknownAttributeError` to a more sane namespace
2015-03-02 09:21:42 -07:00
Vipul A M
cdaab2c479 Removed non-standard and unused require 'active_support/deprecation' from parts out of active_support. 2015-02-27 23:20:09 +05:30
Robin Dupret
95c2fc9679 Follow-up to #10776
The name `ActiveModel::AttributeAssignment::UnknownAttributeError` is
too implementation specific so let's move the constant directly under
the ActiveModel namespace.

Also since this constant used to be under the ActiveRecord namespace, to
make the upgrade path easier, let's avoid raising the former constant
when we deal with this error on the Active Record side.
2015-02-26 15:40:03 +01:00
Ian Ker-Seymer
c5d62cb86d activemodel: make .model_name json encodable
Previously, calling `User.model_name.to_json` would result in an infinite
recursion as `.model_name` inherited its `.as_json` behavior from Object. This
patch fixes that unexpected behavior by delegating `.as_json` to :name.
2015-02-24 11:00:32 -07:00
Rafael Mendonça França
f55bfe7260 Change the deprecation messages to show the preferred way to work with
ActiveModel::Errors
2015-02-20 20:58:58 -02:00
Wojciech Wnętrzak
9ebb778ca0 Simplify and alias ActiveModel::Errors methods where possible 2015-02-20 21:42:00 +01:00
Lucas Mazza
830b7041f2 Move the validate! method to ActiveModel::Validations. 2015-02-20 16:05:26 -02:00
Rafael Mendonça França
e0f29c51b9 Merge pull request #17144 from skojin/patch-doc-validation-format-z-regexp
fix mistype in doc about \z regexp
2015-02-20 14:30:47 -02:00
yuuji.yaginuma
66e2e19bc0 use messages instead of deprecated ActiveModel::Errors#[]= method [ci skip] 2015-02-20 23:53:36 +09:00
Yves Senn
259d33db8c Merge pull request #18996 from morgoth/deprecate-more-errors-methods
Deprecate `ActiveModel::Errors` `add_on_empty` and `add_on_blank` methods
2015-02-19 14:16:47 +01:00
Wojciech Wnętrzak
fd38838f29 Deprecate ActiveModel::Errors add_on_empty and add_on_blank methods
without replacement.
2015-02-19 14:10:38 +01:00
Rafael Mendonça França
3c750c4c6c Merge pull request #18634 from morgoth/deprecate-some-errors-methods
Deprecate `ActiveModel::Errors` `get`, `set` and `[]=` methods.
2015-02-18 18:58:28 -02:00
Robin Dupret
1747c4e2ce Tiny documentation edits [ci skip] 2015-02-15 19:19:04 +01:00
Vijay Dev
95546d4935 Merge branch 'master' of github.com:rails/docrails 2015-02-14 15:35:47 +00:00
Rafael Mendonça França
7919c29d50 Merge pull request #16381 from kakipo/validate-length-tokenizer
Allow symbol as values for `tokenizer` of `LengthValidator`
2015-02-13 12:09:36 -02:00
Rafael Mendonça França
16809025fe Merge pull request #18388 from claudiob/better-docs-for-active-model-lint-tests
Better docs for AM::Lint::Tests
2015-02-06 11:06:59 -02:00
Xavier Noria
6f8d9bd6da revises AM:Dirty example [Godfrey Chan & Xavier Noria]
The existing example seems somewhat forced: is it realistic
to have a model that accepts state in its initializer but
considers it has not been changed? By allowing state changes
to happen only via accessors it seems more natural that new
instances are considered to be unchanged (as they are in AR).

[ci skip]
2015-02-06 10:29:05 +01:00
Xavier Noria
a2af7bb928 use parentheses here, for the beard of the Prophet! [ci skip] 2015-02-06 09:45:24 +01:00
Xavier Noria
4af4cead15 applies guidelines to dirty.rb [ci skip] 2015-02-06 09:36:28 +01:00
Carlos Antonio da Silva
f44b437627 Wrap method arguments with parentheses in docs
As per Rails general coding conventions. Related to #18794 [ci skip]
2015-02-03 07:35:11 -02:00
Vipul A M
fc87123fe8 Person class doesn't contain finder methods, hence usage of Person.find_by is wrong.
Added simple initialize and made use of Person.new instead of Person.find_by to clarify the docs.
[ci skip]
2015-02-03 12:09:42 +05:30
eileencodes
27aa4dda7d Fix validations on child record when record parent has validate: false
Fixes #17621. This 5 year old (or older) issue causes validations to fire
when a parent record has `validate: false` option and a child record is
saved. It's not the responsibility of the model to validate an
associated object unless the object was created or modified by the
parent.

Clean up tests related to validations

`assert_nothing_raised` is not benefiting us in these tests
Corrected spelling of "respects"
It's better to use `assert_not_operator` over `assert !r.valid`
2015-02-01 16:03:49 -08:00
Carlos Antonio da Silva
fdeef19833 Move required error message and changelog to Active Record
The new association error belongs to Active Record, not Active Model.
See #18700 for reference.
2015-02-01 10:31:54 -02:00
Wojciech Wnętrzak
6ec8ba16d8 Deprecate ActiveModel::Errors get, set and []= methods.
They have inconsistent behaviour currently.
2015-02-01 13:14:00 +01:00
Vipul A M
0f67f00d94 AM#Dirty doc fixes
- Grammar fixes
- Add doc for changes_include?
-  implemntations => implementations
2015-02-01 13:43:35 +05:30
Vipul A M
db41078566 Fix description for AM::Callbacks 2015-01-31 11:59:02 +05:30
Henrik Nygren
9a6c6c6f09 Provide a better error message on :required association
Fixes #18696.
2015-01-28 11:32:10 +02:00
Yves Senn
c8e39e2fd4 Merge pull request #18670 from morgoth/fix-duplicating-errors-details
Fixed duplicating ActiveModel::Errors#details
2015-01-24 15:08:11 +01:00
Wojciech Wnętrzak
fb7d95b212 Fixed duplicating ActiveModel::Errors#details 2015-01-24 11:58:55 +01:00
Eugene Gilburg
5bdb42159e use attribute assignment module logic during active model initialization 2015-01-23 14:42:47 -08:00
Sean Griffin
a225d4bec5 ✂️ and 💅 for #10776
Minor style changes across the board. Changed an alias to an explicit
method declaration, since the alias will not be documented otherwise.
2015-01-23 14:51:59 -07:00
Bogdan Gusiev
2606fb3397 Extracted ActiveRecord::AttributeAssignment to ActiveModel::AttributesAssignment
Allows to use it for any object as an includable module.
2015-01-23 23:43:22 +02:00
Rafael Mendonça França
14599a5758 Merge pull request #18322 from morgoth/add-error-codes
Add ActiveModel::Errors#codes
2015-01-21 14:28:54 -02:00
Wojciech Wnętrzak
2ee6ed69fc Add missing AS core extension dependency 2015-01-21 08:04:40 +01:00
Wojciech Wnętrzak
cb74473db6 Add ActiveModel::Errors#details
To be able to return type of validator, one can now call `details`
on Errors instance:

```ruby
class User < ActiveRecord::Base
  validates :name, presence: true
end
```

```ruby
user = User.new; user.valid?; user.errors.details
=> {name: [{error: :blank}]}
```
2015-01-20 22:33:42 +01:00
Sean Griffin
ea721d7027 Don't calculate in-place changes on attribute assignment
When an attribute is assigned, we determine if it was already marked as
changed so we can determine if we need to clear the changes, or mark it
as changed. Since this only affects the `attributes_changed_by_setter`
hash, in-place changes are irrelevant to this process. Since calculating
in-place changes can be expensive, we can just skip it here.

I also added a test for the only edge case I could think of that would
be affected by this change.
2015-01-18 13:43:31 -07:00
Sean Griffin
72570ea289 Merge pull request #18439 from mokhan/validates-acceptance-of-array
allow '1' or true for acceptance validation.
2015-01-12 12:06:00 -07:00
Anton Davydov
095b92af6c Fix error messages scope [skip ci] 2015-01-12 18:21:56 +03:00
mo khan
140557e85f allow '1' or true for acceptance validation. 2015-01-10 22:47:47 -07:00
robertomiranda
e0213f45ea Remove attributes_protected_by_default reference, since MassAssignmentSecurity was removed from ActiveModel f8c9a4d3e88181 2015-01-09 17:53:54 -05:00
claudiob
76dc58b4d0 Better docs for AM::Lint::Tests
This commit changes the original documentation of ActiveModel::Lint::Tests
introduced in dbf20c2d to focus less on *why* the tests exist and more on
*what* the tests do.

For instance, `test_to_key` was documented as:

> Returns an Enumerable of all (primary) key attributes...

whereas `test_to_key` is simply a test meant to *fail* or *pass*, and the
documentation above refers to `to_key`.

[ci skip]
2015-01-07 09:15:47 -08:00
George Millo
fc933fd4ab removing unecessary parameter in private method
'_singularize' only ever gets called with one argument
2015-01-06 00:10:56 +00:00
Rafael Mendonça França
bf7b8c193f Remove unneeded requires
These requires were added only to change deprecation message
2015-01-04 12:11:03 -03:00
Rafael Mendonça França
37175a24bd Remove deprecated ActiveModel::Dirty#reset_#{attribute} and ActiveModel::Dirty#reset_changes. 2015-01-04 11:58:42 -03:00
Rafael Mendonça França
4591b0fc04 Merge pull request #17227 from claudiob/explicitly-abort-callbacks
Introduce explicit way of halting callback chains by throwing :abort. Deprecate current implicit behavior of halting callback chains by returning `false` in apps ported to Rails 5.0. Completely remove that behavior in brand new Rails 5.0 apps.

Conflicts:
	railties/CHANGELOG.md
2015-01-03 17:22:20 -03:00
Vijay Dev
4b9dba99d6 Merge branch 'master' of github.com:rails/docrails 2015-01-03 14:58:17 +00:00
claudiob
91b8129320 Deprecate false as the way to halt AM callbacks
Before this commit, returning `false` in an ActiveModel `before_` callback
such as `before_create` would halt the callback chain.

After this commit, the behavior is deprecated: will still work until
the next release of Rails but will also display a deprecation warning.

The preferred way to halt a callback chain is to explicitly `throw(:abort)`.
2015-01-02 15:31:56 -08:00
claudiob
f767981286 Deprecate false as the way to halt AM validation callbacks
Before this commit, returning `false` in an ActiveModel validation
callback such as `before_validation` would halt the callback chain.

After this commit, the behavior is deprecated: will still work until
the next release of Rails but will also display a deprecation warning.

The preferred way to halt a callback chain is to explicitly `throw(:abort)`.
2015-01-02 15:31:56 -08:00
claudiob
2386daabe7 Throw :abort halts default CallbackChains
This commit changes arguments and default value of CallbackChain's :terminator
option.

After this commit, Chains of callbacks defined **without** an explicit
`:terminator` option will be halted as soon as a `before_` callback throws
`:abort`.

Chains of callbacks defined **with** a `:terminator` option will maintain their
existing behavior of halting as soon as a `before_` callback matches the
terminator's expectation. For instance, ActiveModel's callbacks will still
halt the chain when a `before_` callback returns `false`.
2015-01-02 15:31:55 -08:00
claudiob
7cc145ec65 Use Active Model, not ActiveModel in plain English
Also prevents the word "Model" from linking to the documentation
of ActiveModel::Model because that's not intended.

[ci skip]
2015-01-02 14:19:21 -08:00
Arun Agrawal
4de18d0ead Update copyright notices to 2015 [ci skip] 2014-12-31 08:34:14 +01:00
Rohit Arondekar
a928928c96 Use more semantic method to check password 2014-12-30 21:27:46 +05:30
Sean Griffin
18ae0656f5 Don't calculate all in-place changes to determine if attribute_changed?
Calling `changed_attributes` will ultimately check if every mutable
attribute has changed in place. Since this gets called whenever an
attribute is assigned, it's extremely slow. Instead, we can avoid this
calculation until we actually need it.

Fixes #18029
2014-12-22 14:55:58 -07:00
Robson Marques
ebaf4e40cd Fix inaccurate docs in active_model errors [ci skip]
The default value for the argument `message` in
`ActiveModel::Errors#add` has a new behavior
since ca99ab2481d44d67bc392d0ec1125ff1439e9f94.

Before
  person.errors.add(:name, nil)
  # => ["is invalid"]

After
  person.errors.add(:name, nil)
  # => [nil]
2014-12-22 09:06:30 -02:00
Godfrey Chan
4a19b3dea6 Pass through the prepend option to AS::Callback
I'm not sure what's the use case for this, but apparently it broke some apps.
Since it was not the intended result from #16210 I fixed it to not raise an
exception anymore. However, I didn't add documentation for it because I don't
know if this should be officially supported without knowing how it's meant to
be used.

In general, validations should be side-effect-free (other than adding to the
error message to `@errors`). Order-dependent validations seems like a bad idea.

Fixes #18002
2014-12-12 14:51:02 -08:00
_tiii
a4b02be067 add brackets around attribute_name
since 'attr_name_will_change!' is not an actual method it should
be clearer that you have to insert the attribute name as in line 104

[ci skip]
2014-12-08 17:39:29 +01:00
Sean Griffin
d1f003e67b Correctly handle multiple attribute method prefix/suffixes which match
Active Record defines `attribute_method_suffix :?`. That suffix will
match any predicate method when the lookup occurs in Active Model. This
will make it incorrectly decide that `id_changed?` should not exist,
because it attempts to determine if the attribute `id_changed` is
present, rather than `id` with the `_changed?` suffix. Instead, we will
look for any correct match.
2014-12-04 15:50:31 -07:00
Sean Griffin
704c658531 Ensure numericality validations work with mutation
The detection of in-place changes caused a weird unexpected issue with
numericality validations. That validator (out of necessity) works on the
`_before_type_cast` version of the attribute, since on an `:integer`
type column, a non-numeric string would type cast to 0.

However, strings are mutable, and we changed strings to ensure that the
post type cast version of the attribute was a different instance than
the before type cast version (so the mutation detection can work
properly).

Even though strings are the only mutable type for which a numericality
validation makes sense, special casing strings would feel like a strange
change to make here. Instead, we can make the assumption that for all
mutable types, we should work on the post-type-cast version of the
attribute, since all cases which would return 0 for non-numeric strings
are immutable.

Fixes #17852
2014-12-01 05:31:44 -07:00
Rafael Mendonça França
f25ad07f5a Start Rails 5 development 🎉
We will support only Ruby >= 2.1.

But right now we don't accept pull requests with syntax changes to drop
support to Ruby 1.9.
2014-11-28 15:00:06 -02:00
Nick Veys
f78006d656 Fixing documentation in JSON#from_json
Commit d67b289 introduced a tiny regression in the docs for #from_json,
true needs to be included when the root node is present.
2014-11-20 14:50:24 -06:00
Daniele Di Bernardo
eb05774531 [Enh] Changed the visibility of the ActiveModel::Dirty#clear_attribute_changes method
In Rails 4.2 it is impossible to define a custom default value for a model's
attribute without making it appear as _changed?, especially when the model
is first initialized. Making this method publicly visible will allow such a behaviour,
without the need to use private APIs.
2014-11-06 19:56:20 +01:00
Kuldeep Aggarwal
c551178f1b add missing space.[ci skip] 2014-11-01 22:18:05 +05:30
Godfrey Chan
4daebedcc4 Prepare for 4.2.0.beta4 release 2014-10-30 14:12:24 -07:00
Xavier Noria
e595d91ac2 edit pass over all warnings
This patch uniformizes warning messages. I used the most common style
already present in the code base:

* Capitalize the first word.

* End the message with a full stop.

* "Rails 5" instead of "Rails 5.0".

* Backticks for method names and inline code.

Also, converted a few long strings into the new heredoc convention.
2014-10-28 17:47:32 -07:00
Rafael Mendonça França
89397d09eb Prefix internal method with _
This will avoid naming clash with user defined methods
2014-10-25 17:12:19 -07:00
Garry Shutler
6c8cf21584 Add #key? to ActiveModel::Errors
Mirror Ruby's Hash#key?
2014-10-14 09:53:26 +01:00
Zachary Scott
44e6d91a07 Merge pull request #16409 from justinweiss/update_validation_context_documentation
Docs: Add a note on custom validation contexts. [ci skip]
2014-10-03 17:29:25 -07:00
Ryan Selk
9ded108e84 fix typo in in define_model_callbacks comment [ci skip] 2014-10-03 15:31:14 -06:00
Kuldeep Aggarwal
f50430ee3e add notes for define_model_callbacks [ci skip] 2014-10-03 23:04:01 +05:30
Michael Genereux
4e511001b4 Disallow appended newlines when parsing as integer
\Z allows appended newlines where \z does not.
2014-10-02 13:55:22 -07:00
Sergey Kojin
18674529f4 fix mistype in doc about \z regexp
replace \Z with regular \z
2014-10-02 18:10:44 +04:00
Pablo Herrero
291f64469f Refactor callback setup in to use lambda instead of eval 2014-09-30 09:25:04 -03:00
Pete Higgins
796cab4556 Reduce allocations when running AR callbacks.
Inspired by @tenderlove's work in
c363fff29f060e6a2effe1e4bb2c4dd4cd805d6e, this reduces the number of
strings allocated when running callbacks for ActiveRecord instances. I
measured that using this script:

```
require 'objspace'
require 'active_record'
require 'allocation_tracer'

ActiveRecord::Base.establish_connection adapter: "sqlite3",
                                        database: ":memory:"

ActiveRecord::Base.connection.instance_eval do
  create_table(:articles) { |t| t.string :name }
end

class Article < ActiveRecord::Base; end
a = Article.create name: "foo"
a = Article.find a.id

N = 10
result = ObjectSpace::AllocationTracer.trace do
  N.times { Article.find a.id }
end

result.sort.each do |k,v|
  p k => v
end
puts "total: #{result.values.map(&:first).inject(:+)}"
```

When I run this against master and this branch I get this output:

```
pete@balloon:~/projects/rails/activerecord$ git checkout master
M Gemfile
Switched to branch 'master'
pete@balloon:~/projects/rails/activerecord$ bundle exec ruby benchmark_allocation_with_callback_send.rb > allocations_before
pete@balloon:~/projects/rails/activerecord$ git checkout remove-dynamic-send-on-built-in-callbacks
M Gemfile
Switched to branch 'remove-dynamic-send-on-built-in-callbacks'
pete@balloon:~/projects/rails/activerecord$ bundle exec ruby benchmark_allocation_with_callback_send.rb > allocations_after
pete@balloon:~/projects/rails/activerecord$ diff allocations_before allocations_after
39d38
<
{["/home/pete/projects/rails/activesupport/lib/active_support/callbacks.rb",
81]=>[40, 0, 0, 0, 0, 0]}
42c41
< total: 630
---
> total: 590

```

In addition to this, there are two micro-optimizations present:

* Using `block.call if block` vs `yield if block_given?` when the block was being captured already.

```
pete@balloon:~/projects$ cat benchmark_block_call_vs_yield.rb
require 'benchmark/ips'

def block_capture_with_yield &block
  yield if block_given?
end

def block_capture_with_call &block
  block.call if block
end

def no_block_capture
  yield if block_given?
end

Benchmark.ips do |b|
  b.report("block_capture_with_yield") { block_capture_with_yield }
  b.report("block_capture_with_call") { block_capture_with_call }
  b.report("no_block_capture") { no_block_capture }
end
pete@balloon:~/projects$ ruby benchmark_block_call_vs_yield.rb
Calculating -------------------------------------
block_capture_with_yield
                        124979 i/100ms
block_capture_with_call
                        138340 i/100ms
    no_block_capture    136827 i/100ms
-------------------------------------------------
block_capture_with_yield
                      5703108.9 (±2.4%) i/s -   28495212 in   4.999368s
block_capture_with_call
                      6840730.5 (±3.6%) i/s -   34169980 in   5.002649s
    no_block_capture  5821141.4 (±2.8%) i/s -   29144151 in   5.010580s
```

* Defining and calling methods instead of using send.

```
pete@balloon:~/projects$ cat benchmark_method_call_vs_send.rb
require 'benchmark/ips'

class Foo
  def tacos
    nil
  end
end

my_foo = Foo.new

Benchmark.ips do |b|
  b.report('send') { my_foo.send('tacos') }
  b.report('call') { my_foo.tacos }
end
pete@balloon:~/projects$ ruby benchmark_method_call_vs_send.rb
Calculating -------------------------------------
                send     97736 i/100ms
                call    151142 i/100ms
-------------------------------------------------
                send  2683730.3 (±2.8%) i/s -   13487568 in   5.029763s
                call  8005963.9 (±2.7%) i/s -   40052630 in   5.006604s
```

The result of this is making typical ActiveRecord operations slightly faster:

https://gist.github.com/phiggins/e46e51dcc7edb45b5f98
2014-09-28 15:38:32 -07:00
Rafael Mendonça França
4581d04477 Preparing for 4.2.0.beta2 release 2014-09-26 17:19:53 -03:00
Godfrey Chan
ca67632674 Move the array to a constant 2014-09-23 01:59:43 +09:00
Prathamesh Sonpatki
a91b36f6eb Update error message for validate method
- Improve the error message by suggesting that the user may have
  intended to call validates instead of validate method.
2014-09-20 22:48:52 +09:00
Kuldeep Aggarwal
869a90512f use allow_blank option instead 2014-09-14 00:19:33 +05:30
Robin Dupret
84c0f73c8d Refer to the library name instead of the constant
When we are loading a component and we want to know its version, we are
actually not speaking about the constant but the library itself.

[ci skip]

[Godfrey Chan & Xavier Noria]
2014-08-30 11:58:23 +02:00
David Heinemeier Hansson
7475b43cdb Merge branch 'master' of github.com:rails/rails 2014-08-29 14:54:08 -07:00
Yves Senn
bf44481524 Merge pull request #16661 from edogawaconan/doc-fix
Update documentation to match change in #5942 [ci skip]
2014-08-27 11:34:47 +02:00
Yukio Mizuta
097ca3f1f8 Use ActiveSupport::Concern instead of the traditinal way 2014-08-25 11:06:06 -07:00
edogawaconan
e57ad6dc03 Update documentation to match change in #5942 [ci skip] 2014-08-24 00:04:07 +09:00
Attila Domokos
1079bb6d7d Using each_with_object instead of reduce
This way no new object allocation is taking place. Thanks @jeremy for
the suggestion!
2014-08-22 08:08:12 -05:00
Attila Domokos
36895bd90f Replacing an each with reduce
The functionality has not changed, but the code is more elegant by
using `reduce` instead of `each`.

This way no accumulator needs to be declared, no explicit return is
needed.
2014-08-21 23:13:37 -05:00
David Heinemeier Hansson
6a23bf0f4c Preparing for 4.2.0.beta1 release 2014-08-19 19:32:51 -07:00
Rafael Mendonça França
306dc1a499 Check attributes passed to create_with and where
If the request parameters are passed to create_with and where they can
be used to do mass assignment when used in combination with
Relation#create.

Fixes CVE-2014-3514

Conflicts:
	activerecord/lib/active_record/relation/query_methods.rb
2014-08-18 14:07:37 -03:00
Rafael Mendonça França
8742bc9d5e No need to check model_name anymore 2014-08-17 23:02:27 -03:00
Rafael Mendonça França
d2d809868c Merge pull request #15889 from carnesmedia/model-name
Use #model_name on instances instead of classes
2014-08-17 23:01:13 -03:00
Godfrey Chan
008f3da383 Don't expose these new APIs yet (added in 877ea78 / #16189)
WARNING: don't use them! They might change or go away between future beta/RC/
patch releases!

Also added a CHANGELOG entry for this.
2014-08-16 23:09:10 -07:00
Sean Griffin
877ea784e4 Implement _was and changes for in-place mutations of AR attributes 2014-08-16 23:08:41 -07:00
Yevhene Shemet
f8dcb365df Allow password to contain spaces only. 2014-08-06 22:11:06 +03:00
Justin Weiss
2bb0abbec0 Add a note on custom validation contexts.
The documentation on `:on` for validations was inconsistent, and most
only referenced the `:create` and `:update` contexts. I fixed those to
be consistent with the documentation on `AM::Validations.validates`,
which seemed to have the best docs.

[ci skip]
2014-08-05 13:13:40 -07:00
Carlos Antonio da Silva
28f6b895c6 Call public methods rather than class_eval'ing 2014-08-05 08:18:39 -03:00
kakipo
c3fa5c3d25 Allow symbol as values for tokenize of LengthValidator 2014-08-03 14:50:09 +09:00
Chun-wei Kuo
524f7b494a Fix example code of EachValidator [ci skip]
We have to specify the `:title` option to really use the
`TitleValidator` defined above.
2014-07-28 18:35:28 +08:00
Aaron Patterson
be9f868cb6 %i doesn't work on 1.9 2014-07-17 16:08:38 -07:00
sonnym
0950d409b0 check for valid options in validate method
This change prevents a certain class of user error which results when
mistakenly using the `validate` class method instead of the `validates`
class method.

Only apply when all arguments are symbols, because some validations use
the `validate` method and pass in additional options, namely the
`LenghValidator` via the `ActiveMode::Validations::validates_with`
method.
2014-07-17 17:32:28 -04:00
Rafael Mendonça França
1a300b6748 Make restore_attributes public
Also make it accept a list of attributes to be changed. This will make
possible to restore only a subset of the changed attributes.

Closes #16203
2014-07-17 14:55:28 -03:00
Rafael Mendonça França
41fb06fa47 Deprecate reset_#{attribute} in favor of restore_#{attribute}.
These methods may cause confusion with the `reset_changes` that
behaves differently
of them.

Also rename undo_changes to restore_changes to match this new set of
methods.
2014-07-15 18:09:38 -03:00
Rafael Mendonça França
66d0a01535 Deprecate ActiveModel::Dirty#reset_changes in favor of #clear_changes_information
This method name is causing confusion with the `reset_#{attribute}`
methods. While `reset_name` set the value of the name attribute for the
previous value the `reset_changes` only discard the changes and previous
changes.
2014-07-15 16:04:31 -03:00
Santosh Wadghule
c890f4f8b2 [ci skip] Little bit doc code improvement. 2014-07-14 10:09:14 +05:30
Godfrey Chan
9eb15ed6a0 Only automatically include validations when enabled
This is a follow up to #16024.
2014-07-02 15:07:57 -07:00
Aditya Kapoor
7b1a42c057 automatically include ActiveModel::Validations when include ActiveModel::SecurePassword 2014-07-03 02:51:12 +05:30
Sean Griffin
fa03fa7735 Silence warning emitted in tests
The instance method `model_name` was being defined multiple times,
causing a redefinition warning.
2014-07-01 07:46:56 -06:00
Rafael Mendonça França
dc67d3d2a1 Rename rollback_changes to undo_changes
To avoid overload with database rollback
2014-06-30 16:55:01 -03:00
Rafael Mendonça França
b34f7c1706 Add CHANGELOG entry for #14861 and document private methods on the API 2014-06-30 15:41:41 -03:00
Rafael Mendonça França
bada1d3ed6 Merge pull request #14861 from igor04/dirty-rollback
Added rollback method to ActiveModel::Dirty
2014-06-30 15:37:06 -03:00
Sean Griffin
36a38973a3 We are talking about the libraries, not the constants 2014-06-27 13:10:58 -06:00
Sean Griffin
e04c4c0820 Note that _will_change! is no longer needed for AR instances
Leave the note for `ActiveModel`, since it can't yet detect mutations
(hopefully we can change this in time for 4.2). However, we now detect
mutations on all supported types in `ActiveRecord`, so we can note that
`_will_change!` is no longer needed there.
2014-06-27 13:07:25 -06:00
Rafael Mendonça França
6099b643e6 Merge pull request #15834 from rmehner/allow_proc_and_symbol_for_only_integer
Allow proc and symbol as values for `only_integer` of `NumericalityValidator`
2014-06-26 07:03:31 -03:00
Amiel Martin
6b0e834a19 Use #model_name on instances instead of classes
This allows rails code to be more confdent when asking for a model name, instead of having to ask for the class.

Rails core discussion here: https://groups.google.com/forum/#!topic/rubyonrails-core/ThSaXw9y1F8
2014-06-24 17:20:24 -07:00
igor04
552d4d85f3 Added rollback method to ActiveModel::Dirty 2014-06-23 23:19:43 +03:00
Yuki Nishijima
10adc2ee90 Delegate #model_name method to self.class 2014-06-22 19:14:25 -07:00
Robin Mehner
64a05a928c only_integer of NumericalityValidator now allows procs and symbols 2014-06-22 12:22:27 +02:00
Zachary Scott
5b368010f6 ✂️ and 💅 from d60c405 [ci skip] 2014-06-16 11:35:43 -07:00
Aditya Kapoor
eb5d802cab [ci skip] correct doc for serialization in accordance with API Doc Guide 2014-06-16 22:26:55 +05:30
Godfrey Chan
0ab163d9c6 Edit pass on has_secure_password documentation [ci skip] 2014-06-14 11:05:39 -07:00
Akshay Vishnoi
fb48fccc25 [ci skip] Update #has_secure_password docs 2014-06-14 19:18:24 +05:30
Akshay Vishnoi
cabbc8f6a5 SecurePassword - Validate password must be less than or equal to 72
See #14591, Reason - BCrypt hash function can handle maximum 72 characters.
2014-06-14 12:35:31 +05:30
Arthur Nogueira Neves
6071d626e5 Merge pull request #15690 from deeeki/activemodel_model_doc
[ci skip] Clarify ActiveModel::Model docs
2014-06-13 12:21:46 -05:00
deeeki
8a1468eef6 [ci skip] Clarify ActiveModel::Model docs
ActiveModel attributes initialized with String return String values
2014-06-14 02:13:50 +09:00
Aditya Kapoor
bb075e3839 [ci skip] correct docs for conversion 2014-06-11 23:29:23 +05:30
Kuldeep Aggarwal
e5cc892ce6 remove depricated Validatior#setup 2014-06-10 12:27:17 +05:30
Akshay Vishnoi
fd3f3c5348 [ci skip] Include ActiveModel::Model in a class instead of inheriting 2014-05-30 03:09:57 +05:30
ShunsukeAida
33cc907305 Name#model_name doesn't return a String object 2014-05-30 00:09:41 +09:00
Rafael Mendonça França
5508a3e5ca Merge pull request #15154 from msgehard/move_password_field
Put attr_reader in with all of the other instance methods
2014-05-20 20:24:51 -03:00
Mike Gehard
8dd801d6ca Let others know why this code is here
[ci skip]
2014-05-18 06:47:37 -06:00
Mike Gehard
41f7d07da3 Put attr_reader in with all of the other instance methods
This makes the grouping make a little more sense
2014-05-17 13:45:35 -06:00
Abd ar-Rahman Hamidi
6604ce63e8 Add singular and plural form for some validation messages 2014-05-02 18:32:11 +02:00
hakanensari
9be22bd8d8 Autoload ActiveModel::StrictValidationFailed
Currently, if environment doesn’t eager load code, invoking this
constant before calling #valid? on a model instance results in a
NameError.
2014-04-16 22:48:51 +01:00
Steve Agalloco
e412ccbb56 add missing parentheses to validates_with documentation [skip ci] 2014-04-04 11:54:05 -04:00
David Underwood
d93bfac207 Adds explanation of :base attribute to errors.add
[ci skip]
2014-03-27 16:13:56 -04:00
Henrik Nyh
2e70f44123 ActiveRecord/ActiveModel '#validate' alias for 'valid?'
It's unintuitive to call '#valid?' when you want to run validations but
don't care about the return value.

The alias in ActiveRecord isn't strictly necessary (the ActiveModel
alias is still in effect), but it clarifies.
2014-03-27 17:56:14 +01:00
Prem Sichanugrist
2dd2fcf896
Introduce Rails.gem_version
This method return `Gem::Version.new(Rails.version)`, suggesting a more
reliable way to perform version comparison.

Example:

    Rails.version #=> "4.1.2"
    Rails.gem_version #=> #<Gem::Version "4.1.2">

    Rails.version > "4.1.10" #=> false
    Rails.gem_version > Gem::Version.new("4.1.10") #=> true
    Gem::Requirement.new("~> 4.1.2") =~ Rails.gem_version #=> true

This was originally introduced as `.version` by @charliesome in #8501
but got reverted in #10002 since it was not backward compatible.

Also, updating template for `rake update_versions`.
2014-03-05 12:37:38 -05:00
Eric Hutzelman
088c11658a Fix some validators when used on model instance
Now that Validator #setup is called from the initializer, we need a
reference to the model's class to be passed in to allow the validators
to continue functioning when used at the instance level.

Closes #14134.
2014-02-26 21:35:49 -03:00
Carlos Antonio da Silva
c20fe91b05 Pass strings to demodulize method
Goes along with fea1cdcff4d50d302d8e8532432c3ab107ff816d and
59ec4562a2e70df455b2e44a67c340fa5254e26e.
2014-02-26 21:20:56 -03:00
Aaron Patterson
fea1cdcff4 pass the class name to tableize
We should not rely on to_s to return the name of the class
2014-02-26 15:02:57 -08:00
T.J. Schuck
53f1ab523b Bump version of bcrypt gem 2014-02-25 09:52:32 -05:00
Yves Senn
c554d170e6 update version to 4.2.0.alpha 2014-02-23 13:14:43 +01:00
Rafael Mendonça França
1879c259b8 Merge branch '4-1-0-beta2'
Conflicts:
	actionview/CHANGELOG.md
	activerecord/CHANGELOG.md
2014-02-18 16:00:47 -03:00
Rafael Mendonça França
8b20c72dd8 Preparing for 4.1.0.beta2 release 2014-02-18 15:45:20 -03:00
Yves Senn
7d196cf360 #to_param returns nil if to_key returns nil. Closes #11399.
The documentation of `#to_key` (http://api.rubyonrails.org/classes/ActiveModel/Conversion.html#method-i-to_key)
states that it returns `nil` if there are no key attributes. `to_param` needs
to be aware of that fact and return `nil` as well.

Previously it raised the following exception:

```
  1) Error:
ConversionTest#test_to_param_returns_nil_if_to_key_is_nil:
NoMethodError: undefined method `join' for nil:NilClass
    /Users/senny/Projects/rails/activemodel/lib/active_model/conversion.rb:65:in `to_param'
    /Users/senny/Projects/rails/activemodel/test/cases/conversion_test.rb:34:in `block in <class:ConversionTest>'
```
2014-02-04 10:27:46 +01:00
Carlos Antonio da Silva
26fb57b58d Fix doc markup of clear_validators! 2014-01-27 08:26:54 -02:00
Vince Puzzella
8855163bdb Ability to specify multiple contexts when defining a validation.
Example:

validates_presence_of :name, on: [:update, :custom_validation_context]
2014-01-27 03:26:27 -05:00
Xavier Noria
0df1f91410 revises references to :allow_(nil|blank) in some docs [ci skip] [Steven Yang & Xavier Noria]
Closes #11247.
2014-01-26 20:50:18 +01:00
Godfrey Chan
98705d88cd Some minor fixes 2014-01-24 20:06:31 -08:00
Godfrey Chan
8ca59237dd Got all the new tests passing 2014-01-24 19:49:30 -08:00
Godfrey Chan
20490adcbf Restored the ability to clear the password with user.password= nil (see the docs) 2014-01-24 19:49:30 -08:00
Adrien Coquio
b97035df64 Fix ActiveModel::Errors#has_key? return value 2014-01-22 21:01:41 +01:00
Rafael Mendonça França
b8302bcfda Forgot to push this change in the parent commit 2014-01-20 23:00:17 -02:00
Rafael Mendonça França
06a00038ef When applying changes or reseting changes create the right class
Before this patch after the changes are applied the changes can be only
accessed using string keys, but before symbols are also accepted.

After this change every state of the model will be consistent.
2014-01-20 22:58:14 -02:00
Carlos Antonio da Silva
486db21f91 Fix eager load of Serializers on Active Model 2014-01-17 15:30:09 -02:00
Yves Senn
8c0d5e0d1c doc proc/lambda arg on inclusion validation. Closes #13689. [ci skip] 2014-01-13 11:25:58 +01:00
Carlos Antonio da Silva
3a33e8ea85 Use a better method name to check the requirement of password confirmation
Also improve changelog entries related to secure password to proper
highlight.
2014-01-07 07:59:44 -02:00
Carlos Antonio da Silva
a6da73f975 Fix typo in AMo docs [ci skip] 2014-01-06 08:45:21 -02:00
T.J. Schuck
72bb3fc297 Change all "can not"s to the correct "cannot". 2014-01-03 17:02:31 -05:00
Vipul A M
98cb3e69af update copyright notices to 2014. [ci skip] 2014-01-01 23:59:49 +05:30
Vijay Dev
c4fb191a4c Merge branch 'master' of github.com:lifo/docrails 2013-12-31 22:44:34 +05:30
Godfrey Chan
f3a8be3b8b Merge pull request #13131 from gja/changed-accepts-values
Allows you to check if a field has changed to a particular value
2013-12-30 22:05:56 -08:00
Yves Senn
864514a460 Merge pull request #13483 from aditya-kapoor/add-missing-slashes
Adding missing backslashes in active_model files so as to avoid unwanted [ci skip]
2013-12-27 01:13:02 -08:00
aditya-kapoor
fe49f432c9 Adding missing backslashes in active_model files so as to avoid unwanted links in rdoc [ci skip] 2013-12-27 13:58:31 +05:30
aditya-kapoor
1dae89ccce Added Backslashes to ActiveModel::AttributeMethods to prevent unwanted links in the rdoc + some other doc fixes.[ci skip] 2013-12-25 18:34:11 +05:30
Robin Dupret
6e2d35df3c Fix few typos and improve markup at some levels 2013-12-24 12:39:41 +01:00
Robin Dupret
b894b7b90a Fix few typos in the documentation [ci skip] 2013-12-21 18:59:55 +01:00
Vijay Dev
a3b1105ada Merge branch 'master' of github.com:lifo/docrails 2013-12-20 00:10:30 +05:30
David Heinemeier Hansson
c0a2d474c5 Get ready to release 4.1.0.beta1 2013-12-17 16:05:28 -08:00
Tejas Dinkar
da2b05bb6b Allows you to check if an attribute has changed to a particular value
model.name_changed?(from: "Pete", to: "Ringo")
2013-12-15 12:13:31 +05:30
Rafael Mendonça França
12affbe491 Fix typo [ci skip] 2013-12-13 18:33:30 -02:00
Godfrey Chan
f650981483 Added :nodoc: for attribute_changed? and attribute_was [ci skip]
These methods were made "public" in 47617ecd so that `method_missing`
can invoke them without going through `send`, but they aren't meant
for consumption from outside of Rails.
2013-12-12 12:04:07 -08:00
Akshay Vishnoi
5fccd77b6c Spelling and Grammar checks 2013-12-12 18:28:34 +05:30
Aayush khandelwal
10fffd7ae6 typos rectified lifecycle => life cycle 2013-12-12 12:55:35 +05:30
aditya-kapoor
0c55335074 Merge branch 'master' of github.com:lifo/docrails 2013-12-10 11:44:07 +05:30
Carlos Antonio da Silva
05a685eeb7 Merge pull request #13145 from acapilleri/fix_email_example
fix email regex example code [ci skip]
2013-12-03 07:47:25 -08:00
Angelo capilleri
f590cdb656 fix email regex example code [ci skip]
different from the regex in EmailValidator
2013-12-03 16:44:39 +01:00
Lauro Caetano
b1b9a0aeca Typos. return -> returns. [ci skip] 2013-12-03 13:31:36 -02:00
Genadi Samokovarov
6329d9fa8b Remove deprecated cattr_* requires 2013-12-03 00:28:15 +02:00
Akshay Vishnoi
ef0f633c66 Typo and grammatical fixes [ci skip] 2013-12-02 19:35:02 +05:30
Xavier Noria
17c29a0df0 Merge remote-tracking branch 'docrails/master'
Conflicts:
	activesupport/lib/active_support/core_ext/hash/deep_merge.rb
	activesupport/lib/active_support/core_ext/hash/keys.rb
2013-11-24 20:00:24 +01:00
Carlos Antonio da Silva
aa7fdfb859 Remove short circuit return in favor of simple conditional 2013-11-15 01:11:57 -02:00
Carlos Antonio da Silva
374d465f28 Invert conditional to avoid double checking for Regexp 2013-11-15 01:04:57 -02:00
Carlos Antonio da Silva
9014a79436 Only check that the option exists once instead of doing on each conditional 2013-11-15 01:01:59 -02:00
Carlos Antonio da Silva
61fef76106 Remove argument that is accessible as attribute 2013-11-15 01:00:53 -02:00
Carlos Antonio da Silva
b8c6c08452 Cache regexp source on format validation to avoid allocating new objects
Example:

    >> r = /some-regexp/
    => /some-regexp/
    >> r.source.object_id == r.source.object_id
    => false
2013-11-15 00:38:55 -02:00
Carlos Antonio da Silva
70161ae3b8 Make code simpler to read by using a case statement 2013-11-15 00:24:54 -02:00
Carlos Antonio da Silva
12815e0d44 Avoid a new hash allocation 2013-11-15 00:24:54 -02:00
Carlos Antonio da Silva
4c7e3a3087 Use a simple conditional rather than short circuit with next 2013-11-15 00:19:03 -02:00
Carlos Antonio da Silva
d2992818e0 Simplify number parsing logic in numericality validation 2013-11-15 00:07:22 -02:00
Carlos Antonio da Silva
f70e30ec6d Avoid creation of extra hash with merge just to set a value 2013-11-15 00:07:22 -02:00
Prem Sichanugrist
efff6c1fd4 Change syntax format for example returned values
According to our guideline, we leave 1 space between `#` and `=>`, so we
want `# =>` instead of `#=>`.

Thanks to @fxn for the suggestion.

[ci skip]
2013-11-11 13:53:54 -05:00
Carlos Antonio da Silva
deaf285824 Merge pull request #12686 from kryzhovnik/master
Minor doc fix of ActiveModel::Naming. [ci skip]

Conflicts:
	activemodel/lib/active_model/naming.rb
2013-11-02 14:46:56 -02:00
Andrey Samsonov
fb6f02c521 Minor doc fix of ActiveModel::Naming.
- qoute example line's result when it kind of String
- right ("singular_route_key") method in example
2013-10-29 15:23:03 +04:00
Guillermo Iguaran
c31b900221 Merge pull request #12635 from mperham/4-0-stable
Allow any version of BCrypt
2013-10-24 19:31:13 -02:00
Akira Matsuda
68db6bc431 Let validates_inclusion_of accept Time and DateTime ranges
fixes 4.0.0 regression introduced in 0317b93c17a46d7663a8c36edc26ad0ba3d75f85
2013-10-23 22:10:15 +09:00
T.J. Schuck
5d7b413d84 Use bcrypt's public cost attr, not internal constant
See:

- https://github.com/codahale/bcrypt-ruby/pull/63
- https://github.com/codahale/bcrypt-ruby/pull/64
- https://github.com/codahale/bcrypt-ruby/pull/65
2013-10-10 11:46:59 -04:00
Rafael Mendonça França
c48c111bb2 Merge pull request #8791 from griffinmyers/master
Updated DirtyModel's @changed_attributes hash to be symbol/string agnostic

Conflicts:
	activemodel/CHANGELOG.md
2013-10-03 11:37:10 -03:00
T.J. Schuck
4a99e10199 bcrypt-ruby v3.1.2 supports Ruby 2.0 on Windows 2013-09-23 14:28:26 -04:00
Rafael Mendonça França
ed0b080cb3 Fix the documentation method.
It is reload! in the class definition.

[ci skip]
2013-09-23 11:25:43 -03:00
Rafael Mendonça França
089e1b6426 Document reset_changes since it is part of public API
[ci skip]
2013-09-23 11:00:56 -03:00
Rafael Mendonça França
9aa1a3d853 Merge pull request #10816 from bogdan/less-dirty-dirty
Make AM::Dirty less dirty to plugin into AR or other library
2013-09-23 10:59:05 -03:00