aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
Commit message (Collapse)AuthorAgeFilesLines
* Rename match_attribute_method? to matched_attribute_methodMarcin Olichwirowicz2015-08-121-4/+4
| | | | | `match_attribute_method?` is a bit confusing because it suggest that a return value is a boolean which is not true.
* Remove XML Serialization from core.Zachary Scott2015-08-077-502/+5
| | | | | | | This includes the following classes: - ActiveModel::Serializers::Xml - ActiveRecord::Serialization::XmlSerializer
* pass the correct argument to mock on a test of `validates_length_of`yuuji.yaginuma2015-07-281-1/+1
|
* Freeze string literals when not mutated.schneems2015-07-193-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37) please [give me a pull request to the appropriate file](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/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)
* Revert "Revert "Reduce allocations when running AR callbacks.""Guo Xiang Tan2015-07-162-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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}" ```
* Removes unnecessary comments from i18n validations tests [ci skip]Zamith2015-07-111-61/+2
| | | | | | These comments do not add a lot to the readability, grepability or overall understanding of the tests, therefore I believe they can be safely removed.
* Remove the reference to mocha in activemodelZamith2015-07-111-27/+27
| | | | | Activemodel is no longer dependent on mocha, so we can make the comments more generic.
* Use private method call assertions in Active Model tests.Kasper Timm Hansen2015-07-104-59/+46
| | | | Also fix Minitest constant reference.
* Merge pull request #20803 from TheBlasfem/marking_serialization_classRafael Mendonça França2015-07-081-1/+1
|\ | | | | marking serialization class in Readme
| * marking serialization classJulio Lopez2015-07-071-1/+1
| |
* | docs, clarify the meanaing of return values from validation methods.Yves Senn2015-07-071-0/+3
| | | | | | | | | | | | | | | | | | | | [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.
* | docs, remove accidental :nodoc: of ActiveModel::Validations::ClassMethods ↵Yves Senn2015-07-071-2/+1
|/ | | | | | | | | | | | | | | | | | | | | 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
* Separate the constraint and other options [ci skip]Robin Dupret2015-07-011-3/+8
| | | | | | | | | | 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]
* Improve Validation Helpers' documentation comments and testsRadan Skoric2015-06-275-7/+41
|
* A few documentation fixes [ci skip]Robin Dupret2015-06-231-1/+1
|
* Add nodoc to the Validations::Helpers [ci skip]Mehmet Emin İNAÇ2015-06-221-1/+1
|
* docs, :scissors: wrongly placed heading. [ci skip]Yves Senn2015-06-221-2/+0
| | | | | The heading "Active Model Length Validator" was shown on the "ActiveModel::Validations" page without any text following it.
* Move the validations HelperMethods to its own fileRoque Pinel2015-06-212-10/+13
| | | | | | Closes #11209 [Roque Pinel & Steven Yang]
* select the AR adapter through `bin/test`.Yves Senn2015-06-111-0/+1
|
* use our runner (`bin/test`) for framework components.Yves Senn2015-06-111-0/+3
| | | | | | | | | | This adds a script `bin/test` to most Rails framework components. The script uses the rails minitest plugin to augment the runner. See https://github.com/rails/rails/pull/19571 for details about the plugin. I did not yet add `bin/test` for activerecord, activejob and railties. These components rely on specific setup performed in the rake-tasks.
* Revert "Add code example for include option of ↵Rafael Mendonça França2015-06-101-14/+1
| | | | | | | | AM::Serialization#serializable_hash" This reverts commit 3d949f34816d6eca0a6b59cfa08d91f36e8e64dd. This was already documented in other PR.
* Add code example for include option of AM::Serialization#serializable_hashRadan Skoric2015-06-091-1/+14
|
* Fix typo in AM I18n validation test name [skip ci]Anton Davydov2015-06-091-1/+1
|
* Tiny documentation edits [ci skip]Robin Dupret2015-06-071-2/+2
|
* Merge pull request #20004 from rusikf/patch-1Robin Dupret2015-06-071-0/+31
|\ | | | | add docs to include option at ActiveModel::Serialization [ci skip]
| * add docs to include option at ActiveModel::Serialization#serializable_hash ↵rusikf2015-05-111-0/+31
| | | | | | | | [ci skip]
* | Require yaml for isolation testRafael Mendonça França2015-05-291-0/+1
| | | | | | | | | | It was removed when we removed mocha at 5a6ae7f7539216931f2b3f4aa53394ac4136c74e
* | formatting changesunknown2015-05-292-5/+5
| |
* | Remove use of mocha from Active ModelRoque Pinel2015-05-284-59/+117
| |
* | Remove unused package tasksArun Agrawal2015-05-281-10/+2
| | | | | | | | We are using `all:build` now.
* | Merge pull request #20262 from arunagw/aa-remove-broken-unused-release-taskYves Senn2015-05-271-7/+0
|\ \ | | | | | | Remove broken and unused release task
| * | Remove broken and unused release taskArun Agrawal2015-05-221-7/+0
| | | | | | | | | | | | | | | - We do release with release.rb - There is no `rake/gemcutter`
* | | Spelling/typo/grammatical fixes [ci skip]karanarora2015-05-231-1/+1
|/ / | | | | | | | | | | | | | | | | | | spelling fix [ci skip] example to be consistent [ci skip] grammatical fix typo fixes [ci skip]
* | [ci skip] Don’t encourage `sudo gem install`claudiob2015-05-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | I think we are better off leaving `sudo` outside of the documented way of installing gems (`activerecord`, `actionpack`, …). We don’t want newbies to think that `sudo` is required or, even worse, than they actually have to type `[sudo] gem install`. In most scenarios, `sudo` is not needed to install gems, and people who do need it, probably already know about it. What do you think? :grin:
* | Stop skipping a test that now works on Rubiniusclaudiob2015-05-101-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The test was skipped because of an issue that, in the meantime, has been fixed: https://github.com/rubinius/rubinius/issues/3328. Using the latest Rubinius (the one currently on Travis CI), this is the result: ```sh $ ruby --version rubinius 2.5.3 (2.1.0 2482b093 2015-05-10 3.5.1 JI) [x86_64-darwin14.3.0] ``` **Before this PR** ```sh $ ruby -Itest test/cases/attribute_assignment_test.rb Run options: --seed 58569 .....S... Finished in 0.048278s, 186.4203 runs/s, 269.2738 assertions/s. 9 runs, 13 assertions, 0 failures, 0 errors, 1 skips You have skipped tests. Run with --verbose for details. ``` **After this PR** $ ruby -Itest test/cases/attribute_assignment_test.rb Run options: --seed 35720 ......... Finished in 0.029441s, 305.6961 runs/s, 475.5273 assertions/s. 9 runs, 14 assertions, 0 failures, 0 errors, 0 skips ```
* | minor rdoc syntax fix [ci skip]Gourav Tiwari2015-05-081-2/+2
| |
* | Adds/Corrects use case for adding an error messageZamith2015-05-042-1/+7
|/ | | | | I believe this is a use case that was supposed to be supported, and it's a small fix.
* ensure `method_missing` called for non-existing methods passed toJay Elaraj2015-04-283-10/+22
| | | | `ActiveModel::Serialization#serializable_hash`
* Don't document private internal constant [ci skip]Zachary Scott2015-04-261-0/+1
|
* Fix grammar/style: assigns/declares -> assignments/declarations.Tim Wade2015-04-241-3/+3
| | | | [ci skip]
* Fix grammar/style: use (v) fall back (on).Tim Wade2015-04-241-1/+1
| | | | [ci skip]
* Fix grammar/style: break up long sentence.Tim Wade2015-04-241-2/+2
| | | | | | | A conjunction was needed to make these sentences correct. Breaking them up seemed like a better option. [ci skip]
* Fix grammar/style: pluralize 'each of its method'Tim Wade2015-04-241-1/+1
| | | | [ci skip]
* pass over CHANGELOGs. [ci skip]Yves Senn2015-04-221-1/+1
|
* Add `ActiveModel::Dirty#[attr_name]_previously_changed?` andFernando Tapia Rico2015-04-213-2/+43
| | | | | | | | `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.
* Merge pull request #19753 from jonatack/use-ruby-2-2-2Guillermo Iguaran2015-04-131-1/+1
|\ | | | | Upgrade to Ruby 2.2.2
| * Upgrade to Ruby 2.2.2Jon Atack2015-04-141-1/+1
| | | | | | | | and fix the grammar in the ruby_version_check.rb user message.
* | Merge pull request #19448 from tgxworld/fix_activesupport_callbacks_clash_on_runRafael Mendonça França2015-04-062-2/+2
|\ \ | | | | | | Fix AS::Callbacks raising an error when `:run` callback is defined.
| * | Revert "Reduce allocations when running AR callbacks."Guo Xiang Tan2015-03-222-2/+2
| | | | | | | | | | | | This reverts commit 796cab45561fce268aa74e6587cdb9cae3bb243e.
* | | fix typo in deprecation message. [Robin Dupret]Yves Senn2015-04-051-1/+1
| | |