Commit Graph

1349 Commits

Author SHA1 Message Date
Carlos Antonio da Silva
05b80a1cce Improve AMo changelog example to not rely on AR [ci skip] 2012-12-19 23:03:32 -02:00
Roberto Vasquez Angel
d72a07f1d1 Add ActiveModel::Validations::AbsenceValidator, a validator to check the absence of attributes.
Add `ActiveModel::Errors#add_on_present` method. Adds error messages to present attributes.
2012-12-15 16:27:44 -05:00
Carlos Antonio da Silva
df9f9b7f3e Convert changelogs to 1.9 hash style and fix some formatting [ci skip] 2012-12-14 20:25:22 -02:00
Aaron Patterson
49219293e5 Merge pull request #8510 from thedarkone/thread_safety_improvements
Thread safety improvements
2012-12-14 11:12:50 -08:00
thedarkone
45448a5788 Replace some global Hash usages with the new thread safe cache.
Summary of the changes:
 * Add thread_safe gem.
 * Use thread safe cache for digestor caching.
 * Replace manual synchronization with ThreadSafe::Cache in Relation::Delegation.
 * Replace @attribute_method_matchers_cache Hash with ThreadSafe::Cache.
 * Use TS::Cache to avoid the synchronisation overhead on listener retrieval.
 * Replace synchronisation with TS::Cache usage.
 * Use a preallocated array for performance/memory reasons.
 * Update the controllers cache to the new AS::Dependencies::ClassCache API.
   The original @controllers cache no longer makes much sense after @tenderlove's
   changes in 7b6bfe84f3 and f345e2380c.
 * Use TS::Cache in the connection pool to avoid locking overhead.
 * Use TS::Cache in ConnectionHandler.
2012-12-14 12:18:47 +01:00
Andrew White
4dd5635922 Only call in_time_zone on Time or DateTime instances
Both String and Date now respond to in_time_zone so we need to
check if the value is a Time or a DateTime.
2012-12-11 12:35:30 +00:00
Jeremy Kemper
8110035623 Revert "Omit directories from gemspec.files for RubyGems 2 compat."
Obviated by rubygems/rubygems@486ed83cc8

This reverts commit bb8923dee093b615615cdfb83b34d1b0bb254f25.
2012-12-09 17:14:27 -07:00
Jeremy Kemper
bb8923dee0 Omit directories from gemspec.files for RubyGems 2 compat.
RG2 packager expects each spec.files path to be a file and bombs when it tries to tarball a dir.

May revert if rubygems/rubygems#413 is accepted.
2012-12-08 17:18:46 -07:00
claudiob
019df98875 Replace comments' non-breaking spaces with spaces
Sometimes, on Mac OS X, programmers accidentally press Option+Space
rather than just Space and don’t see the difference. The problem is
that Option+Space writes a non-breaking space (0XA0) rather than a
normal space (0x20).

This commit removes all the non-breaking spaces inadvertently
introduced in the comments of the code.
2012-12-04 22:11:54 -08:00
Renato Mascarenhas
cc62ec1e8c Actually test that ActiveModel::Errors#add defaults to :invalid. 2012-12-01 22:30:34 -02:00
Renato Mascarenhas
703b6387ee Call full_messages instead of to_a in its spec. 2012-12-01 22:30:33 -02:00
Renato Mascarenhas
cf7ab6056a Reset attributes should not report changes.
When resetting an attribute, you expect it to return to the state it was
before any changes. Namely, this fixes this unexpected behavior:

~~~ruby
model.name = "Bob"
model.reset_name!
model.name_changed? #=> true
~~~
2012-12-01 16:58:09 -02:00
Carlos Antonio da Silva
c2be9b0c3e Simplify keys order test for as_json in Active Model 2012-11-30 10:21:24 -02:00
Rafael Mendonça França
ec17f0d352 Add CHANGELOG entries for the observes extraction
[ci skip]
2012-11-29 01:08:36 -02:00
Rafael Mendonça França
ccecab3ba9 Remove observers and sweepers
They was extracted from a plugin.

See https://github.com/rails/rails-observers

[Rafael Mendonça França + Steve Klabnik]
2012-11-28 22:46:49 -02:00
Steve Klabnik
9504b44cf6 Specify type of singular association during serialization
When serialising a class, specify the type of any singular associations, if
necessary. Rails already correctly specifies the :type of any enumerable
association (e.g. a has_many association), but made no attempt to do so for
non-enumerables (e.g. a has_one association).
We must specify the :type of any STI association. A has_one
association to a class which uses single-table inheritance is an example of
this type of association.

Fixes #7471
2012-11-28 11:48:32 -08:00
Rafael Mendonça França
5658923daa Merge pull request #7282 from xHire/validates_length_of_fix
Length validation handles correctly nil. Fix #7180

Conflicts:
	activemodel/CHANGELOG.md
2012-11-26 18:44:07 -02:00
Carlos Antonio da Silva
26a3b70cc4 Merge pull request #8320 from senny/active_model_log_folder
Log output from activemodel's railtie_test directly to STDOUT.

There's no logging going on here, but since we initialize the app, the
logger is set and the folder is automatically created. With this change,
the default logger is not created, so there is no logging folder anymore.

Conflicts:
	activemodel/test/cases/railtie_test.rb
2012-11-26 15:32:25 -02:00
Yves Senn
6fc83201db log output from activemodel's railtie_test directly to STDOUT
after this patch, running the tests in activemodel will no longer
create an untracked log/ folder inside of activemodel
2012-11-26 17:23:20 +01:00
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
Michal Zima
ea76e9a312 Length validation handles correctly nil. Fix #7180
When nil or empty string are not allowed, they are not valid.
2012-11-26 12:34:32 +01: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
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
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
Carlos Antonio da Silva
ea0056f52a Merge pull request #8256 from nalwayaabhishek/master
Displaying error message if validation fail in examples (p tag was missing)
2012-11-19 02:49:00 -08:00
Abhishek Nalwaya
c33e893775 displaying error message(p tag was missing) and adding output as comment 2012-11-19 07:03:40 +05:30
Saulius Grigaliunas
61edea05c3 Point user to strong_parameters as the new protection model [ci skip] 2012-11-18 15:40:41 +02:00
Carlos Antonio da Silva
0b63da9d5a Initialize #min_cost to avoid warning in Ruby 2.0 2012-11-17 18:40:01 -02:00
Vijay Dev
7b70eeed43 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	actionpack/lib/action_dispatch/routing/redirection.rb
2012-11-17 01:50:49 +05:30
Trevor Turk
06faa6da80 Use BCrypt's MIN_COST in the test environment for speedier tests 2012-11-14 09:42:54 -06:00
Daniel Lopes
d7536e6108 add details on password confirmation used with has_secure_password 2012-11-13 17:31:46 -06:00
Dennis Taylor
ba291a67df Trivial documentation fix for ActiveModel::Naming comment. 2012-11-09 11:23:51 -08:00
Aaron Patterson
72f5085404 rm dead code 2012-11-09 10:31:23 +09:00
Vinny Diehl
a96a176930 Clean up gemspecs
Organized the gemspec files a bit.

 * Made quotes more consistent (single quotes dominated, so I used
   that).
 * Moved license line down a line, separating it logically, and removed
   the extra whitespace before its = operator.
 * Minor whitespace fixes.
2012-11-08 19:09:43 -05:00
Vasiliy Ermolovich
70ecf6c518 use Array() instead flatten
* move ActiveModel::Errors tests to errors_test.rb
* add spec coverage for add_on_empty and add_on_blank
2012-11-05 18:29:31 +03:00
Carlos Antonio da Silva
b1fe78e0cb Raise ArgumentError when no attribute is given to AMo::EachValidator
ArgumentError is better suited than RuntimeError for this.
2012-11-04 11:41:05 -02:00
Carlos Antonio da Silva
d9f20c575a Set hash value instead of using merge! 2012-11-04 11:35:01 -02:00
Vijay Dev
3b0bb08699 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	actionpack/lib/action_controller/metal/mime_responds.rb
	activerecord/lib/active_record/attribute_methods.rb
	guides/source/working_with_javascript_in_rails.md
2012-11-03 01:56:16 +05:30
Alexey Gaziev
b955939d55 Make caller attribute in deprecation methods optional 2012-10-30 10:23:41 +08:00
Cédric FABIANSKI
3152ee878a Add test for code change introduced in this commit f20032f 2012-10-29 21:55:09 +01:00
Nikita Afanasenko
0b7067d849 Provide a call stack for deprecation warnings where needed.
It's sometimes hard to quickly find where deprecated call was performed, especially in case of migrating between Rails versions. So this is an attempt to improve the call stack part of the warning message by providing caller explicitly.
2012-10-29 19:22:59 +04:00
Francesco Rodriguez
df2b60cd41 fix failing isolated tests 2012-10-26 23:03:36 -05:00
Francesco Rodriguez
10d9cb2052 fix AM::Serializers titles [ci skip] 2012-10-26 21:46:15 -05:00
Francesco Rodriguez
070329596f AM::Serializers::Xml depends on AM::Naming 2012-10-26 21:45:40 -05:00
Francesco Rodriguez
9ac095fef5 minor edits and remove mixed titles in AM::Validations docs [ci skip] 2012-10-25 20:41:35 -05:00
Francesco Rodriguez
2ef4d5ed5c fix output messages - docs [ci skip] 2012-10-22 14:27:55 -05:00
AvnerCohen
77eb1fb22d convert comments to 1.9 hash syntax 2012-10-22 19:34:24 +02:00
Vijay Dev
f938019da2 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	activesupport/lib/active_support/core_ext/hash/slice.rb
	guides/source/active_support_core_extensions.md
2012-10-21 18:49:19 +05:30
Francesco Rodriguez
c9a88a2c26 minor edits in AM documentation [ci skip] 2012-10-21 01:26:01 -05:00
Hrvoje Šimić
aee07fe135 include serializers in ActiveModel::Serialization example 2012-10-19 17:24:34 +02:00
Hrvoje Šimić
2d2c82354f better examples in ActiveModel readme 2012-10-19 16:58:30 +02:00
Jan Berdajs
a774354dfe add credit to committer of pull request #6569 2012-10-18 16:29:17 +02:00
Francesco Rodriguez
f12244b6d7 remove non-breaking spaces [ci skip] 2012-10-18 01:23:26 -05:00
Yves Senn
a06012c81f active_model/validations requires necessary files to run 2012-10-18 07:44:41 +02:00
Yves Senn
f00b33e173 cleanup, replace non-breaking spaces with spaces 2012-10-18 07:44:41 +02:00
dfens
ab9140ff02 Cleanup trailing whitespaces 2012-10-12 09:56:39 +02:00
Vijay Dev
f638ef951b Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	activerecord/lib/active_record/persistence.rb
	railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb
2012-10-11 01:05:14 +05:30
Vijay Dev
43f32f2f5d Revert "Fix Example in active model attribute methods"
This reverts commit 1c02b988641c201308e6b3de6457128878e47bd5.
2012-10-11 00:43:52 +05:30
Vijay Dev
d5802adf83 Revert "Fix all examples in comments in active_model attribute methods"
This reverts commit 93b1ca8bd34993f8958219f13c195f5acf8e55f6.
2012-10-11 00:43:17 +05:30
Robin Dupret
f839e619d4 Use a 1.9 Hash syntax in README files (fixes thanks to @vijaydev) 2012-10-10 15:14:03 +02:00
Rafael Mendonça França
d56b5dacb1 Use the flat_map method.
Thanks to @jeremy to teach me this one.
2012-10-03 00:17:10 -03:00
Rafael Mendonça França
86062005a7 Revert "Merge pull request #7826 from sikachu/master-validators-kind"
This reverts commit 4e9f53f9736544f070e75e516c71137b7eb49a7a, reversing
changes made to 6b802cdb4f5b84e1bf49aaeb0e994b3be6028af9.

Revert "Don't use tap in this case."

This reverts commit 454d820bf0a18fe1db4c55b0145197d70fef1f82.

Reason: Is not a good idea to add options to this method since we can do
the same thing using method composition.

    Person.validators_on(:name).select { |v| v.kind == :presence }

Also it avoids to change the method again to add more options.
2012-10-02 23:57:00 -03:00
Rafael Mendonça França
454d820bf0 Don't use tap in this case.
The use of tap in this case is very confusing since we are mutating the
return value inside the block
2012-10-02 23:24:42 -03:00
Prem Sichanugrist
4f9b59dba0 Make .validators_on accept :kind option
This will filter out the validators on a particular attribute based on
its kind.
2012-10-02 22:09:06 -04:00
Nick Rowe
93b1ca8bd3 Fix all examples in comments in active_model attribute methods 2012-10-02 15:35:12 -07:00
Nick Rowe
1c02b98864 Fix Example in active model attribute methods 2012-10-02 15:18:08 -07:00
John Foley
60c65ca8df Switch to using include? on validation callbacks 2012-09-23 12:53:50 -06:00
John Foley
d66d6076b2 Fix collisions with before and after validation callbacks.
This commit allows a user to do something like:
    before_validation :do_stuff, :on => [ :create, :update ]
    after_validation :do_more, :on => [ :create, :update ]
2012-09-23 12:53:50 -06:00
Francesco Rodriguez
356eed9c60 add :nodoc: to AMo::DeprecatedMassAssignmentSecurity::ClassMethods [ci skip] 2012-09-20 12:18:59 -05:00
Francesco Rodriguez
6783c3f449 change AMo::ForbiddenAttributesProtection#sanitize_for_mass_assignment to protected 2012-09-20 12:18:59 -05:00
Francesco Rodriguez
1e56f1f14c update AMo::ForbiddenAttributesError documentation [ci skip] 2012-09-20 12:18:59 -05:00
Francesco Rodriguez
3759e32882 add :nodoc: directives to AMo::DeprecatedMassAssignmentSecurity [ci skip] 2012-09-20 12:18:58 -05:00
Guillermo Iguaran
1f4c89fbde Update changelogs to add entries about strong_parameters integration 2012-09-19 17:50:39 -05:00
Guillermo Iguaran
9bfa13bb06 attr_accessible and attr_protected raise an exception pointing to use plugin or new protection model 2012-09-16 23:58:21 -05:00
Guillermo Iguaran
8cfe95d719 Don't use assert_nothing_raised when assert_equal is used 2012-09-16 23:58:21 -05:00
Guillermo Iguaran
1fa4f9243d Rename ForbiddenAttributes exception to ForbiddenAttributesError 2012-09-16 23:58:21 -05:00
Guillermo Iguaran
52aa5343f4 Change AMo::ForbiddenAttributesProtection tests to use a subclass of Hash instead of monkey patch permitted? method in regular hashes 2012-09-16 23:58:19 -05:00
Guillermo Iguaran
f8c9a4d3e8 Remove MassAssignmentSecurity from ActiveModel
This will be moved out to protected_attributes gem
2012-09-16 23:58:19 -05:00
Guillermo Iguaran
a8f6d5c645 Integrate ActiveModel::ForbiddenAttributesProtection from StrongParameters gem 2012-09-16 23:58:19 -05:00
Nihad Abbasov
ab14392cbb remove '.rb' from require call 2012-09-12 12:48:17 +06:00
Vijay Dev
cb524dc1d7 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
2012-09-09 17:38:47 +05:30
Carlos Antonio da Silva
29fe06577f Bump builder dependencies in Active Model and Action Pack 2012-09-07 13:13:39 -03:00
Carlos Antonio da Silva
0180e090ab Update Active Model xml serialization test to reflect a change in builder
Due to a change in builder, nil values and empty strings now generates
closed tags, so instead of this:

    <pseudonyms nil=\"true\"></pseudonyms>

It generates this:

    <pseudonyms nil=\"true\"/>

Document this change in Rails so that people can track it down easily if
necessary.
2012-09-07 13:08:30 -03:00
Anatoly Makarevich
fce0d088a5 Added forgotten :message option to ActiveModel validates documentation 2012-09-07 14:56:23 +04:00
Xavier Noria
810a50dacf CHANGELOGs are now per branch
Changes in old branches needed to be manually synched in CHANGELOGs of newer ones.
This has proven to be brittle, sometimes one just forgets this manual step.
With this commit we switch to CHANGELOGs per branch. When a new major version is
cut from master, the CHANGELOGs in master start being blank.

A link to the CHANGELOG of the previous branch allows anyone interested to
follow the history.
2012-08-28 21:15:16 +02:00
kennyj
9063f3729b Fix method redefined warnings. 2012-08-29 02:38:12 +09:00
Gabriel Sobrinho
2f3eb484f2 Accept a symbol for :in option on inclusion and exclusion validators 2012-08-24 15:26:17 -03:00
Francesco Rodriguez
961957d570 Fix ActiveModel tests that depend on run order 2012-08-23 16:00:58 -05:00
José Valim
2801786e1a Get rid of config.preload_frameworks in favor of config.eager_load_namespaces
The new option allows any Ruby namespace to be registered and set
up for eager load. We are effectively exposing the structure existing
in Rails since v3.0 for all developers in order to make their applications
thread-safe and CoW friendly.
2012-08-21 14:47:19 -03:00
Rafael Mendonça França
cfd7f4e9a0 Merge pull request #7024 from bogdan/strict_validation_custom_exception
AM::Validation#validates: custom exception for :strict option

Conflicts:
	activemodel/CHANGELOG.md
2012-08-16 16:59:04 -03:00
Vijay Dev
176f0888d8 Merge branch 'master' of github.com:lifo/docrails 2012-08-16 00:07:17 +05:30
Anthony
78f5874c82 Following the false issue reporting I did here : https://github.com/rails/rails/issues/6958
- Enable propagation of :skip_types, :dasherize and :camelize on included models by default
- Adding the option to override this propagation on a per-include basis (:include => { :model => { :dasherize => false } }
- Enough tests to prove it works
- Updated activemodel CHANGELOG.md

Squashed my commits
2012-08-13 19:14:24 -07:00
Carlos Antonio da Silva
ce06b8a56c Refactor model name logic and make it a real private class method
Under a "private" call, class methods are not real private methods,
they're public just like any other method.

Make model_name_from_record_or_class a private class method, and nodoc it.
2012-08-11 13:33:28 -03:00
Rafael Mendonça França
8781b266b9 Sync CHANGELOGs [ci skip] 2012-08-11 13:13:58 -03:00
Bert Goethals
920d9ee4d8 Naming helpers should first check if passed object responds to model_name 2012-08-08 22:40:06 +02:00
andrea longhi
d7f0e434dd add around_create callback documentation for ActiveModel::Callbacks 2012-08-08 00:16:28 +02:00
Bogdan Gusiev
2e4f7986b8 AM::Validation#validates: ability to pass custom exception to :strict option 2012-08-06 13:45:27 +03:00
Xavier Noria
447b6a4e67 removes usage of Object#in? from the code base (the method remains defined by Active Support)
Selecting which key extensions to include in active_support/rails
made apparent the systematic usage of Object#in? in the code base.
After some discussion in

    5ea6b0df9a

we decided to remove it and use plain Ruby, which seems enough
for this particular idiom.

In this commit the refactor has been made case by case. Sometimes
include? is the natural alternative, others a simple || is the
way you actually spell the condition in your head, others a case
statement seems more appropriate. I have chosen the one I liked
the most in each case.
2012-08-06 00:30:02 +02:00
Vijay Dev
3d3fa165e4 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	activemodel/lib/active_model/secure_password.rb
	activerecord/lib/active_record/associations/collection_proxy.rb
2012-08-04 15:18:35 +05:30
Vijay Dev
b51201242a copy edits [ci skip] 2012-08-04 15:09:33 +05:30
Rafael Mendonça França
9895f6ca2b Merge pull request #7253 from acapilleri/lenght_validator_errors_options
calculate errors_options one time in validate_each
2012-08-03 09:57:37 -07:00
Angelo Capilleri
93b6fafe3c calculate errors_options one time in validate_each
errors_options is calculated for every *CHECKS* but it could be
calculated one time  because options and RESERVED_OPTIONS
not change during this cycle
2012-08-03 17:42:38 +02:00
Jon Leighton
55b24888bb Remove ActiveRecord::Base.to_a
On reflection, it seems like a bit of a weird method to have on
ActiveRecord::Base, and it shouldn't be needed most of the time anyway.
2012-08-03 11:51:52 +01:00
Robert Pankowecki
ad9b6a3f94 Fix ActiveModel::Serializers::Xml#to_xml reference
Link to ActiveRecord::Serialization#to_xml for more details
2012-08-02 23:47:02 +02:00
Xavier Noria
077372b20d load active_support/deprecation in active_support/rails 2012-08-02 21:59:23 +02:00
Xavier Noria
4aee8dd486 load active_support/core_ext/module/delegation in active_support/rails 2012-08-02 21:59:23 +02:00
Xavier Noria
5e1b92044c load active_support/core_ext/class/attribute in active_support/rails 2012-08-02 21:59:23 +02:00
Xavier Noria
64bc8447c2 load active_support/concern in active_support/rails 2012-08-02 21:59:23 +02:00
Xavier Noria
5ea6b0df9a load active_support/core_ext/object/inclusion in active_support/rails 2012-08-02 21:59:22 +02:00
Xavier Noria
8f58d6e507 load active_support/core_ext/object/blank in active_support/rails 2012-08-02 21:59:22 +02:00
Xavier Noria
1a7b2e8fad defines a private require-hub active_support/rails
This is a private place to put those AS features that are used
by every component. Nowadays we cherry-pick individual files
wherever they are used, but that it is not worth the effort
for stuff that is going to be loaded for sure sooner or later,
like blank?, autoload, concern, etc.
2012-08-02 21:59:22 +02:00
Robby Grossman
ad7f9cdf00 has_secure_password should not raise a 'digest missing' error if the calling class has specified for validations to be skipped. 2012-07-31 16:16:21 -04:00
Francesco Rodriguez
7b7501b2e5 update ActiveModel::Observer documentation [ci skip] 2012-07-31 11:46:13 -05:00
Francesco Rodriguez
ab53cc7b2e update ActiveModel::ObserverArray documentation [ci skip] 2012-07-30 23:32:48 -05:00
Francesco Rodriguez
1d537fdc47 add :nodoc: to ActiveModel::Observing#inherited [ci skip] 2012-07-30 23:19:15 -05:00
Francesco Rodriguez
cb15fe55da update ActiveModel::Observing documentation [ci skip] 2012-07-30 23:15:27 -05:00
Francesco Rodriguez
d67b289796 update ActiveModel::Serializers documentation [ci skip] 2012-07-30 21:34:03 -05:00
Francesco Rodriguez
4ff5a5df4d add documentation to ActiveModel #from_json method [ci skip] 2012-07-30 21:34:03 -05:00
Francesco Rodriguez
1ca957c5bb fix #after_validation example [ci skip] 2012-07-30 10:55:06 -05:00
Francesco Rodriguez
4d1794713e add :nodoc: directives to ActiveModel Sanitizers [ci skip] 2012-07-29 23:09:24 -05:00
Francesco Rodriguez
c57b8d236b fix class reference in AM::MassAssignmentSecurity documentation [ci skip] 2012-07-29 22:56:04 -05:00
Francesco Rodriguez
cb6c3e28af update ActiveModel::Validations::Callbacks documentation [ci skip] 2012-07-29 22:40:37 -05:00
Francesco Rodriguez
097bfc8296 update #validates and #validates! documentation [ci skip] 2012-07-29 20:08:42 -05:00
Francesco Rodriguez
0557273f38 update ActiveModel::Valdations#validates_with docs [ci skip] 2012-07-29 19:57:48 -05:00
Francesco Rodriguez
01e61eed6a update ActiveModel::Validations docs [ci skip] 2012-07-29 19:52:25 -05:00
Francesco Rodriguez
78502673ac update ActiveModel::Validator docs [ci skip] 2012-07-29 13:35:33 -05:00
Francesco Rodriguez
f0f7786aab update ActiveModel::SecurePassword docs [ci skip] 2012-07-29 12:04:43 -05:00
Francesco Rodriguez
79b8778721 add example to ActiveModel::StrictValidationFailed [ci skip] 2012-07-28 14:24:56 -05:00
Francesco Rodriguez
b8672914b7 add example to ActiveModel::MissingAttributeError [ci skip] 2012-07-28 01:19:38 -05:00
Francesco Rodriguez
ac18d642e9 update ActiveModel::MassAssignmentSecurity docs [ci skip] 2012-07-28 00:58:21 -05:00
Francesco Rodriguez
b8e4f7155b add example to ActiveModel::Naming#model_name [ci skip] 2012-07-27 23:38:34 -05:00
Francesco Rodriguez
36ebafdce9 fix AM::Naming examples [ci skip] 2012-07-27 23:16:51 -05:00
Jon Leighton
6a81ccd69d ActiveRecord::Base.all returns a Relation.
Previously it returned an Array.

If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This
is more explicit.

In most cases this should not break existing code, since
Relations use method_missing to delegate unknown methods to #to_a
anyway.
2012-07-27 13:34:12 +01:00
Accessd
f35f6ab003 fix typo in callbacks test 2012-07-24 12:01:41 +04:00
Francesco Rodriguez
b7b97fadc1 add :nodoc: directive to AM::ObserverArray internal methods [ci skip] 2012-07-22 13:26:43 -05:00
Rafael Mendonça França
a63f7a1364 Update documentation and change the range method name to delimiter. 2012-07-20 14:23:05 -03:00
Rafael Mendonça França
770fa81bba Don't pass :within option to the i18n 2012-07-20 14:10:25 -03:00
Rafael Mendonça França
53edd32684 validates_inclusion_of and validates_exclusion_of now accept
`:within` option as alias of `:in` as documented.

Fix #7118
2012-07-20 13:53:31 -03:00
Bogdan Gusiev
c175563b88 AM::Validations: remove documentation duplicates 2012-07-10 10:07:38 +03:00
Vijay Dev
ee20be7c33 Merge branch 'master' of github.com:lifo/docrails 2012-07-07 20:44:49 +05:30
Carlos Antonio da Silva
d4f59783d2 Merge pull request #6938 from acapilleri/as_json_refactoring
Small refactoring of as_json method
2012-07-07 06:39:56 -07:00
Francesco Rodriguez
ca802fda66 add :nodoc: to internal implementations of AM::Validator [ci skip] 2012-07-06 00:17:13 -05:00
Francesco Rodriguez
9a7702a1df update ActiveModel::Serialization documentation [ci skip] 2012-07-06 00:09:08 -05:00
Francesco Rodriguez
70c4676d88 fix syntax of AM::Validations::HelperMethods examples [ci skip] 2012-07-05 11:19:20 -05:00
Francesco Rodriguez
68df230255 update ActiveModel::Validations::HelperMethods documentation [ci skip] 2012-07-05 00:09:29 -05:00
Francesco Rodriguez
6e00099a28 update ActiveModel::Conversion documentation [ci skip] 2012-07-04 23:11:47 -05:00
Angelo Capilleri
fde7fd8693 small refactoring of as_json method
with this change root has always one assignment
2012-07-03 15:11:41 +02:00
Angelo Capilleri
17fa4ef666 observer update refactoring 2012-07-03 09:08:33 +02:00
Laknath
0149a6eef9 Changed attr_accessible example to reflect grouped roles
Related to the request #5699 - https://github.com/rails/rails/pull/5699 and
not documented.
2012-07-01 10:14:13 +05:30
Vijay Dev
6b9d1a0db2 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	activemodel/lib/active_model/errors.rb
2012-06-30 23:15:22 +05:30
Carlos Antonio da Silva
4a20fcf7b2 Refactor attribute method matcher to use Hash#fetch 2012-06-26 22:21:19 -03:00
Carlos Antonio da Silva
7fad77fcc7 Cleanup attribute methods a bit, use map! when accepting *args
Since we're dealing with a new array instance, it's safe to use map! and
we avoid an extra array object.

Also remove the symbolize_keys! from AttributeMethodMatcher, since it's
an internal class that always receives symbol keys from the prefix/suffix
methods implementations.
2012-06-26 22:21:18 -03:00
Carlos Antonio da Silva
fef781cac4 Use default + merge! instead of reverse_merge
Since we're not directly requiring the reverse_merge extension, we can
avoid another hash creation by using default_hash.merge! instead.
2012-06-26 22:21:18 -03:00
Carlos Antonio da Silva
0ee6aa749c Set hash value instead of merge a single key, and use flatten! if possible
There's no need to create two extra hashes with options.merge(another_hash),
with the goal of setting only one value, so lets just set it.

Also refactor validates_each to use _merge_attributes, like other
validates_* helpers do.
2012-06-26 22:21:18 -03:00
Francesco Rodriguez
65362af7a8 add :nodoc: to internal implementations [ci skip] 2012-06-25 12:14:50 -05:00
Carlos Antonio da Silva
2a7cfee13e Make internal callback model definitions private in AMo
These _define class methods don't need to be exposed to objects that
extend ActiveModel::Callbacks.

Also use merge! options to avoid the creation of an extra hash.
2012-06-25 13:21:26 -03:00
Francesco Rodriguez
809d4f8eb2 update ActiveModel::Name documentation [ci skip] 2012-06-25 10:40:54 -05:00
Francesco Rodriguez
5130d862a5 fix punctuation in activemodel/errors [ci skip] 2012-06-25 02:23:33 -05:00
Francesco Rodriguez
87615f28e0 update ActiveModel::Naming documentation 2012-06-23 16:58:36 -05:00
Francesco Rodriguez
cca9a21a82 update ActiveModel::Model documentation [ci skip] 2012-06-23 15:12:33 -05:00
Francesco Rodriguez
ffe16b16cd add description ActiveModel::StrictValidationField [ci skip] 2012-06-23 14:49:22 -05:00
Francesco Rodriguez
62a13093c0 update ActiveModel::Lint documentation [ci skip] 2012-06-22 18:01:12 -05:00
Francesco Rodriguez
311810b8b2 update ActiveModel::Errors#include? documentation [ci skip] 2012-06-22 16:48:50 -05:00
Francesco Rodriguez
bc7ac33846 add :nodoc: to internal implementations [ci skip] 2012-06-22 16:29:59 -05:00
Francesco Rodriguez
1727f4330c add documentation and examples to ActiveModel::Errors [ci skip] 2012-06-22 16:04:16 -05:00
Francesco Rodriguez
629bc03bf8 change param name to improve documentation
The keys of the error messages are actually attribute names. It makes
the documentation easier to understand:

    # Returns +true+ if the error messages include an error for the given
    # +attribute+, +false+ otherwise.
    #
    #   person.errors.messages # => { :name => ["can not be nil"] }
    #   person.errors.include?(:name) # => true
    #   person.errors.include?(:age)  # => false
    def include?(attribute)
      (v = messages[attribute]) && v.any?
    end
2012-06-22 12:42:32 -05:00
Francesco Rodriguez
bc818e4bc5 update ActiveModel::Errors documentation and minor fixes [ci skip] 2012-06-22 11:54:15 -05:00
Francesco Rodriguez
d9238d044a update ActiveModel::Conversion documentation [ci skip] 2012-06-22 11:54:15 -05:00
Vijay Dev
35ee8fa3d8 Merge branch 'master' of github.com:lifo/docrails 2012-06-22 22:15:27 +05:30
Vijay Dev
6285675db1 fixes a few mistakes in api docs [ci skip] 2012-06-22 22:14:29 +05:30
Rafael Mendonça França
fb8cf55868 Merge pull request #6800 from mschneider/dynamic_finders_for_aliased_attributes
Dynamic finders for aliased attributes
2012-06-22 07:51:11 -07:00
Maximilian Schneider
f984b8152f made dynamic finders alias_attribute aware
previously dynamic finders only worked in combination with the actual
column name and not its alias defined with #alias_attribute
2012-06-22 16:44:01 +02:00
Carlos Antonio da Silva
965b779eb2 Add some coverage for AR serialization with serializable_hash
ActiveRecord json/xml serialization should use as base
serializable_hash, provided by ActiveModel. Add some more coverage
around options :only and :except for both json and xml serialization.
2012-06-22 08:28:03 -03:00
Francesco Rodriguez
d569bfed0d update ActiveModel::Callbacks documentation [ci skip] 2012-06-22 00:32:54 -05:00
Francesco Rodriguez
c3025e8d59 add description to ActiveModel::MissingAttributeError [ci skip] 2012-06-21 16:56:40 -05:00
Francesco Rodriguez
1ce803d091 add :nodoc: to AM::AttributeMethods#instance_method_already_implemented? [ci skip] 2012-06-21 16:40:17 -05:00
Francesco Rodriguez
95a938a5e6 add example to ActiveModel::AttributeMethods#undefine_attribute_methods [ci skip] 2012-06-21 16:19:40 -05:00
Francesco Rodriguez
f975c4b641 add docs to AM::AttributeMethods#define_attribute_method [ci skip] 2012-06-21 15:51:37 -05:00
Francesco Rodriguez
1cb2cb8bea add :nodoc: to AM::AttributeMethods::AttributeMethodMatcher [ci skip] 2012-06-21 15:37:09 -05:00
Francesco Rodriguez
b5b350ad5c fix ActiveModel::AttributeMethods#alias_attribute documentation [ci skip] 2012-06-21 12:51:39 -05:00
Francesco Rodriguez
bf3332bfdf update ActiveModel::AttributeMethods documentation [ci skip] 2012-06-21 12:26:14 -05:00
Jon Leighton
e030f26ad3 Simplify AR configuration code.
Get rid of ActiveModel::Configuration, make better use of
ActiveSupport::Concern + class_attribute, etc.
2012-06-15 19:15:36 +01:00
Francesco Rodriguez
62f6277c53 add example to ActiveModel::Validations#validators [ci skip] 2012-06-15 11:38:07 -05:00
Vijay Dev
c1474ff2e7 Merge branch 'master' of github.com:lifo/docrails 2012-06-14 22:52:38 +05:30
MrBrdo
bc7c0b5c10 prevent users from unknowingly using bad regexps that can compromise security (http://homakov.blogspot.co.uk/2012/05/saferweb-injects-in-various-ruby.html) 2012-06-14 18:10:49 +02:00
Akira Matsuda
588bb6b987 Range#cover? is not implemented in AS now 2012-06-12 02:29:21 +09:00
Robb Kidd
f20208842a Make observer enable/disable documentation more informative.
* Moved the simplest case--enable/disable all on all--to the top.
* Made clear what "ORM" means to avoid having to teach people how to solve "uninitialized constant ORM"
  errors in their test reports.
2012-06-09 16:04:01 -03:00
Piotr Sarnacki
41d63710f2 Merge pull request #6668 from pomnikita/master
Compact array of values added to PermissionSet instance
2012-06-08 11:35:13 -07:00
Nikita Pomyashchiy
00ff0a6776 Compact array of values added to PermissionSet instance 2012-06-08 01:00:34 +04:00
Francesco Rodriguez
ab11a2780f change AMS::JSON.include_root_in_json default value to false
Changes:

* Update `include_root_in_json` default value to false for default value
  to false for `ActiveModel::Serializers::JSON`.
* Remove unnecessary change to include_root_in_json option in
  wrap_parameters template.
* Update `as_json` documentation.
* Fix JSONSerialization tests.

Problem:

It's confusing that AM serializers behave differently from AR,
even when AR objects include AM serializers module.

    class User < ActiveRecord::Base; end

    class Person
      include ActiveModel::Model
      include ActiveModel::AttributeMethods
      include ActiveModel::Serializers::JSON

      attr_accessor :name, :age

      def attributes
        instance_values
      end
    end

    user.as_json
    => {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true}
    # root is not included

    person.as_json
    => {"person"=>{"name"=>"Francesco", "age"=>22}}
    # root is included

    ActiveRecord::Base.include_root_in_json
    => false

    Person.include_root_in_json
    => true

    # different default values for include_root_in_json

Proposal:

Change the default value of AM serializers to false, update
the misleading documentation and remove unnecessary change
to false of include_root_in_json option with AR objects.

    class User < ActiveRecord::Base; end

    class Person
      include ActiveModel::Model
      include ActiveModel::AttributeMethods
      include ActiveModel::Serializers::JSON

      attr_accessor :name, :age

      def attributes
        instance_values
      end
    end

    user.as_json
    => {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true}
    # root is not included

    person.as_json
    => {"name"=>"Francesco", "age"=>22}
    # root is not included

    ActiveRecord::Base.include_root_in_json
    => false

    Person.include_root_in_json
    => false

    # same behaviour, more consistent

Fixes #6578.
2012-06-06 01:11:39 -05:00
Vijay Dev
40d5303b4f Merge branch 'master' of github.com:lifo/docrails 2012-06-02 21:50:02 +05:30
Rafael Mendonça França
3449b757da Sync CHANGLOG with the 3-2-stable branch 2012-06-01 11:41:30 -03:00
Francesco Rodriguez
f87820d00a update ActiveModel::Dirty documentation 2012-05-31 05:06:00 -05:00
José Valim
555d8152c7 Merge pull request #5843 from kuroda/translation_of_deeply_nested_model_attributes
Fix human attribute_name to handle deeply nested attributes
2012-05-29 23:26:26 -07:00
Steve Purcell
b3ccd7b27a Don't enable validations when passing false hash values to ActiveModel.validates
Passing a falsey option value for a validator currently causes that validator to
be enabled, just like "true":

    ActiveModel.validates :foo, :presence => false

This is rather counterintuitive, and makes it inconvenient to wrap `validates` in
methods which may conditionally enable different validators.

As an example, one is currently forced to write:

      def has_slug(source_field, options={:unique => true})
        slugger = Proc.new { |r| r[:slug] = self.class.sluggify(r[source_field]) if r[:slug].blank? }
        before_validation slugger
        validations = { :presence => true, :slug => true }
        if options[:unique]
          validations[:uniqueness] = true
        end
        validates :slug, validations
      end

because the following reasonable-looking alternative fails to work as expected:

      def has_slug(source_field, options={:unique => true})
        slugger = Proc.new { |r| r[:slug] = self.class.sluggify(r[source_field]) if r[:slug].blank? }
        before_validation slugger
        validates :slug, :presence => true, :slug => true, :uniqueness => options[:unique]
      end

(This commit includes a test, and all activemodel and activerecord tests pass as before.)
2012-05-28 15:02:02 +01:00
Vijay Dev
575e77ba16 Merge branch 'master' of github.com:lifo/docrails 2012-05-26 17:49:59 +05:30
Edward Tsech
b98a343da5 Add comment for attr_accessible/attr_protected :as option. [ci skip] 2012-05-25 16:35:53 +02:00
José Valim
56417b4092 Merge pull request #4785 from ayamomiji/add-self-to-allow-method-name-using-ruby-keyword
add `self.` to allow method name using ruby keyword
2012-05-25 00:29:07 -07:00
Matt Griffin
6c7b250ac0 Add license field to gemspecs, by Matt Griffin 2012-05-23 09:22:25 -07:00