Commit Graph

606 Commits

Author SHA1 Message Date
Lawrence Pit
9bd91b00b8 Favor %{} in all code instead of (deprecated) {{}} as interpolation syntax for I18n
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-05-03 13:37:32 +02:00
Neeraj Singh
883f27aa9a test cases for record.to_xml [#458 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-04-30 13:19:30 +02:00
Neeraj Singh
580dd3b052 array.to_xml should be able to handle all types of data elements [#4490 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-04-29 09:04:34 +02:00
reu
77c099c231 Fix validates_numericaly_of only integer error message [#4406 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-04-25 10:14:15 +02:00
Jeremy Kemper
1924cff934 Fix Active Model observer tests 2010-04-16 13:14:52 -07:00
Ryan Bigg
d748cc3cd0 Re-define empty? for errors to check if the values inside the OrderedHash are empty rather than the OrderedHash itself. [#4356 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-04-10 13:21:20 +02:00
Aaron Patterson
30f3a3df77 errors.rb needs to be declared as UTF-8 [#3941 state:resolved]
Signed-off-by: wycats <wycats@gmail.com>
2010-04-02 09:14:55 -07:00
Sam Pohlenz
3adaef8ae7 Restore changed_attributes method in ActiveModel::Dirty and loosen expectation on including class' initialize method.
[#4308 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-04-01 17:52:45 -07:00
José Valim
f1da7174cc Fix tests added in previous commit. 2010-03-27 11:04:21 +01:00
Jacob Atzen
a5d637d86c ActiveModel::Dirty#changes should return a HashWithIndifferentAccess [#4157 state:resolved]
Keep the Rails style of inject

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-03-27 10:48:32 +01:00
Joshua Peek
4377deed35 ensure activemodel lib is setup correctly 2010-02-28 18:27:00 -06:00
Jeremy Kemper
2ba6049506 Accept array of attributes as arg also, like 2.3 2010-02-25 13:07:48 -08:00
Carlhuda
24ab5665b2 Revert "Fix test load paths for those not using bundler"
This reverts commit eec2d301d4ce9df9c71c1a5aa63053eb970b6818.

This commit broke tests. You cannot have a file called "bundler" on the load path.
2010-02-23 17:31:17 -08:00
José Valim
6fa2bbfd10 Fix AMo isolated tests. 2010-02-22 08:45:41 +01:00
Prem Sichanugrist
8f97e9d19a Add validators reflection so you can do 'Person.validators' and 'Person.validators_on(:name)'.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-02-21 12:37:46 +01:00
José Valim
250c809246 Require persisted? in ActiveModel::Lint and remove new_record? and destroyed? methods. ActionPack does not care if the resource is new or if it was destroyed, it cares only if it's persisted somewhere or not. 2010-02-21 11:12:14 +01:00
José Valim
9dd67fce25 Add to_key and to_param methods to ActiveModel::Conversion. 2010-02-21 09:08:59 +01:00
snusnu
f81c6bc040 AMo #key is now #to_key and CI is probably happy
Obviously #key is a too common name to be included
in the AMo interface, #to_key fits better and also
relates nicely to #to_param. Thx wycats, koz and
josevalim for the suggestion.

AR's #to_key implementation now takes customized
primary keys into account and there's a testcase
for that too.

The #to_param AMo lint makes no assumptions on how
the method behaves in the presence of composite
primary keys. It leaves the decision wether to
provide a default, or to raise and thus signal to
the user that implementing this method will need
his special attention, up to the implementers. All
AMo cares about is that #to_param is implemented
and returns nil in case of a new_record?.

The default CompliantObject used in lint_test
provides a naive default implementation that just
joins all key attributes with '-'.

The #to_key default implementation in lint_test's
CompliantObject now returns [id] instead of [1].
This was previously causing the (wrong) tests I
added for AR's #to_key implementation to pass. The
#to_key tests added with this patch should be
better.

The CI failure was caused by my lack of knowledge
about the test:isolated task. The tests for the
record_identifier code in action_controller are
using fake non AR models and I forgot to stub the
#to_key method over there. This issue didn't come
up when running the test task, only test:isolated
revealed it. This patch fixes that.

All tests pass isolated or not, well, apart from
one previously unpended test in action_controller
that is unrelated to my patch.
2010-02-20 20:17:29 -08:00
snusnu
9acd686753 Adds #key and #to_param to the AMo interface
This commit introduces two new methods that every
AMo compliant object must implement. Below are the
default implementations along with the implied
interface contract.

  # Returns an Enumerable of all (primary) key
  # attributes or nil if new_record? is true
  def key
    new_record? ? nil : [1]
  end

  # Returns a string representing the object's key
  # suitable for use in URLs, or nil if new_record?
  # is true
  def to_param
    key ? key.first.to_s : nil
  end

1) The #key method

Previously rails' record_identifier code, which is
used in the #dom_id helper, relied on calling #id
on the record to provide a reasonable DOM id. Now
with rails3 being all ORM agnostic, it's not safe
anymore to assume that every record ever will have
an #id as its primary key attribute.

Having a #key method available on every AMo object
means that #dom_id can be implemented using

  record.to_model.key # instead of
  record.id

Using this we're able to take composite primary
keys into account (e.g. available in datamapper)
by implementing #dom_id using a newly added

  record_key_for_dom_id(record)

method. The user can overwrite this method to
provide customized versions of the object's key
used in #dom_id.

Also, dealing with more complex keys that can
contain arbitrary strings, means that we need to
make sure that we only provide DOM ids that are
valid according to the spec. For this reason, this
patch sends the key provided through a newly added

  sanitize_dom_id(candidate_id)

method, that makes sure we only produce valid HTML

The reason to not just add #dom_id to the AMo
interface was that it feels like providing a DOM
id should not be a model concern. Adding #dom_id
to the AMo interface would force these concern on
the model, while it's better left to be implemented
in a helper.

Now one could say the same is true for #to_param,
and actually I think that it doesn't really fit
into the model either, but it's used in AR and it's
a main part of integrating into the rails router.

This is different from #dom_id which is only used
in view helpers and can be implemented on top of a
semantically more meaningful method like #key.

2) The #to_param method

Since the rails router relies on #to_param to be
present, AR::Base implements it and returns the
id by default, allowing the user to overwrite the
method if desired.

Now with different ORMs integrating into rails,
every ORM railtie needs to implement it's own
#to_param implementation while already providing
code to be AMo compliant. Since the whole point of
AMo compliance seems to be to integrate any ORM
seamlessly into rails, it seems fair that all we
really need to do as another ORM, is to be AMo
compliant. By including #to_param into the official
interface, we can make sure that this code can be
centralized in the various AMo compliance layers,
and not be added separately by every ORM railtie.

3) All specs pass
2010-02-19 23:31:25 -08:00
Joshua Peek
eec2d301d4 Fix test load paths for those not using bundler 2010-02-15 10:20:11 -06:00
Carl Lerche
9f01dff9c2 Get rails tests running on bundler 0.9 2010-01-31 19:13:43 -08:00
Joshua Peek
db49c706b6 Axe AM state machine
We're going do it eventually, get it done before 3.0 is final.
2010-01-30 18:38:01 -06:00
José Valim
d6e2f5013c Drop AR I18n deprecation and simple use errors.messages as fallback. 2010-01-30 13:12:12 +01:00
Samuel Elliott
31ea83eb89 Adding Proc support to validation messages so that they can become a little more dynamic, allowing for customisations during the request [#3514 status:resolved].
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-01-17 14:40:10 +01:00
José Valim
b078f7fd39 Fix typos and add tests to ensure they will be caught the next time. 2010-01-11 23:38:35 +01:00
José Valim
017f5d5308 Fix typo by renaming :genre to :gender. 2010-01-09 00:18:07 +01:00
José Valim
7045c4c279 Allow validates to map some types to specific options. So now you can do:
validates :email, :presence => true, :format => /@/
  validates :genre, :inclusion => %w(m f)
  validates :password, :length => 6..20
2010-01-08 21:36:04 +01:00
José Valim
fa14d6d51e Compile length validator options still at the class level, so whenever the validator is called, it just needs to check for :maximum, :minimum and :is values. 2010-01-08 21:36:04 +01:00
José Valim
47a5fd4c4b Allow :if, :unless, :on, :allow_nil and :allow_blank as shared options in validates. 2010-01-07 19:23:59 +01:00
jamie
0a79eb7889 Add validates method as shortcut to setup validators for a given set of attributes:
class Person < ActiveRecord::Base
  include MyValidators

  validates :name, :presence => true, :uniqueness => true, :length => { :maximum => 100 }
  validates :email, :presence => true, :email => true
end

[#3058 status:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-01-07 19:23:59 +01:00
José Valim
a25ef06956 Allow to specify default attributes names translation in I18n yml files.
For example, you could easily specify :created_at and :updated_at translations as:

  en:
    attributes:
      created_at: "Created at"
      updated_at: "Updated at"

This configuration is built on ActiveModel, so it means those translations are
shared between different ORMs as well (but always as a fallback).
2010-01-07 15:31:50 +01:00
José Valim
b0572ab2b6 Be sure to dup load paths before clearing the array. 2010-01-07 15:31:50 +01:00
José Valim
190ce3ab37 Errors messages are now moved from :activerecord.errors to simply :errors on I18n yml files. 2010-01-07 15:31:49 +01:00
Joshua Peek
e5ed62deea Autoload AR test case 2010-01-04 16:50:01 -06:00
Joshua Peek
640d9e7e32 Autoload AMo test case 2010-01-04 16:29:07 -06:00
José Valim
4796be33a4 Add missing tests to Validators. 2010-01-03 17:14:50 +01:00
José Valim
08986ce290 Remove deprecated ActiveModel tests (%d and %s is no longer supported in error messages a couple months already) 2010-01-02 22:27:03 +01:00
José Valim
653fa4c10c Add naming to AMo::Lint 2010-01-02 22:27:02 +01:00
José Valim
7cc0a4cfa1 Use activerecord.errors.format as in Rails 2.3.5. 2010-01-02 22:27:02 +01:00
José Valim
5fdd0e80a4 Be sure to convert namespaced names to we have 'Parrots name' instead of 'Parrots.name' in error messages. 2010-01-02 22:27:02 +01:00
José Valim
6d390671f6 Move ActiveRecord callbacks implementation to ActiveModel and make use of it.
Signed-off-by: Yehuda Katz <wycats@Yehuda-Katz.local>
2009-12-28 16:19:23 -08:00
José Valim
74098e4cb6 No need to use ValidationsRepairHelper hack on ActiveModel anymore, Model.reset_callbacks(:validate) is enough. However, tests in ActiveRecord are still coupled, so moved ValidationsRepairHelper back there. 2009-12-23 13:30:58 +01:00
José Valim
e31077c9aa Small clean up in Naming and TTranslation tests. 2009-12-23 12:28:02 +01:00
José Valim
f1085f4128 Move validations in ActiveModel to validators, however all validatity checks are still in the class method. 2009-12-23 00:36:51 +01:00
José Valim
2476c5312d Validator is simply sent to validate method. However, the API needs to change, so validate accepts a record. 2009-12-22 23:12:21 +01:00
Joshua Peek
7ee5843c3c Fully expand relative rails framework paths and make sure we aren't
adding any to the load path more than once.
2009-12-16 11:56:51 -06:00
Carlhuda
c1304098cc Reorganize autoloads:
* A new module (ActiveSupport::Autoload) is provide that extends
    autoloading with new behavior.
  * All autoloads in modules that have extended ActiveSupport::Autoload
    will be eagerly required in threadsafe environments
  * Autoloads can optionally leave off the path if the path is the same
    as full_constant_name.underscore
  * It is possible to specify that a group of autoloads live under an
    additional path. For instance, all of ActionDispatch's middlewares
    are ActionDispatch::MiddlewareName, but they live under 
    "action_dispatch/middlewares/middleware_name"
  * It is possible to specify that a group of autoloads are all found
    at the same path. For instance, a number of exceptions might all
    be declared there.
  * One consequence of this is that testing-related constants are not
    autoloaded. To get the testing helpers for a given component,
    require "component_name/test_case". For instance, "action_controller/test_case".
  * test_help.rb, which is automatically required by a Rails application's
    test helper, requires the test_case.rb for all active components, so
    this change will not be disruptive in existing or new applications.
2009-12-02 20:01:08 -08:00
Joshua Peek
11e798ae0f Avoid adding component lib/ to load path multiple times 2009-11-09 23:28:36 -06:00
José Valim
e714b499cc Move validator, human_name and human_attribute_name to ActiveModel, remove deprecated error messages and add i18n_scope and lookup_ancestors.
Signed-off-by: Carl Lerche <carllerche@mac.com>
2009-10-20 17:52:32 -07:00
Yehuda Katz + Carl Lerche
4f6d6f7031 Have all the tests running off a single Gemfile 2009-10-20 16:34:44 -07:00
Yehuda Katz
02b76862e1 Bundle AMo 2009-10-15 14:04:18 -07:00
Joshua Peek
ff56f3d5e1 Rewrite ActiveModel::Lint as a simple TU mixin 2009-10-07 09:24:51 -05:00
Sam Pohlenz
4df96338ed Fixed behavior of attribute_methods_generated? [#3220 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
2009-10-07 09:07:39 -05:00
Sam Pohlenz
f8e91bda9c Don't share attribute matchers between classes [#3216 state:resolved]
Allows separate models that include ActiveModel::AttributeMethods to
use different sets of attribute matchers.

Signed-off-by: Joshua Peek <josh@joshpeek.com>
2009-10-07 09:07:39 -05:00
Jeremy Kemper
38e056ee2a Use ActiveModel::TestCase base class 2009-09-24 22:56:30 -07:00
Akira Matsuda
0990a13500 Ensure validation errors to be ordered in declared order
[#2301 state:committed milestone:2.3.5]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2009-09-11 18:52:22 -07:00
José Valim
4f37b97033 Changed ActiveRecord to use new callbacks and speed up observers by only notifying events that are actually being consumed.
Signed-off-by: Joshua Peek <josh@joshpeek.com>
2009-09-08 10:26:39 -05:00
Joshua Peek
6dc9ad80e6 Fix warnings in AMo 2009-09-05 19:10:21 -05:00
Joshua Peek
c6e0923245 Fix failing AMo isolated tests 2009-09-05 18:54:19 -05:00
Kane
cf9f361699 added proc and symbol support to validates_numericality_of [#3049 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
2009-08-31 13:35:14 -05:00
Yehuda Katz
dbf20c2dbb Initial AMo Lint implementation 2009-08-29 01:49:18 -05:00
Pratik Naik
25e5b0c4a8 Remove support for SQLite 2.
If you're still using it, please install the plugin from git://github.com/rails/sqlite2_adapter.git
2009-08-17 14:54:34 +01:00
Elliot Winkler
cccb0e6b93 Add validates_format_of :without => /regexp/ option [Elliot Winkler, Peer Allan]
[#430 state:resolved]

  Example :

    validates_format_of :subdomain, :without => /www|admin|mail/

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
2009-08-10 15:22:31 +01:00
Jeff Dean
22f3398253 Introduce validates_with to encapsulate attribute validations in a class.
[#2630 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2009-08-09 22:47:56 -07:00
Adam Keys
5632b36701 Fix exclusive range patch to use begin/end instead of min/max. [#2981 status:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
2009-08-08 23:42:18 +01:00
Pratik Naik
c6fe49b009 Simplyfy validates_length_of and remove puts 2009-08-08 19:08:39 +01:00
jzw
5ab94b2595 validates_length_of with maximum should allow nil [#2309 status:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2009-08-08 19:08:13 +01:00
James Hill
cfd421daa2 Allow validations to use values from custom readers [#2936 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
2009-08-05 11:45:01 -05:00
Joshua Peek
272c504f91 Dasherize XML root by default to avoid invalid tags "<admin/posts>...</admin/posts>" [#2875 state:resolved] 2009-07-22 21:06:34 -05:00
John Maxwell
c39151a847 Patch to ActiveModel's (and ActiveRecord, by association) XML serialization: If two parameters are present in Procs supplied to to_xml's :procs option, the model being serialized will be passed as the second argument [#2373 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
2009-07-22 20:47:15 -05:00
Joshua Peek
6944b391cd Kill AMo Base 2009-07-21 00:13:26 -05:00
Joshua Peek
2685d93b07 Kill AMo ivar attributes helper 2009-07-20 23:28:58 -05:00
Joshua Peek
d2b78b3594 Initial extraction of AMo xml serializer 2009-07-03 21:38:14 -05:00
Joshua Peek
e3d6d10e1f Ensure JSON serializer includes model naming 2009-07-03 21:38:13 -05:00
Yehuda Katz + Carl Lerche
7583a24ee0 Move mocha down below initial T::U require and bump version to 0.9.7 [#2858 state:resolved] 2009-07-01 11:53:17 -07:00
Joshua Peek
fbdf706fff Add basic JSON serializer to AMo 2009-06-17 21:27:54 -05:00
Joshua Peek
af5301089f Add simple attribute implementation backed by ivars 2009-06-17 21:27:54 -05:00
Joshua Peek
d5d59230f4 Simplify AMo validation attribute reader 2009-06-17 21:27:54 -05:00
Joshua Peek
1c4d28ba31 Move model naming into ActiveModel 2009-06-17 10:37:39 -05:00
Joshua Peek
4d70359200 Integrate ActiveModel::Observing into ActiveRecord 2009-06-10 23:36:44 -05:00
Joshua Peek
69742ca8fa Merge branch 'master' into active_model
Conflicts:
	activemodel/lib/active_model/core.rb
	activemodel/test/cases/state_machine/event_test.rb
	activemodel/test/cases/state_machine/state_transition_test.rb
	activerecord/lib/active_record/validations.rb
	activerecord/test/cases/validations/i18n_validation_test.rb
	activeresource/lib/active_resource.rb
	activeresource/test/abstract_unit.rb
2009-05-29 16:06:21 -05:00
Jeremy Kemper
e8550ee032 Cherry-pick core extensions 2009-05-13 12:00:15 -07:00
Pratik Naik
d758d996d1 Deprecate Model#validate/validate_on_create/validate_on_update. Use Model.validate :method and likewise 2009-03-21 19:07:15 +00:00
Pratik Naik
320933205e Deprecate Errors#on_base/add_to_base/invalid?/each_full 2009-03-21 18:34:05 +00:00
Pratik Naik
6173e5bfae Add ActiveModel::Validations tests for regular ruby classes 2009-03-20 22:21:27 +00:00
Pratik Naik
08a99d0eac Add I18n translations to ActiveModel and move more AR specific parts to ActiveRecord::Validations 2009-03-20 21:45:13 +00:00
Pratik Naik
7d187c193c Validation tests arent using any fixtures 2009-03-20 18:07:35 +00:00
Pratik Naik
4a582aa7ca Use mattr_accessor in TestsDatabase instead of setup method 2009-03-20 17:56:46 +00:00
Pratik Naik
37283a6aae Deprecate Error#on(attribute) in favour of Errors#[attribute] 2009-03-20 17:36:22 +00:00
Pratik Naik
4367f39dea TestDatabase -> TestsDatabase 2009-03-20 16:02:12 +00:00
Pratik Naik
d01e639daf Remove unused columns from the ActiveModel test schema 2009-03-20 15:33:40 +00:00
Pratik Naik
60756ad4ec Move relevant validation tests from Active Record to Active Model 2009-03-20 15:07:49 +00:00
Pratik Naik
e945bcfe4a Add test sqlite3 db to .gitignore 2009-03-20 11:22:27 +00:00
Pratik Naik
5b1a1bf5bf Make Active Model test suite similar to Active Record 2009-03-20 10:32:24 +00:00
Jeremy Kemper
1c36172c13 Ruby 1.9 compat: rename deprecated assert_raises to assert_raise.
[#1617 state:resolved]
2009-03-08 13:11:58 -07:00
Jeremy Kemper
d9c95c82e5 Explicitly require Active Support for tests 2008-11-24 22:45:44 -08:00
Jeremy Kemper
e931012287 Require Mocha >= 0.9.3 which includes a MiniTest adapter 2008-11-23 15:05:59 -08:00
Jeremy Kemper
0492759db3 MiniTest compat: don't shadow @name 2008-11-22 19:19:13 -08:00
Jeremy Kemper
5b7d07f423 Require mocha for tests. Get rid of uses_mocha helper. 2008-11-19 11:08:34 -08:00
Jeremy Kemper
a1ce4008c8 Require mocha before the testcase overrides, otherwise its run method is clobbered 2008-11-19 11:08:19 -08:00
Jeremy Kemper
d7bad6e2eb Use the Ruby load path for test_helper requires. Fix AM::TestCase. 2008-11-15 20:25:14 -08:00
rick
c9e366e997 all aasm tests without activerecord moved over and passing 2008-06-28 11:33:50 -07:00
rick
a9d9ca16c7 converted tests for more complex state transitions 2008-06-28 11:01:40 -07:00
rick
74cb056986 add basic events and transitions. still more tests to convert 2008-06-28 09:19:44 -07:00
rick
b9528ad3c5 initial statemachine machine and state classes 2008-06-28 00:55:02 -07:00
rick
7fc628e3fc convert specs to tests 2008-06-27 23:29:03 -07:00