aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionmailer/CHANGELOG.md2
-rw-r--r--actionmailer/lib/action_mailer/base.rb11
-rw-r--r--actionmailer/test/base_test.rb13
-rw-r--r--actionpack/lib/abstract_controller/collector.rb4
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb13
-rw-r--r--actionpack/test/controller/flash_test.rb4
-rw-r--r--actionpack/test/controller/mime_responds_test.rb4
-rw-r--r--actionpack/test/dispatch/mime_type_test.rb14
-rw-r--r--activerecord/CHANGELOG.md6
-rw-r--r--activerecord/lib/active_record/attribute_methods/serialization.rb2
-rw-r--r--activerecord/lib/active_record/relation.rb14
-rw-r--r--activerecord/lib/active_record/store.rb2
-rw-r--r--activerecord/test/cases/relations_test.rb5
-rw-r--r--activerecord/test/cases/serialization_test.rb7
-rw-r--r--activerecord/test/cases/store_test.rb7
-rw-r--r--guides/source/4_0_release_notes.textile4
-rw-r--r--guides/source/configuring.textile2
-rw-r--r--railties/lib/rails/test_help.rb5
18 files changed, 105 insertions, 14 deletions
diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md
index 4d8f739403..96cfb43e0b 100644
--- a/actionmailer/CHANGELOG.md
+++ b/actionmailer/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* Allow to set default Action Mailer options via `config.action_mailer.default_options=` *Robert Pankowecki*
+
* Raise an `ActionView::MissingTemplate` exception when no implicit template could be found. *Damien Mathieu*
* Asynchronously send messages via the Rails Queue *Brian Cardarella*
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index f31e1e007b..150d435140 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -278,6 +278,11 @@ module ActionMailer #:nodoc:
# set something in the defaults using a proc, and then set the same thing inside of your
# mailer method, it will get over written by the mailer method.
#
+ # It is also possible to set these default options that will be used in all mailers through
+ # the <tt>default_options=</tt> configuration in <tt>config/application.rb</tt>:
+ #
+ # config.action_mailer.default_options = { from: "no-reply@example.org" }
+ #
# = Callbacks
#
# You can specify callbacks using before_filter and after_filter for configuring your messages.
@@ -421,6 +426,10 @@ module ActionMailer #:nodoc:
self.default_params = default_params.merge(value).freeze if value
default_params
end
+ # Allows to set defaults through app configuration:
+ #
+ # config.action_mailer.default_options = { from: "no-reply@example.org" }
+ alias :default_options= :default
# Receives a raw email, parses it into an email object, decodes it,
# instantiates a new mailer, and passes the email object to the mailer
@@ -786,4 +795,4 @@ module ActionMailer #:nodoc:
ActiveSupport.run_load_hooks(:action_mailer, self)
end
-end \ No newline at end of file
+end
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index 144a6bfe39..4ed332d13d 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -653,6 +653,19 @@ class BaseTest < ActiveSupport::TestCase
assert_equal "Anonymous mailer body", mailer.welcome.body.encoded.strip
end
+ test "default_from can be set" do
+ class DefaultFromMailer < ActionMailer::Base
+ default :to => 'system@test.lindsaar.net'
+ self.default_options = {from: "robert.pankowecki@gmail.com"}
+
+ def welcome
+ mail(subject: "subject", body: "hello world")
+ end
+ end
+
+ assert_equal ["robert.pankowecki@gmail.com"], DefaultFromMailer.welcome.from
+ end
+
protected
# Execute the block setting the given values and restoring old values after
diff --git a/actionpack/lib/abstract_controller/collector.rb b/actionpack/lib/abstract_controller/collector.rb
index 492329c401..09b9e7ddf0 100644
--- a/actionpack/lib/abstract_controller/collector.rb
+++ b/actionpack/lib/abstract_controller/collector.rb
@@ -16,6 +16,10 @@ module AbstractController
generate_method_for_mime(mime)
end
+ Mime::Type.register_callback do |mime|
+ generate_method_for_mime(mime) unless self.instance_methods.include?(mime.to_sym)
+ end
+
protected
def method_missing(symbol, &block)
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb
index 83cd3d1ca8..fe39c220a5 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -58,6 +58,8 @@ module Mime
cattr_reader :browser_generated_types
attr_reader :symbol
+ @register_callbacks = []
+
# A simple helper class used in parsing the accept header
class AcceptItem #:nodoc:
attr_accessor :order, :name, :q
@@ -89,6 +91,10 @@ module Mime
TRAILING_STAR_REGEXP = /(text|application)\/\*/
PARAMETER_SEPARATOR_REGEXP = /;\s*\w+="?\w+"?/
+ def register_callback(&block)
+ @register_callbacks << block
+ end
+
def lookup(string)
LOOKUP[string]
end
@@ -106,10 +112,15 @@ module Mime
def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], skip_lookup = false)
Mime.const_set(symbol.upcase, Type.new(string, symbol, mime_type_synonyms))
- SET << Mime.const_get(symbol.upcase)
+ new_mime = Mime.const_get(symbol.upcase)
+ SET << new_mime
([string] + mime_type_synonyms).each { |str| LOOKUP[str] = SET.last } unless skip_lookup
([symbol] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext.to_s] = SET.last }
+
+ @register_callbacks.each do |callback|
+ callback.call(new_mime)
+ end
end
def parse(accept_header)
diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb
index e4b34125ad..32ad48b289 100644
--- a/actionpack/test/controller/flash_test.rb
+++ b/actionpack/test/controller/flash_test.rb
@@ -210,10 +210,6 @@ class FlashIntegrationTest < ActionDispatch::IntegrationTest
SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33'
class TestController < ActionController::Base
- def dont_set_flash
- head :ok
- end
-
def set_flash
flash["that"] = "hello"
head :ok
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index bdcd5561a8..c8e036b116 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -505,7 +505,7 @@ class RespondToControllerTest < ActionController::TestCase
end
class RespondWithController < ActionController::Base
- respond_to :html, :json
+ respond_to :html, :json, :touch
respond_to :xml, :except => :using_resource_with_block
respond_to :js, :only => [ :using_resource_with_block, :using_resource, 'using_hash_resource' ]
@@ -623,12 +623,14 @@ class RespondWithControllerTest < ActionController::TestCase
super
@request.host = "www.example.com"
Mime::Type.register_alias('text/html', :iphone)
+ Mime::Type.register_alias('text/html', :touch)
Mime::Type.register('text/x-mobile', :mobile)
end
def teardown
super
Mime::Type.unregister(:iphone)
+ Mime::Type.unregister(:touch)
Mime::Type.unregister(:mobile)
end
diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb
index 9d77c3acc5..ed012093a7 100644
--- a/actionpack/test/dispatch/mime_type_test.rb
+++ b/actionpack/test/dispatch/mime_type_test.rb
@@ -118,6 +118,20 @@ class MimeTypeTest < ActiveSupport::TestCase
end
end
+ test "register callbacks" do
+ begin
+ registered_mimes = []
+ Mime::Type.register_callback do |mime|
+ registered_mimes << mime
+ end
+
+ Mime::Type.register("text/foo", :foo)
+ assert_equal registered_mimes, [Mime::FOO]
+ ensure
+ Mime::Type.unregister(:FOO)
+ end
+ end
+
test "custom type with extension aliases" do
begin
Mime::Type.register "text/foobar", :foobar, [], [:foo, "bar"]
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index ccaa2ad8f1..95967c61ee 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -24,12 +24,14 @@
dealing with a `Relation` object rather than an array:.
User.where(:age => 30).inspect
- # => <ActiveRecord::Relation [#<User ...>, #<User ...>]>
+ # => <ActiveRecord::Relation [#<User ...>, #<User ...>] ...>
User.where(:age => 30).to_a.inspect
# => [#<User ...>, #<User ...>]
- *Brian Cardarella & Jon Leighton*
+ The number of records displayed will be limited to 10.
+
+ *Brian Cardarella, Jon Leighton & Damien Mathieu*
* Add `collation` and `ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later.
Example:
diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb
index 4af4d28b74..49ab3ab808 100644
--- a/activerecord/lib/active_record/attribute_methods/serialization.rb
+++ b/activerecord/lib/active_record/attribute_methods/serialization.rb
@@ -6,7 +6,7 @@ module ActiveRecord
included do
# Returns a hash of all the attributes that have been specified for serialization as
# keys and their class restriction as values.
- class_attribute :serialized_attributes
+ class_attribute :serialized_attributes, instance_writer: false
self.serialized_attributes = {}
end
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 7725331694..dc00448dff 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -515,7 +515,19 @@ module ActiveRecord
end
def inspect
- "#<#{self.class.name} #{to_a.inspect}>"
+ text = if limit_value && limit_value <= 10
+ to_a.inspect
+ else
+ entries = limit(11).to_a
+ if entries.size > 10
+ entries.pop
+ "[#{entries.map(&:inspect).join(', ')}, ...]"
+ else
+ entries.inspect
+ end
+ end
+
+ "#<#{self.class.name} #{text}>"
end
private
diff --git a/activerecord/lib/active_record/store.rb b/activerecord/lib/active_record/store.rb
index 2af5b02fb7..d836acf18f 100644
--- a/activerecord/lib/active_record/store.rb
+++ b/activerecord/lib/active_record/store.rb
@@ -43,7 +43,7 @@ module ActiveRecord
extend ActiveSupport::Concern
included do
- class_attribute :stored_attributes
+ class_attribute :stored_attributes, instance_writer: false
self.stored_attributes = {}
end
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 7fdd42f150..bdf14e0a85 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1316,4 +1316,9 @@ class RelationTest < ActiveRecord::TestCase
relation = Post.limit(2)
assert_equal "#<ActiveRecord::Relation [#{Post.limit(2).map(&:inspect).join(', ')}]>", relation.inspect
end
+
+ test "relations limits the records in #inspect at 10" do
+ relation = Post.limit(11)
+ assert_equal "#<ActiveRecord::Relation [#{Post.limit(10).map(&:inspect).join(', ')}, ...]>", relation.inspect
+ end
end
diff --git a/activerecord/test/cases/serialization_test.rb b/activerecord/test/cases/serialization_test.rb
index a4c065e667..ce167509c1 100644
--- a/activerecord/test/cases/serialization_test.rb
+++ b/activerecord/test/cases/serialization_test.rb
@@ -51,4 +51,11 @@ class SerializationTest < ActiveRecord::TestCase
assert_equal @contact_attributes[:awesome], contact.awesome, "For #{format}"
end
end
+
+ def test_serialized_attributes_are_class_level_settings
+ assert_raise NoMethodError do
+ topic = Topic.new
+ topic.serialized_attributes = []
+ end
+ end
end
diff --git a/activerecord/test/cases/store_test.rb b/activerecord/test/cases/store_test.rb
index 7f2b8945f9..3e60b62fd5 100644
--- a/activerecord/test/cases/store_test.rb
+++ b/activerecord/test/cases/store_test.rb
@@ -120,4 +120,11 @@ class StoreTest < ActiveRecord::TestCase
test "stored attributes are returned" do
assert_equal [:color, :homepage], Admin::User.stored_attributes[:settings]
end
+
+ test "stores_attributes are class level settings" do
+ assert_raise NoMethodError do
+ @john.stored_attributes = {}
+ end
+ end
+
end
diff --git a/guides/source/4_0_release_notes.textile b/guides/source/4_0_release_notes.textile
index 8415f6f83a..b7ac11999a 100644
--- a/guides/source/4_0_release_notes.textile
+++ b/guides/source/4_0_release_notes.textile
@@ -112,6 +112,8 @@ h4(#railties_deprecations). Deprecations
h3. Action Mailer
+* Allow to set default Action Mailer options via <tt>config.action_mailer.default_options=</tt>.
+
* Raise an <tt>ActionView::MissingTemplate</tt> exception when no implicit template could be found.
* Asynchronously send messages via the Rails Queue.
@@ -360,6 +362,8 @@ User.where(:age => 30).to_a.inspect
# => [#<User ...>, #<User ...>]
</ruby>
+if more than 10 items are returned by the relation, inspect will only show the first 10 followed by ellipsis.
+
* Add <tt>:collation</tt> and <tt>:ctype</tt> support to PostgreSQL. These are available for PostgreSQL 8.4 or later.
<yaml>
diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile
index af46538bf5..cd9aab4892 100644
--- a/guides/source/configuring.textile
+++ b/guides/source/configuring.textile
@@ -424,7 +424,7 @@ There are a number of settings available on +config.action_mailer+:
* +config.action_mailer.perform_deliveries+ specifies whether mail will actually be delivered and is true by default. It can be convenient to set it to false for testing.
-* +config.action_mailer.default+ configures Action Mailer defaults. These default to:
+* +config.action_mailer.default_options+ configures Action Mailer defaults. Use to set options like `from` or `reply_to` for every mailer. These default to:
<ruby>
:mime_version => "1.0",
:charset => "UTF-8",
diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb
index 46bf3bbe48..581ceaf9ce 100644
--- a/railties/lib/rails/test_help.rb
+++ b/railties/lib/rails/test_help.rb
@@ -10,7 +10,10 @@ require 'action_dispatch/testing/integration'
# Enable turn if it is available
begin
require 'turn'
- MiniTest::Unit.use_natural_language_case_names = true
+
+ Turn.config do |c|
+ c.natural = true
+ end
rescue LoadError
end