aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/enum_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* add ActiveRecord::Enum testcase about multiple enums declaring at a timekeepcosmos2015-03-051-0/+14
|
* Error message testing fixFranky W2015-02-201-2/+4
| | | | | | | | | The testing of error messages have been implemented wrongly a few times. This is an attempt to fix it. For example, some of these test should have failed with the new code. The reason they are not failling with the new string is the fact they were not being tested beforehand.
* Mention `where.not` in the exampleGodfrey Chan2015-02-141-0/+4
| | | | | | | ...so it doesn't look like you *have* to use SQL strings for that case (not anymore!). Would like to replace the SQL string example with something that you cannot do with the "normal" query API, but I could not come up with a short, realistic example. Suggestions welcome!
* Fixed a bug where NULLs are casted into the first enum valueGodfrey Chan2015-02-131-3/+8
|
* Partially revert ae33aeaGodfrey Chan2015-02-131-4/+0
| | | | | Using enum names in SQL strings doesn't actually work, the test was wrong (fixed in 3dfd1ba).
* Break up these testsGodfrey Chan2015-02-131-4/+23
| | | | Make sure we have coverage for both the find/build cases
* oops, 'format' is not a real enumGodfrey Chan2015-02-131-8/+8
|
* Enums should be referred to by symbolsGodfrey Chan2015-02-131-1/+14
| | | | | Also updated the documentation about the new ability to query them normally, and added test to make sure they work!
* Refactor enum to be defined in terms of the attributes APISean Griffin2015-02-111-1/+16
| | | | | | | | | | | In addition to cleaning up the implementation, this allows type casting behavior to be applied consistently everywhere. (#where for example). A good example of this was the previous need for handling value to key conversion in the setter, because the number had to be passed to `where` directly. This is no longer required, since we can just pass the string along to where. (It's left around for backwards compat) Fixes #18387
* Enums shouldn't ruin people's anniversariesGodfrey Chan2014-09-041-1/+2
| | | | | | | | Added a few more methods on Module/Class to the dangerous class methods blacklist. (Technically, allocate and new are already protected currently because we happen to redefine them in the current implantation.) Closes #16792
* Follow up to bbe7fe41 to fix enum leakage across classes.Godfrey Chan2014-04-071-7/+28
| | | | | | | | The original attempt didn't really fix the problem and wasn't testing the problematic area. This commit corrected those issues in the original commit. Also removed the private `enum_mapping_for` method. As `defined_enums` is now a method, this method doesn't provide much value anymore.
* make enums distinct per classEvan Whalen2014-04-071-0/+15
|
* Block a few default Class methods as scope name.Arthur Neves2014-04-031-0/+1
| | | | | | Add tests to make sure scopes cannot be create with names such as: private, protected, public. Make sure enum values don't collide with those methods too.
* Fix a bug affecting validations of enum attributesTheMonster2014-02-271-0/+27
| | | | | | | | | | | | | | This fixes a bug where any enum attribute of a model would be evaluated always as 0 when calling the database on validations. This fix converts the value of the enum attribute to its integer value rather than the string before building the relation as the bug occured when the string finally gets converted to integer using string.to_i which converts it to 0. [Vilius Luneckas, Ahmed AbouElhamayed]
* Remove unused variable.Tim Fenney2014-01-311-1/+1
|
* `enum` now raises on "dangerous" name conflictsGodfrey Chan2014-01-291-0/+59
| | | | | | | | | Dangerous name conflicts includes instance or class method conflicts with methods defined within `ActiveRecord::Base` but not its ancestors, as well as conflicts with methods generated by other enums on the same class. Fixes #13389.
* Remove unused assignment to fix warnings in enum test.Vipul A M2014-01-241-1/+0
|
* Add more tests for the dirty feature for enumsRafael Mendonça França2014-01-211-0/+32
|
* Make enum feature work with dirty methodsRafael Mendonça França2014-01-211-0/+40
| | | | | To make this possible we have to override the save_changed_attribute hook.
* Enum mappings are now exposed via class methods instead of constants.Godfrey Chan2014-01-141-3/+3
| | | | | | | | | | | | | | | | Example: class Conversation < ActiveRecord::Base enum status: [ :active, :archived ] end Before: Conversation::STATUS # => { "active" => 0, "archived" => 1 } After: Conversation.statuses # => { "active" => 0, "archived" => 1 }
* use enum labels as form values. Achieved by `_before_type_cast`.Yves Senn2014-01-111-0/+4
| | | | | | | | | | | | | | | | | | | Closes #13650, #13672 This is an alternate implementation to solve #13650. Currently form fields contain the enum value (eg. "1"). This breaks because the setter `enum=` expects the label (eg. "active"). ActiveRecord::Enum allows you to use labels in your application but store numbers. We should make sure that all parts after AR are dealing with labels and not the underlying mapping to a number. This patch defines `_before_type_cast` on every enum column to return the label. This method is later used to fetch the value to display in form fields. I deliberately copied the implementation of the enum getter instead of delegating to it. This allows you to overwrite the getter and for example return a `Value Object` but have it still work for form fields.
* Building new records with enum scopes now works as expectedGodfrey Chan2014-01-031-6/+7
| | | | | | | | | | | | | | | | | | | | | | Previously, this would give an `ArgumentError`: class Issue < ActiveRecord::Base enum :status, [:open, :finished] end Issue.open.build # => ArgumentError: '0' is not a valid status Issue.open.create # => ArgumentError: '0' is not a valid status PR #13542 muted the error, but the issue remains. This commit fixes the issue by allowing the enum value to be written directly via the setter: Issue.new.status = 0 # This now sets status to :open Assigning a value directly via the setter like this is not part of the documented public API, so users should not rely on this behavior. Closes #13530.
* Fix the enums writer methodsRobin Dupret2014-01-011-1/+10
| | | | | | | | | | | Previously, the writer methods would simply check whether the passed argument was the symbol representing the integer value of an enum field. Therefore, it was not possible to specify the numeric value itself but the dynamically defined scopes generate where clauses relying on this kind of values so a chained call to a method like `find_or_initialize_by` would trigger an `ArgumentError`. Reference #13530
* Add the ability to nullify the `enum` columnAmr Tamimi2014-01-011-0/+15
|
* bring back constant to expose the enum mapping as HWIA.Yves Senn2013-11-061-0/+6
|
* store enum mapping using `Strings` instead of `Symbols`.Yves Senn2013-11-051-2/+7
| | | | | This allows to assign both `String` and `Symbol` values to the enum without having to call `to_sym`, which is a security problem.
* direct enum assignment rasies ArgumentError for unknown values.Yves Senn2013-11-051-0/+12
|
* define enum methods inside a `Module` to make them overwritable.Yves Senn2013-11-051-0/+5
|
* The enum value constant isn't used, so rm it for now.Aaron Patterson2013-11-041-10/+0
|
* fix copy & paste test-case naming. [ci skip]Yves Senn2013-11-041-1/+1
|
* Explicit mapping for enumYury Korolev2013-11-021-0/+8
|
* Add a test case for the scope enum addsDavid Heinemeier Hansson2013-11-021-0/+4
|
* Use an already existing fixtureCarlos Antonio da Silva2013-11-021-1/+1
|
* Fix to work on Ruby 1.9.3, example and changelog improvementsCarlos Antonio da Silva2013-11-021-3/+3
|
* Added ActiveRecord::Base#enum for declaring enum attributes where the values ↵David Heinemeier Hansson2013-11-021-0/+36
map to integers in the database, but can be queried by name