rails 4.2.0 → 4.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 820f40537f6670c1bf36f61979047ac3b8173437
4
- data.tar.gz: 19860336f8213b3e83f09118a638d40a67b625bb
3
+ metadata.gz: 4e087cbe55af0d08158b557b367f6c2659f0ec1d
4
+ data.tar.gz: 7971fa171d28124f22623f145367afb5522cfdbd
5
5
  SHA512:
6
- metadata.gz: 0d9aba1fdb1c9bcf61616777f57854700e8b58fde7a17eed6d39e5fed8e95751bccefc834a94aa2fd03e11f1aa4939dc7e7a48736d5e9dcda1b4ab28cc3ab094
7
- data.tar.gz: 0c778c7b93788d1f30764afe47f47a761c423f7d501b322c56a6ed0f66cd2147f85eda2c3a6bbb92283ed792868f36b6e6b3c1f860a81cd169c354d0823a3336
6
+ metadata.gz: 560d2cdea938f753a4cca004bd54299acb334f7782d69110dd9124ec4f8b18b8a6755d1d2fa33e8c8712b2b5cb138aa70bfd95dddce0e83825fc698cb1a53b0c
7
+ data.tar.gz: 79c1412cb6b5a021128ec34108bc67bbdb984808748199dfc868e18d05a9f53ba7b773d056c4e4d7399412e5371286bf93696d04098f90dedf71093069bd8c6f
data/guides/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## Rails 4.2.3 (June 25, 2015) ##
2
+
3
+ * No Changes *
4
+
5
+
6
+ ## Rails 4.2.2 (June 16, 2015) ##
7
+
8
+ * No Changes *
9
+
10
+
11
+ ## Rails 4.2.1 (March 19, 2015) ##
12
+
13
+ * No changes.
14
+
15
+
16
+ ## Rails 4.2.0 (December 20, 2014) ##
17
+
1
18
  * New guide about constant autoloading and reloading.
2
19
 
3
20
  *Xavier Noria*
@@ -1,5 +1,5 @@
1
1
  # Activate the gem you are reporting the issue against.
2
- gem 'rails', '4.0.0'
2
+ gem 'rails', '4.2.0'
3
3
 
4
4
  require 'rails'
5
5
  require 'action_controller/railtie'
@@ -1,5 +1,5 @@
1
1
  # Activate the gem you are reporting the issue against.
2
- gem 'activerecord', '4.0.0'
2
+ gem 'activerecord', '4.2.0'
3
3
  require 'active_record'
4
4
  require 'minitest/autorun'
5
5
  require 'logger'
@@ -0,0 +1,15 @@
1
+ # Activate the gems you are reporting the issue against.
2
+ gem 'activesupport', '4.2.0'
3
+ require 'active_support'
4
+ require 'active_support/core_ext/object/blank'
5
+ require 'minitest/autorun'
6
+
7
+ # Ensure backward compatibility with Minitest 4
8
+ Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
9
+
10
+ class BugTest < Minitest::Test
11
+ def test_stuff
12
+ assert "zomg".present?
13
+ refute "".present?
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ unless File.exist?('Gemfile')
2
+ File.write('Gemfile', <<-GEMFILE)
3
+ source 'https://rubygems.org'
4
+ gem 'rails', github: 'rails/rails'
5
+ gem 'arel', github: 'rails/arel'
6
+ GEMFILE
7
+
8
+ system 'bundle'
9
+ end
10
+
11
+ require 'bundler'
12
+ Bundler.setup(:default)
13
+
14
+ require 'active_support'
15
+ require 'active_support/core_ext/object/blank'
16
+ require 'minitest/autorun'
17
+
18
+ # Ensure backward compatibility with Minitest 4
19
+ Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
20
+
21
+ class BugTest < Minitest::Test
22
+ def test_stuff
23
+ assert "zomg".present?
24
+ refute "".present?
25
+ end
26
+ end
@@ -7,11 +7,9 @@ module RailsGuides
7
7
  t = str2
8
8
  n = s.length
9
9
  m = t.length
10
- max = n/2
11
10
 
12
11
  return m if (0 == n)
13
12
  return n if (0 == m)
14
- return n if (n - m).abs > max
15
13
 
16
14
  d = (0..m).to_a
17
15
  x = nil
@@ -172,7 +172,7 @@ Rails Architectural Changes
172
172
 
173
173
  The major change in Rails 3.1 is the Assets Pipeline. It makes CSS and JavaScript first-class code citizens and enables proper organization, including use in plugins and engines.
174
174
 
175
- The assets pipeline is powered by [Sprockets](https://github.com/sstephenson/sprockets) and is covered in the [Asset Pipeline](asset_pipeline.html) guide.
175
+ The assets pipeline is powered by [Sprockets](https://github.com/rails/sprockets) and is covered in the [Asset Pipeline](asset_pipeline.html) guide.
176
176
 
177
177
  ### HTTP Streaming
178
178
 
@@ -90,6 +90,9 @@ Post.find(2) # Subsequent calls reuse the cached prepared statement
90
90
  Post.find_by_title('first post')
91
91
  Post.find_by_title('second post')
92
92
 
93
+ Post.find_by(title: 'first post')
94
+ Post.find_by(title: 'second post')
95
+
93
96
  post.comments
94
97
  post.comments(true)
95
98
  ```
@@ -297,6 +300,30 @@ application is using any of these spellings, you will need to update them:
297
300
  assert_select('p', 'AT&amp;T') # => false
298
301
  ```
299
302
 
303
+ Furthermore substitutions have changed syntax.
304
+
305
+ Now you have to use a `:match` CSS-like selector:
306
+
307
+ ```ruby
308
+ assert_select ":match('id', ?)", 'comment_1'
309
+ ```
310
+
311
+ Additionally Regexp substitutions look different when the assertion fails.
312
+ Notice how `/hello/` here:
313
+
314
+ ```ruby
315
+ assert_select(":match('id', ?)", /hello/)
316
+ ```
317
+
318
+ becomes `"(?-mix:hello)"`:
319
+
320
+ ```
321
+ Expected at least 1 element matching "div:match('id', "(?-mix:hello)")", found 0..
322
+ Expected 0 to be >= 1.
323
+ ```
324
+
325
+ See the [Rails Dom Testing](https://github.com/rails/rails-dom-testing/tree/8798b9349fb9540ad8cb9a0ce6cb88d1384a210b) documentation for more on `assert_select`.
326
+
300
327
 
301
328
  Railties
302
329
  --------
@@ -735,7 +735,7 @@ You can choose not to yield and build the response yourself, in which case the a
735
735
 
736
736
  While the most common way to use filters is by creating private methods and using *_action to add them, there are two other ways to do the same thing.
737
737
 
738
- The first is to use a block directly with the *_action methods. The block receives the controller as an argument, and the `require_login` filter from above could be rewritten to use a block:
738
+ The first is to use a block directly with the *\_action methods. The block receives the controller as an argument, and the `require_login` filter from above could be rewritten to use a block:
739
739
 
740
740
  ```ruby
741
741
  class ApplicationController < ActionController::Base
@@ -1164,67 +1164,10 @@ class ClientsController < ApplicationController
1164
1164
  end
1165
1165
  ```
1166
1166
 
1167
- WARNING: You shouldn't do `rescue_from Exception` or `rescue_from StandardError` unless you have a particular reason as it will cause serious side-effects (e.g. you won't be able to see exception details and tracebacks during development). If you would like to dynamically generate error pages, see [Custom errors page](#custom-errors-page).
1167
+ WARNING: You shouldn't do `rescue_from Exception` or `rescue_from StandardError` unless you have a particular reason as it will cause serious side-effects (e.g. you won't be able to see exception details and tracebacks during development).
1168
1168
 
1169
1169
  NOTE: Certain exceptions are only rescuable from the `ApplicationController` class, as they are raised before the controller gets initialized and the action gets executed. See Pratik Naik's [article](http://m.onkey.org/2008/7/20/rescue-from-dispatching) on the subject for more information.
1170
1170
 
1171
-
1172
- ### Custom errors page
1173
-
1174
- You can customize the layout of your error handling using controllers and views.
1175
- First define your app own routes to display the errors page.
1176
-
1177
- * `config/application.rb`
1178
-
1179
- ```ruby
1180
- config.exceptions_app = self.routes
1181
- ```
1182
-
1183
- * `config/routes.rb`
1184
-
1185
- ```ruby
1186
- match '/404', via: :all, to: 'errors#not_found'
1187
- match '/422', via: :all, to: 'errors#unprocessable_entity'
1188
- match '/500', via: :all, to: 'errors#server_error'
1189
- ```
1190
-
1191
- Create the controller and views.
1192
-
1193
- * `app/controllers/errors_controller.rb`
1194
-
1195
- ```ruby
1196
- class ErrorsController < ActionController::Base
1197
- layout 'error'
1198
-
1199
- def not_found
1200
- render status: :not_found
1201
- end
1202
-
1203
- def unprocessable_entity
1204
- render status: :unprocessable_entity
1205
- end
1206
-
1207
- def server_error
1208
- render status: :server_error
1209
- end
1210
- end
1211
- ```
1212
-
1213
- * `app/views`
1214
-
1215
- ```
1216
- errors/
1217
- not_found.html.erb
1218
- unprocessable_entity.html.erb
1219
- server_error.html.erb
1220
- layouts/
1221
- error.html.erb
1222
- ```
1223
-
1224
- Do not forget to set the correct status code on the controller as shown before.
1225
-
1226
- WARNING: You should avoid using the database or any complex operations because the user is already on the error page. Generating another error while on an error page could cause issues like presenting an empty page for the users.
1227
-
1228
1171
  Force HTTPS protocol
1229
1172
  --------------------
1230
1173
 
@@ -48,7 +48,7 @@ create test/mailers/previews/user_mailer_preview.rb
48
48
  ```ruby
49
49
  # app/mailers/application_mailer.rb
50
50
  class ApplicationMailer < ActionMailer::Base
51
- default "from@example.com"
51
+ default from: "from@example.com"
52
52
  layout 'mailer'
53
53
  end
54
54
 
@@ -507,6 +507,9 @@ url helper.
507
507
  <%= user_url(@user, host: 'example.com') %>
508
508
  ```
509
509
 
510
+ NOTE: non-`GET` links require [jQuery UJS](https://github.com/rails/jquery-ujs)
511
+ and won't work in mailer templates. They will result in normal `GET` requests.
512
+
510
513
  ### Sending Multipart Emails
511
514
 
512
515
  Action Mailer will automatically send multipart emails if you have different
@@ -670,7 +673,7 @@ files (environment.rb, production.rb, etc...)
670
673
  | Configuration | Description |
671
674
  |---------------|-------------|
672
675
  |`logger`|Generates information on the mailing run if available. Can be set to `nil` for no logging. Compatible with both Ruby's own `Logger` and `Log4r` loggers.|
673
- |`smtp_settings`|Allows detailed configuration for `:smtp` delivery method:<ul><li>`:address` - Allows you to use a remote mail server. Just change it from its default `"localhost"` setting.</li><li>`:port` - On the off chance that your mail server doesn't run on port 25, you can change it.</li><li>`:domain` - If you need to specify a HELO domain, you can do it here.</li><li>`:user_name` - If your mail server requires authentication, set the username in this setting.</li><li>`:password` - If your mail server requires authentication, set the password in this setting.</li><li>`:authentication` - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of `:plain`, `:login`, `:cram_md5`.</li><li>`:enable_starttls_auto` - Set this to `false` if there is a problem with your server certificate that you cannot resolve.</li></ul>|
676
+ |`smtp_settings`|Allows detailed configuration for `:smtp` delivery method:<ul><li>`:address` - Allows you to use a remote mail server. Just change it from its default `"localhost"` setting.</li><li>`:port` - On the off chance that your mail server doesn't run on port 25, you can change it.</li><li>`:domain` - If you need to specify a HELO domain, you can do it here.</li><li>`:user_name` - If your mail server requires authentication, set the username in this setting.</li><li>`:password` - If your mail server requires authentication, set the password in this setting.</li><li>`:authentication` - If your mail server requires authentication, you need to specify the authentication type here. This is a symbol and one of `:plain` (will send the password in the clear), `:login` (will send password Base64 encoded) or `:cram_md5` (combines a Challenge/Response mechanism to exchange information and a cryptographic Message Digest 5 algorithm to hash important information)</li><li>`:enable_starttls_auto` - Detects if STARTTLS is enabled in your SMTP server and starts to use it. Defaults to `true`.</li><li>`:openssl_verify_mode` - When using TLS, you can set how OpenSSL checks the certificate. This is really useful if you need to validate a self-signed and/or a wildcard certificate. You can use the name of an OpenSSL verify constant ('none', 'peer', 'client_once', 'fail_if_no_peer_cert') or directly the constant (`OpenSSL::SSL::VERIFY_NONE`, `OpenSSL::SSL::VERIFY_PEER`, ...).</li></ul>|
674
677
  |`sendmail_settings`|Allows you to override options for the `:sendmail` delivery method.<ul><li>`:location` - The location of the sendmail executable. Defaults to `/usr/sbin/sendmail`.</li><li>`:arguments` - The command line arguments to be passed to sendmail. Defaults to `-i -t`.</li></ul>|
675
678
  |`raise_delivery_errors`|Whether or not errors should be raised if the email fails to be delivered. This only works if the external email server is configured for immediate delivery.|
676
679
  |`delivery_method`|Defines a delivery method. Possible values are:<ul><li>`:smtp` (default), can be configured by using `config.action_mailer.smtp_settings`.</li><li>`:sendmail`, can be configured by using `config.action_mailer.sendmail_settings`.</li><li>`:file`: save emails to files; can be configured by using `config.action_mailer.file_settings`.</li><li>`:test`: save emails to `ActionMailer::Base.deliveries` array.</li></ul>See [API docs](http://api.rubyonrails.org/classes/ActionMailer/Base.html) for more info.|
@@ -743,7 +746,9 @@ Mailer framework. You can do this in an initializer file
743
746
  `config/initializers/sandbox_email_interceptor.rb`
744
747
 
745
748
  ```ruby
746
- ActionMailer::Base.register_interceptor(SandboxEmailInterceptor) if Rails.env.staging?
749
+ if Rails.env.staging?
750
+ ActionMailer::Base.register_interceptor(SandboxEmailInterceptor)
751
+ end
747
752
  ```
748
753
 
749
754
  NOTE: The example above uses a custom environment called "staging" for a
@@ -435,39 +435,13 @@ config.action_controller.asset_host = "assets.example.com"
435
435
  image_tag("rails.png") # => <img src="http://assets.example.com/images/rails.png" alt="Rails" />
436
436
  ```
437
437
 
438
- #### register_javascript_expansion
439
-
440
- Register one or more JavaScript files to be included when symbol is passed to javascript_include_tag. This method is typically intended to be called from plugin initialization to register JavaScript files that the plugin installed in `vendor/assets/javascripts`.
441
-
442
- ```ruby
443
- ActionView::Helpers::AssetTagHelper.register_javascript_expansion monkey: ["head", "body", "tail"]
444
-
445
- javascript_include_tag :monkey # =>
446
- <script src="/assets/head.js"></script>
447
- <script src="/assets/body.js"></script>
448
- <script src="/assets/tail.js"></script>
449
- ```
450
-
451
- #### register_stylesheet_expansion
452
-
453
- Register one or more stylesheet files to be included when symbol is passed to `stylesheet_link_tag`. This method is typically intended to be called from plugin initialization to register stylesheet files that the plugin installed in `vendor/assets/stylesheets`.
454
-
455
- ```ruby
456
- ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion monkey: ["head", "body", "tail"]
457
-
458
- stylesheet_link_tag :monkey # =>
459
- <link href="/assets/head.css" media="screen" rel="stylesheet" />
460
- <link href="/assets/body.css" media="screen" rel="stylesheet" />
461
- <link href="/assets/tail.css" media="screen" rel="stylesheet" />
462
- ```
463
-
464
438
  #### auto_discovery_link_tag
465
439
 
466
440
  Returns a link tag that browsers and feed readers can use to auto-detect an RSS or Atom feed.
467
441
 
468
442
  ```ruby
469
- auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", {title: "RSS Feed"}) # =>
470
- <link rel="alternate" type="application/rss+xml" title="RSS Feed" href="http://www.example.com/feed" />
443
+ auto_discovery_link_tag(:rss, "http://www.example.com/feed.rss", { title: "RSS Feed" }) # =>
444
+ <link rel="alternate" type="application/rss+xml" title="RSS Feed" href="http://www.example.com/feed.rss" />
471
445
  ```
472
446
 
473
447
  #### image_path
@@ -1420,22 +1394,6 @@ date_field_tag "dob"
1420
1394
 
1421
1395
  Provides functionality for working with JavaScript in your views.
1422
1396
 
1423
- #### button_to_function
1424
-
1425
- Returns a button that'll trigger a JavaScript function using the onclick handler. Examples:
1426
-
1427
- ```ruby
1428
- button_to_function "Greeting", "alert('Hello world!')"
1429
- button_to_function "Delete", "if (confirm('Really?')) do_delete()"
1430
- button_to_function "Details" do |page|
1431
- page[:details].visual_effect :toggle_slide
1432
- end
1433
- ```
1434
-
1435
- #### define_javascript_functions
1436
-
1437
- Includes the Action Pack JavaScript libraries inside a single `script` tag.
1438
-
1439
1397
  #### escape_javascript
1440
1398
 
1441
1399
  Escape carrier returns and single and double quotes for JavaScript segments.
@@ -1456,15 +1414,6 @@ alert('All is good')
1456
1414
  </script>
1457
1415
  ```
1458
1416
 
1459
- #### link_to_function
1460
-
1461
- Returns a link that will trigger a JavaScript function using the onclick handler and return false after the fact.
1462
-
1463
- ```ruby
1464
- link_to_function "Greeting", "alert('Hello world!')"
1465
- # => <a onclick="alert('Hello world!'); return false;" href="#">Greeting</a>
1466
- ```
1467
-
1468
1417
  ### NumberHelper
1469
1418
 
1470
1419
  Provides methods for converting numbers into formatted strings. Methods are provided for phone numbers, currency, percentage, precision, positional notation, and file size.
@@ -171,18 +171,18 @@ name that should be used:
171
171
 
172
172
  ```ruby
173
173
  class Product < ActiveRecord::Base
174
- self.table_name = "PRODUCT"
174
+ self.table_name = "my_products"
175
175
  end
176
176
  ```
177
177
 
178
178
  If you do so, you will have to define manually the class name that is hosting
179
- the fixtures (class_name.yml) using the `set_fixture_class` method in your test
179
+ the fixtures (my_products.yml) using the `set_fixture_class` method in your test
180
180
  definition:
181
181
 
182
182
  ```ruby
183
- class FunnyJoke < ActiveSupport::TestCase
184
- set_fixture_class funny_jokes: Joke
185
- fixtures :funny_jokes
183
+ class ProductTest < ActiveSupport::TestCase
184
+ set_fixture_class my_products: Product
185
+ fixtures :my_products
186
186
  ...
187
187
  end
188
188
  ```
@@ -876,7 +876,7 @@ For example:
876
876
  Item.transaction do
877
877
  i = Item.lock.first
878
878
  i.name = 'Jones'
879
- i.save
879
+ i.save!
880
880
  end
881
881
  ```
882
882
 
@@ -3043,53 +3043,6 @@ The method `Range#overlaps?` says whether any two given ranges have non-void int
3043
3043
 
3044
3044
  NOTE: Defined in `active_support/core_ext/range/overlaps.rb`.
3045
3045
 
3046
- Extensions to `Proc`
3047
- --------------------
3048
-
3049
- ### `bind`
3050
-
3051
- As you surely know Ruby has an `UnboundMethod` class whose instances are methods that belong to the limbo of methods without a self. The method `Module#instance_method` returns an unbound method for example:
3052
-
3053
- ```ruby
3054
- Hash.instance_method(:delete) # => #<UnboundMethod: Hash#delete>
3055
- ```
3056
-
3057
- An unbound method is not callable as is, you need to bind it first to an object with `bind`:
3058
-
3059
- ```ruby
3060
- clear = Hash.instance_method(:clear)
3061
- clear.bind({a: 1}).call # => {}
3062
- ```
3063
-
3064
- Active Support defines `Proc#bind` with an analogous purpose:
3065
-
3066
- ```ruby
3067
- Proc.new { size }.bind([]).call # => 0
3068
- ```
3069
-
3070
- As you see that's callable and bound to the argument, the return value is indeed a `Method`.
3071
-
3072
- NOTE: To do so `Proc#bind` actually creates a method under the hood. If you ever see a method with a weird name like `__bind_1256598120_237302` in a stack trace you know now where it comes from.
3073
-
3074
- Action Pack uses this trick in `rescue_from` for example, which accepts the name of a method and also a proc as callbacks for a given rescued exception. It has to call them in either case, so a bound method is returned by `handler_for_rescue`, thus simplifying the code in the caller:
3075
-
3076
- ```ruby
3077
- def handler_for_rescue(exception)
3078
- _, rescuer = Array(rescue_handlers).reverse.detect do |klass_name, handler|
3079
- ...
3080
- end
3081
-
3082
- case rescuer
3083
- when Symbol
3084
- method(rescuer)
3085
- when Proc
3086
- rescuer.bind(self)
3087
- end
3088
- end
3089
- ```
3090
-
3091
- NOTE: Defined in `active_support/core_ext/proc.rb`.
3092
-
3093
3046
  Extensions to `Date`
3094
3047
  --------------------
3095
3048