Commit Graph

236 Commits

Author SHA1 Message Date
José Valim
dc8773b19f Rename new method to_path to to_partial_path to avoid conflicts with File#to_path and similar. 2011-08-01 11:42:00 +02:00
José Valim
1b7db58a06 Merge pull request #2034 from Casecommons/to_path
Allow ActiveModel-compatible instances to define their own partial paths
2011-07-28 00:50:07 -07:00
thedarkone
efe4cbe5f2 Handle the empty array correctly. 2011-07-27 18:07:47 +02:00
Grant Hutchins & Peter Jaros
bf812074fd Let ActiveModel instances define partial paths.
Deprecate ActiveModel::Name#partial_path. Now you
should call #to_path directly on ActiveModel
instances.
2011-07-25 16:05:24 -04:00
John Firebaugh
4860143ee4 ActiveModel support for the :include serialization option
This commit moves support for the :include serialization option for
serializing associated objects out of ActiveRecord in into ActiveModel.
The following methods support the :include option:

  * serializable_hash
  * to_json
  * to_xml

Instances must respond to methods named by the values of the :includes
array (or keys of the :includes hash). If an association method returns
an object that is_a?(Enumerable) (which AR has_many associations do), it
is assumed to be a collection association, and its elements must respond
to :serializable_hash. Otherwise it must respond to :serializable_hash
itself.

While here, fix #858, XmlSerializer should not singularize already
singular association names.
2011-07-17 11:34:07 -07:00
John Firebaugh
2a9a10f5e3 Add a test 2011-07-17 11:34:06 -07:00
John Firebaugh
da4e1faf6f serializable_hash(:only => [], :methods => [:foo]) should work 2011-07-17 11:34:06 -07:00
Joe Fiorini
ac5e691153 Enable passing root: false to #to_json 2011-07-01 23:00:13 -04:00
Ian Stewart
eafa174bfd changing an attribute multiple times retains the correct original value 2011-06-28 22:18:24 -07:00
Alexander Uvarov
528f405cdc Allow to specify mass-assignment roles as array 2011-06-23 12:56:39 +06:00
Santiago Pastorino
5599e3fa0c Merge pull request #1654 from ganeshkumar/test_cases
removed duplicate code in tests
2011-06-13 05:45:47 -07:00
ganesh
7c3094626d removed duplicate code 2011-06-11 21:49:12 +05:30
José Valim
410a42860b Get rid of the alternate namespace lookup. 2011-06-11 18:01:26 +02:00
thoefer
0831b7e076 Brought back alternative convention for namespaced models in i18n. 2011-06-08 13:40:17 +02:00
José Valim
139a9f7011 Transform the symbol into a constant lookup. 2011-05-31 12:24:30 +02:00
Bogdan Gusiev
aa2639e746 ActiveModel::MassAssignmentSecurity.mass_assignment_sanitizer method
In order to specify your own sanitize method
Implemented .mass_assignment_sanitizer configuration option
2011-05-30 11:34:00 +03:00
Bogdan Gusiev
c7567c9a6d MassAssignmentSecurity: add ability to specify your own sanitizer
Added an ability to specify your own behavior on mass assingment
protection, controlled by option:
ActiveModel::MassAssignmentSecurity.mass_assignment_sanitizer
2011-05-26 15:58:43 +03:00
Arun Agrawal
1ffc3063b7 No more need rubygems here. 2011-05-22 02:02:56 +05:30
Yves Senn
e5429b789d Specify the name to be used for ActiveModel::Name fixes #1168
This patch allows to specify the name of your models independent of the class name.
2011-05-20 16:59:09 +02:00
Jim Herzberg
fbf99653f1 Attributes with :string type should not be given the type passed in model serialization options. Closes #1058 2011-05-18 15:52:55 -04:00
Sebastian Martinez
21b61a8ac4 Follow code conventions on some tests 2011-05-10 20:58:36 -03:00
Joshua Wehner
2cef2d411a Methods that return nil should not be considered YAML 2011-05-10 12:06:09 -04:00
Josh Kalderimis
b2451f4a7f renamed mass-assignment scopes to roles, updated code, tests, docs and security guide 2011-05-08 16:43:29 +02:00
Aditya Sanghi
bf5cf5db86 :if should not fire on validations when not in context with :on 2011-04-29 02:54:37 +05:30
Myron Marston
7db7aa5053 Add additional tests for AM::ObserverArray that I had missed yesterday. 2011-04-28 08:32:22 -07:00
Myron Marston
fef22157b0 Fix bug with AM::Observer disablement.
Now that we propagate the enabling/disabling to descendants, we no longer have to check the disabled_observer Set on each superclass of the model class.  This was causing a bug when disabling all observers at a superclass level and then enabling an individual observer at a subclass level.

Plus the logic is simpler now :).
2011-04-28 08:27:15 -07:00
Myron Marston
05d4653cef Revert "Revert "Handle enabling/disabling observers at different levels of the class hierarchy.""
This reverts commit 2a25c5818b03d7d6cd63aad180bff23479dbd861.

I'm going to add another commit that keeps the same behavior of fixes
the problems of leaking memory in development.
2011-04-28 07:58:58 -07:00
José Valim
2a25c5818b Revert "Handle enabling/disabling observers at different levels of the class hierarchy."
This reverts commit ad62f1928768bd2676958a4a08512bad342fe469 because the current
subclasses implementation leaks memory in development.

Instead of keeping an array of subclasses, the better solution is to
ask the parent if an observer is being disabled or not.
2011-04-28 09:32:57 +02:00
Myron Marston
ad62f19287 Handle enabling/disabling observers at different levels of the class hierarchy.
Last call wins.
2011-04-28 10:25:07 +08:00
Myron Marston
1f8cc446d9 Allow observers to be enabled and disabled.
This is useful in situations like model unit tests and the occasional rake task to backfill old data.
2011-04-28 10:23:49 +08:00
Josh Kalderimis
1054ebd613 AM mass assignment security attr_accessible and attr_protected now allow for scopes using :as => scope eg.
attr_accessible :name
    attr_accessible :name, :admin, :as => :admin
2011-04-24 09:53:18 +02:00
Aaron Patterson
3e23752236 bcrypt will encrypt anything, so validate_presence_of would not catch nil / blank passwords. Thank you to Aleksander Kamil Modzelewski for reporting this 2011-04-14 14:54:25 -07:00
José Valim
df5691aa94 No need to rescue here. Invoking the wrong method in an object can happen anywhere if you are not careful. In other words, test your shit. 2011-04-11 17:47:59 +02:00
José Valim
5bf3d46bec Revert "Add :use_include option to allow user to explicitly use Range#include? method in Ruby 1.9"
Use :with => range.to_a instead.

This reverts commit f6540211b5b9133c9f93c11655a04d613c237e67.
2011-04-11 17:41:33 +02:00
Prem Sichanugrist
a9f3c9da01 Using Object#in? and Object#either? in various places
There're a lot of places in Rails source code which make a lot of sense to switching to Object#in? or Object#either? instead of using [].include?.
2011-04-11 03:17:09 +08:00
Prem Sichanugrist
f6540211b5 Add :use_include option to allow user to explicitly use Range#include? method in Ruby 1.9
In Ruby 1.9 we're currently use `Range#cover?` to fix the performance problem. However, there might be the case that you want to use `Range#include?` instead. This patch will give you that option.
2011-04-10 18:49:28 +08:00
Prem Sichanugrist
58594be680 Add support for proc or lambda as an option for InclusionValidator, ExclusionValidator, and FormatValidator
You can now use a proc or lambda in :in option for InclusionValidator and ExclusionValidator, and :with, :without option for FormatValidator
2011-04-10 18:49:28 +08:00
John Firebaugh
d907f3cb5c Rename test directory to match code directory
Hopefully "serializeration" is not an in joke that I missed.
2011-04-06 01:50:35 +08:00
Santiago Pastorino
da6c7bd4b4 Do not in place modify what table_name returns 2011-03-22 19:36:16 -03:00
Santiago Pastorino
445241d713 define_attr_method should be able to define methods that returns nil 2011-03-17 23:17:20 -03:00
Aaron Patterson
00f0879367 dup strings on return so that in place modifications do not break anything. I am looking at you "compute_table_name" 2011-03-17 10:26:11 -07:00
Santiago Pastorino
c834a751d2 define_attr_method correctly defines methods with invalid identifiers 2011-03-16 21:20:44 -03:00
Santiago Pastorino
fda45f4fc4 Add a define_attr_method test 2011-03-16 21:08:02 -03:00
Santiago Pastorino
5232077517 Add test for define_attr_method using as name an invalid identifier 2011-03-16 21:01:49 -03:00
Santiago Pastorino
cb44e99de4 Add test for define_attribute_method using as name an invalid identifier 2011-03-16 21:01:04 -03:00
Santiago Pastorino
157c37f558 Refactor length validation 2011-03-12 21:12:44 -02:00
Andriy Tyurnikov
f48d3d4df6 length validation for fixnums
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-03-12 21:12:44 -02:00
R.T. Lechow
86c15d8b89 Active Model typos. 2011-03-05 11:56:34 +01:00
Alexander Uvarov
24faddd60c Move ActiveModel::AttributeMethods#attribute_methods_generated? to ActiveRecord, so it's flexible now
[#6428 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2011-03-01 20:22:45 +01:00
Santiago Pastorino
a00bed0c48 Revert "Properly interpolate i18n keys in modules [#5572 state:resolved]"
This breaks #6448, you should use :"module/class" as key for namespacing
[#6448 state:committed]

This reverts commit 8d30193b08bd2321a7a78a1f481bd5e4d4d45557.
2011-02-27 21:30:03 -02:00