diff options
109 files changed, 498 insertions, 2532 deletions
@@ -1,4 +1,4 @@ -source 'http://rubygems.org' +source "http://rubygems.org" gemspec @@ -32,19 +32,19 @@ end platforms :mri_19 do # TODO: Remove the conditional when ruby-debug19 supports Ruby >= 1.9.3 - gem "ruby-debug19", :require => 'ruby-debug' if RUBY_VERSION < "1.9.3" + gem "ruby-debug19", :require => "ruby-debug" if RUBY_VERSION < "1.9.3" end platforms :ruby do if ENV["RB_FSEVENT"] - gem 'rb-fsevent' + gem "rb-fsevent" end - gem 'json' - gem 'yajl-ruby' + gem "json" + gem "yajl-ruby" gem "nokogiri", ">= 1.4.4" group :test do - gem 'ruby-prof' + gem "ruby-prof" end # AR gem "sqlite3", "~> 1.3.3" @@ -75,10 +75,10 @@ end # gems that are necessary for ActiveRecord tests with Oracle database if ENV['ORACLE_ENHANCED_PATH'] || ENV['ORACLE_ENHANCED'] platforms :ruby do - gem 'ruby-oci8', ">= 2.0.4" + gem "ruby-oci8", ">= 2.0.4" end if ENV['ORACLE_ENHANCED_PATH'] - gem 'activerecord-oracle_enhanced-adapter', :path => ENV['ORACLE_ENHANCED_PATH'] + gem "activerecord-oracle_enhanced-adapter", :path => ENV['ORACLE_ENHANCED_PATH'] else gem "activerecord-oracle_enhanced-adapter", :git => "git://github.com/rsim/oracle-enhanced.git" end diff --git a/actionmailer/Rakefile b/actionmailer/Rakefile index df996acbc2..e7d8ee299d 100755 --- a/actionmailer/Rakefile +++ b/actionmailer/Rakefile @@ -1,7 +1,7 @@ #!/usr/bin/env rake require 'rake/testtask' require 'rake/packagetask' -require 'rake/gempackagetask' +require 'rubygems/package_task' desc "Default Task" task :default => [ :test ] @@ -24,7 +24,7 @@ end spec = eval(File.read('actionmailer.gemspec')) -Rake::GemPackageTask.new(spec) do |p| +Gem::PackageTask.new(spec) do |p| p.gem_spec = spec end diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index b9e682b711..9bd73dd740 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -40,12 +40,10 @@ require 'active_support/lazy_load_hooks' module ActionMailer extend ::ActiveSupport::Autoload - autoload :AdvAttrAccessor autoload :Collector autoload :Base autoload :DeliveryMethods autoload :MailHelper - autoload :OldApi autoload :TestCase autoload :TestHelper end diff --git a/actionmailer/lib/action_mailer/adv_attr_accessor.rb b/actionmailer/lib/action_mailer/adv_attr_accessor.rb deleted file mode 100644 index c1aa8021ce..0000000000 --- a/actionmailer/lib/action_mailer/adv_attr_accessor.rb +++ /dev/null @@ -1,28 +0,0 @@ -module ActionMailer - module AdvAttrAccessor #:nodoc: - def adv_attr_accessor(name, deprecation=nil) - ivar = "@#{name}" - deprecation ||= "Please pass :#{name} as hash key to mail() instead" - - class_eval <<-ACCESSORS, __FILE__, __LINE__ + 1 - def #{name}=(value) - ActiveSupport::Deprecation.warn "#{name}= is deprecated. #{deprecation}" - #{ivar} = value - end - - def #{name}(*args) - raise ArgumentError, "expected 0 or 1 parameters" unless args.length <= 1 - if args.empty? - ActiveSupport::Deprecation.warn "#{name}() is deprecated and will be removed in future versions." - #{ivar} if instance_variable_names.include?(#{ivar.inspect}) - else - ActiveSupport::Deprecation.warn "#{name}(value) is deprecated. #{deprecation}" - #{ivar} = args.first - end - end - ACCESSORS - - self.protected_instance_variables << ivar if self.respond_to?(:protected_instance_variables) - end - end -end diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index f00a0c8ae0..103da05639 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,5 +1,4 @@ require 'mail' -require 'action_mailer/tmail_compat' require 'action_mailer/collector' require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/object/blank' @@ -131,9 +130,6 @@ module ActionMailer #:nodoc: # # config.action_mailer.default_url_options = { :host => "example.com" } # - # Setting <tt>ActionMailer::Base.default_url_options</tt> directly is now deprecated, use the configuration - # option mentioned above to set the default host. - # # If you do decide to set a default <tt>:host</tt> for your mailers you want to use the # <tt>:only_path => false</tt> option when using <tt>url_for</tt>. This will ensure that absolute URLs are # generated because the <tt>url_for</tt> view helper will, by default, generate relative URLs when a @@ -297,9 +293,9 @@ module ActionMailer #:nodoc: # information and a cryptographic Message Digest 5 algorithm to hash important information) # * <tt>:enable_starttls_auto</tt> - When set to true, detects if STARTTLS is enabled in your SMTP server # and starts to use it. - # * <tt>:openssl_verify_mode</tt> - 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 + # * <tt>:openssl_verify_mode</tt> - 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,...). # # * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method. @@ -325,19 +321,6 @@ module ActionMailer #:nodoc: # * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with # <tt>delivery_method :test</tt>. Most useful for unit and functional testing. # - # * <tt>default_charset</tt> - This is now deprecated, use the +default+ method above to - # set the default +:charset+. - # - # * <tt>default_content_type</tt> - This is now deprecated, use the +default+ method above - # to set the default +:content_type+. - # - # * <tt>default_mime_version</tt> - This is now deprecated, use the +default+ method above - # to set the default +:mime_version+. - # - # * <tt>default_implicit_parts_order</tt> - This is now deprecated, use the +default+ method above - # to set the default +:parts_order+. Parts Order is used when a message is built implicitly - # (i.e. multiple parts are assembled from templates which specify the content type in their - # filenames) this variable controls how the parts are ordered. class Base < AbstractController::Base include DeliveryMethods abstract! @@ -352,7 +335,6 @@ module ActionMailer #:nodoc: self.protected_instance_variables = %w(@_action_has_layout) helper ActionMailer::MailHelper - include ActionMailer::OldApi private_class_method :new #:nodoc: diff --git a/actionmailer/lib/action_mailer/old_api.rb b/actionmailer/lib/action_mailer/old_api.rb deleted file mode 100644 index bfa9499764..0000000000 --- a/actionmailer/lib/action_mailer/old_api.rb +++ /dev/null @@ -1,255 +0,0 @@ -require 'active_support/concern' -require 'active_support/core_ext/object/try' -require 'active_support/core_ext/object/blank' - -module ActionMailer - module OldApi #:nodoc: - extend ActiveSupport::Concern - - included do - extend ActionMailer::AdvAttrAccessor - self.protected_instance_variables.concat %w(@parts @mail_was_called @headers) - - # Specify the BCC addresses for the message - adv_attr_accessor :bcc - - # Specify the CC addresses for the message. - adv_attr_accessor :cc - - # Specify the charset to use for the message. This defaults to the - # +default_charset+ specified for ActionMailer::Base. - adv_attr_accessor :charset - - # Specify the content type for the message. This defaults to <tt>text/plain</tt> - # in most cases, but can be automatically set in some situations. - adv_attr_accessor :content_type - - # Specify the from address for the message. - adv_attr_accessor :from - - # Specify the address (if different than the "from" address) to direct - # replies to this message. - adv_attr_accessor :reply_to - - # Specify the order in which parts should be sorted, based on content-type. - # This defaults to the value for the +default_implicit_parts_order+. - adv_attr_accessor :implicit_parts_order - - # Defaults to "1.0", but may be explicitly given if needed. - adv_attr_accessor :mime_version - - # The recipient addresses for the message, either as a string (for a single - # address) or an array (for multiple addresses). - adv_attr_accessor :recipients, "Please pass :to as hash key to mail() instead" - - # The date on which the message was sent. If not set (the default), the - # header will be set by the delivery agent. - adv_attr_accessor :sent_on, "Please pass :date as hash key to mail() instead" - - # Specify the subject of the message. - adv_attr_accessor :subject - - # Specify the template name to use for current message. This is the "base" - # template name, without the extension or directory, and may be used to - # have multiple mailer methods share the same template. - adv_attr_accessor :template, "Please pass :template_name or :template_path as hash key to mail() instead" - - # Define the body of the message. This is either a Hash (in which case it - # specifies the variables to pass to the template when it is rendered), - # or a string, in which case it specifies the actual text of the message. - adv_attr_accessor :body - end - - def process(method_name, *args) - initialize_defaults(method_name) - super - unless @mail_was_called - create_parts - create_mail - end - @_message - end - - # Add a part to a multipart message, with the given content-type. The - # part itself is yielded to the block so that other properties (charset, - # body, headers, etc.) can be set on it. - def part(params) - ActiveSupport::Deprecation.warn "part() is deprecated and will be removed in future versions. " << - "Please pass a block to mail() instead." - params = {:content_type => params} if String === params - - if custom_headers = params.delete(:headers) - params.merge!(custom_headers) - end - - part = Mail::Part.new(params) - - yield part if block_given? - @parts << part - end - - # Add an attachment to a multipart message. This is simply a part with the - # content-disposition set to "attachment". - def attachment(params, &block) - ActiveSupport::Deprecation.warn "attachment() is deprecated and will be removed in future versions. " << - "Please use the attachments[] API instead." - params = { :content_type => params } if String === params - - params[:content] ||= params.delete(:data) || params.delete(:body) - - if params[:filename] - params = normalize_file_hash(params) - else - params = normalize_nonfile_hash(params) - end - - part(params, &block) - end - - protected - - def normalize_nonfile_hash(params) - content_disposition = "attachment;" - - mime_type = params.delete(:mime_type) - - if content_type = params.delete(:content_type) - content_type = "#{mime_type || content_type};" - end - - params[:body] = params.delete(:data) if params[:data] - - { :content_type => content_type, - :content_disposition => content_disposition }.merge(params) - end - - def normalize_file_hash(params) - filename = File.basename(params.delete(:filename)) - content_disposition = "attachment; filename=\"#{File.basename(filename)}\"" - - mime_type = params.delete(:mime_type) - - if (content_type = params.delete(:content_type)) && (content_type !~ /filename=/) - content_type = "#{mime_type || content_type}; filename=\"#{filename}\"" - end - - params[:body] = params.delete(:data) if params[:data] - - { :content_type => content_type, - :content_disposition => content_disposition }.merge(params) - end - - def create_mail - m = @_message - - set_fields!({:subject => @subject, :to => @recipients, :from => @from, - :bcc => @bcc, :cc => @cc, :reply_to => @reply_to}, @charset) - - m.mime_version = @mime_version if @mime_version - m.date = @sent_on.to_time rescue @sent_on if @sent_on - - @headers.each { |k, v| m[k] = v } - - real_content_type, ctype_attrs = parse_content_type - main_type, sub_type = split_content_type(real_content_type) - - if @parts.size == 1 && @parts.first.parts.empty? - m.content_type([main_type, sub_type, ctype_attrs]) - m.body = @parts.first.body.encoded - else - @parts.each do |p| - m.add_part(p) - end - - m.body.set_sort_order(@implicit_parts_order) - m.body.sort_parts! - - if real_content_type =~ /multipart/ - ctype_attrs.delete "charset" - m.content_type([main_type, sub_type, ctype_attrs]) - end - end - - wrap_delivery_behavior! - m.content_transfer_encoding = '8bit' unless m.body.only_us_ascii? - - @_message - end - - # Set up the default values for the various instance variables of this - # mailer. Subclasses may override this method to provide different - # defaults. - def initialize_defaults(method_name) - @charset ||= self.class.default[:charset].try(:dup) - @content_type ||= self.class.default[:content_type].try(:dup) - @implicit_parts_order ||= self.class.default[:parts_order].try(:dup) - @mime_version ||= self.class.default[:mime_version].try(:dup) - - @cc, @bcc, @reply_to, @subject, @from, @recipients = nil, nil, nil, nil, nil, nil - - @mailer_name ||= self.class.mailer_name.dup - @template ||= method_name - @mail_was_called = false - - @parts ||= [] - @headers ||= {} - @sent_on ||= Time.now - @body ||= {} - end - - def create_parts - if String === @body - @parts.unshift create_inline_part(@body) - elsif @parts.empty? || @parts.all? { |p| p.content_disposition =~ /^attachment/ } - lookup_context.find_all(@template, [@mailer_name]).each do |template| - self.formats = template.formats - @parts << create_inline_part(render(:template => template), template.mime_type) - end - - if @parts.size > 1 - @content_type = "multipart/alternative" if @content_type !~ /^multipart/ - end - - # If this is a multipart e-mail add the mime_version if it is not - # already set. - @mime_version ||= "1.0" unless @parts.empty? - end - end - - def create_inline_part(body, mime_type=nil) - ct = mime_type || "text/plain" - main_type, sub_type = split_content_type(ct.to_s) - - Mail::Part.new( - :content_type => [main_type, sub_type, {:charset => charset}], - :content_disposition => "inline", - :body => body - ) - end - - def set_fields!(headers, charset) #:nodoc: - m = @_message - m.charset = charset - m.subject ||= headers.delete(:subject) if headers[:subject] - m.to ||= headers.delete(:to) if headers[:to] - m.from ||= headers.delete(:from) if headers[:from] - m.cc ||= headers.delete(:cc) if headers[:cc] - m.bcc ||= headers.delete(:bcc) if headers[:bcc] - m.reply_to ||= headers.delete(:reply_to) if headers[:reply_to] - end - - def split_content_type(ct) - ct.to_s.split("/") - end - - def parse_content_type - if @content_type.blank? - [ nil, {} ] - else - ctype, *attrs = @content_type.split(/;\s*/) - attrs = Hash[attrs.map { |attr| attr.split(/=/, 2) }] - [ctype, {"charset" => @charset}.merge!(attrs)] - end - end - end -end diff --git a/actionmailer/lib/action_mailer/tmail_compat.rb b/actionmailer/lib/action_mailer/tmail_compat.rb deleted file mode 100644 index 1b2cdcfb27..0000000000 --- a/actionmailer/lib/action_mailer/tmail_compat.rb +++ /dev/null @@ -1,37 +0,0 @@ -module Mail - class Message - - def set_content_type(*args) - message = 'Message#set_content_type is deprecated, please just call ' << - 'Message#content_type with the same arguments' - ActiveSupport::Deprecation.warn(message, caller[0,2]) - content_type(*args) - end - - alias :old_transfer_encoding :transfer_encoding - def transfer_encoding(value = nil) - if value - message = 'Message#transfer_encoding is deprecated, ' << - 'please call Message#content_transfer_encoding with the same arguments' - ActiveSupport::Deprecation.warn(message, caller[0,2]) - content_transfer_encoding(value) - else - old_transfer_encoding - end - end - - def transfer_encoding=(value) - message = 'Message#transfer_encoding= is deprecated, ' << - 'please call Message#content_transfer_encoding= with the same arguments' - ActiveSupport::Deprecation.warn(message, caller[0,2]) - self.content_transfer_encoding = value - end - - def original_filename - message = 'Message#original_filename is deprecated, please call Message#filename' - ActiveSupport::Deprecation.warn(message, caller[0,2]) - filename - end - - end -end diff --git a/actionmailer/test/log_subscriber_test.rb b/actionmailer/test/log_subscriber_test.rb index ba9b4d6500..5f52a1bd69 100644 --- a/actionmailer/test/log_subscriber_test.rb +++ b/actionmailer/test/log_subscriber_test.rb @@ -1,4 +1,5 @@ require "abstract_unit" +require 'mailers/base_mailer' require "active_support/log_subscriber/test_helper" require "action_mailer/log_subscriber" @@ -11,13 +12,6 @@ class AMLogSubscriberTest < ActionMailer::TestCase end class TestMailer < ActionMailer::Base - def basic - recipients "somewhere@example.com" - subject "basic" - from "basic@example.com" - body "Hello world" - end - def receive(mail) # Do nothing end @@ -28,12 +22,12 @@ class AMLogSubscriberTest < ActionMailer::TestCase end def test_deliver_is_notified - TestMailer.basic.deliver + BaseMailer.welcome.deliver wait assert_equal(1, @logger.logged(:info).size) - assert_match(/Sent mail to somewhere@example.com/, @logger.logged(:info).first) + assert_match(/Sent mail to system@test.lindsaar.net/, @logger.logged(:info).first) assert_equal(1, @logger.logged(:debug).size) - assert_match(/Hello world/, @logger.logged(:debug).first) + assert_match(/Welcome/, @logger.logged(:debug).first) end def test_receive_is_notified diff --git a/actionmailer/test/old_base/adv_attr_test.rb b/actionmailer/test/old_base/adv_attr_test.rb deleted file mode 100644 index c5a6b6d88b..0000000000 --- a/actionmailer/test/old_base/adv_attr_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'abstract_unit' -require 'action_mailer/adv_attr_accessor' - -class AdvAttrTest < ActiveSupport::TestCase - class Person - cattr_reader :protected_instance_variables - @@protected_instance_variables = [] - - extend ActionMailer::AdvAttrAccessor - adv_attr_accessor :name - end - - def setup - ActiveSupport::Deprecation.silenced = true - @person = Person.new - end - - def teardown - ActiveSupport::Deprecation.silenced = false - end - - def test_adv_attr - assert_nil @person.name - @person.name 'Bob' - assert_equal 'Bob', @person.name - end - - def test_adv_attr_writer - assert_nil @person.name - @person.name = 'Bob' - assert_equal 'Bob', @person.name - end - - def test_raise_an_error_with_multiple_args - assert_raise(ArgumentError) { @person.name('x', 'y') } - end - - def test_ivar_is_added_to_protected_instnace_variables - assert Person.protected_instance_variables.include?('@name') - end -end diff --git a/actionmailer/test/old_base/mail_render_test.rb b/actionmailer/test/old_base/mail_render_test.rb deleted file mode 100644 index 3a1d3184f4..0000000000 --- a/actionmailer/test/old_base/mail_render_test.rb +++ /dev/null @@ -1,134 +0,0 @@ -require 'abstract_unit' - -class RenderMailer < ActionMailer::Base - def inline_template - recipients 'test@localhost' - subject "using helpers" - from "tester@example.com" - - @world = "Earth" - body render(:inline => "Hello, <%= @world %>") - end - - def file_template - recipients 'test@localhost' - subject "using helpers" - from "tester@example.com" - - @recipient = 'test@localhost' - body render(:file => "templates/signed_up") - end - - def no_instance_variable - recipients 'test@localhost' - subject "No Instance Variable" - from "tester@example.com" - - silence_warnings do - body render(:inline => "Look, subject.nil? is <%= @subject.nil? %>!") - end - end - - def multipart_alternative - recipients 'test@localhost' - subject 'multipart/alternative' - from 'tester@example.com' - - build_multipart_message(:foo => "bar") - end - - private - def build_multipart_message(assigns = {}) - content_type "multipart/alternative" - - part "text/plain" do |p| - p.body = build_body_part('plain', assigns, :layout => false) - end - - part "text/html" do |p| - p.body = build_body_part('html', assigns) - end - end - - def build_body_part(content_type, assigns, options = {}) - ActiveSupport::Deprecation.silence do - render "#{template}.#{content_type}", :body => assigns - end - end -end - -class FirstMailer < ActionMailer::Base - def share - recipients 'test@localhost' - subject "using helpers" - from "tester@example.com" - end -end - -class SecondMailer < ActionMailer::Base - def share - recipients 'test@localhost' - subject "using helpers" - from "tester@example.com" - end -end - -# CHANGED: Those tests were changed because body returns an object now -# Instead of mail.body.strip, we should mail.body.to_s.strip -class RenderHelperTest < Test::Unit::TestCase - def setup - set_delivery_method :test - ActionMailer::Base.perform_deliveries = true - ActionMailer::Base.deliveries.clear - ActiveSupport::Deprecation.silenced = true - - @recipient = 'test@localhost' - end - - def teardown - ActiveSupport::Deprecation.silenced = false - restore_delivery_method - end - - def test_inline_template - mail = RenderMailer.inline_template - assert_equal "Hello, Earth", mail.body.to_s.strip - end - - def test_file_template - mail = RenderMailer.file_template - assert_equal "Hello there,\n\nMr. test@localhost", mail.body.to_s.strip - end - - def test_no_instance_variable - mail = RenderMailer.no_instance_variable.deliver - assert_equal "Look, subject.nil? is true!", mail.body.to_s.strip - end -end - -class FirstSecondHelperTest < Test::Unit::TestCase - def setup - set_delivery_method :test - ActiveSupport::Deprecation.silenced = true - ActionMailer::Base.perform_deliveries = true - ActionMailer::Base.deliveries.clear - - @recipient = 'test@localhost' - end - - def teardown - ActiveSupport::Deprecation.silenced = false - restore_delivery_method - end - - def test_ordering - mail = FirstMailer.share - assert_equal "first mail", mail.body.to_s.strip - mail = SecondMailer.share - assert_equal "second mail", mail.body.to_s.strip - mail = FirstMailer.share - assert_equal "first mail", mail.body.to_s.strip - mail = SecondMailer.share - assert_equal "second mail", mail.body.to_s.strip - end -end diff --git a/actionmailer/test/old_base/mail_service_test.rb b/actionmailer/test/old_base/mail_service_test.rb deleted file mode 100644 index 0b5b0b2da3..0000000000 --- a/actionmailer/test/old_base/mail_service_test.rb +++ /dev/null @@ -1,1097 +0,0 @@ -# encoding: utf-8 -require 'abstract_unit' - -class FunkyPathMailer < ActionMailer::Base - self.view_paths = "#{File.dirname(__FILE__)}/../fixtures/path.with.dots" - - def multipart_with_template_path_with_dots(recipient) - recipients recipient - subject "This path has dots" - from "Chad Fowler <chad@chadfowler.com>" - attachment :content_type => "text/plain", - :data => "dots dots dots..." - end -end - -class TestMailer < ActionMailer::Base - def signed_up(recipient) - recipients recipient - subject "[Signed up] Welcome #{recipient}" - from "system@loudthinking.com" - - @recipient = recipient - end - - def cancelled_account(recipient) - recipients recipient - subject "[Cancelled] Goodbye #{recipient}" - from "system@loudthinking.com" - sent_on Time.local(2004, 12, 12) - body "Goodbye, Mr. #{recipient}" - end - - def from_with_name - from "System <system@loudthinking.com>" - recipients "root@loudthinking.com" - body "Nothing to see here." - end - - def from_without_name - from "system@loudthinking.com" - recipients "root@loudthinking.com" - body "Nothing to see here." - end - - def cc_bcc(recipient) - recipients recipient - subject "testing bcc/cc" - from "system@loudthinking.com" - sent_on Time.local(2004, 12, 12) - cc "nobody@loudthinking.com" - bcc "root@loudthinking.com" - - body "Nothing to see here." - end - - def different_reply_to(recipient) - recipients recipient - subject "testing reply_to" - from "system@loudthinking.com" - sent_on Time.local(2008, 5, 23) - reply_to "atraver@gmail.com" - - body "Nothing to see here." - end - - def iso_charset(recipient) - recipients recipient - subject "testing isø charsets" - from "system@loudthinking.com" - sent_on Time.local(2004, 12, 12) - cc "nobody@loudthinking.com" - bcc "root@loudthinking.com" - charset "iso-8859-1" - - body "Nothing to see here." - end - - def unencoded_subject(recipient) - recipients recipient - subject "testing unencoded subject" - from "system@loudthinking.com" - sent_on Time.local(2004, 12, 12) - cc "nobody@loudthinking.com" - bcc "root@loudthinking.com" - - body "Nothing to see here." - end - - def extended_headers(recipient) - recipients recipient - subject "testing extended headers" - from "Grytøyr <stian1@example.net>" - sent_on Time.local(2004, 12, 12) - cc "Grytøyr <stian2@example.net>" - bcc "Grytøyr <stian3@example.net>" - charset "iso-8859-1" - - body "Nothing to see here." - end - - def utf8_body(recipient) - recipients recipient - subject "testing utf-8 body" - from "Foo áëô îü <extended@example.net>" - sent_on Time.local(2004, 12, 12) - cc "Foo áëô îü <extended@example.net>" - bcc "Foo áëô îü <extended@example.net>" - charset "UTF-8" - - body "åœö blah" - end - - def multipart_with_mime_version(recipient) - recipients recipient - subject "multipart with mime_version" - from "test@example.com" - sent_on Time.local(2004, 12, 12) - mime_version "1.1" - content_type "multipart/alternative" - - part "text/plain" do |p| - p.body = render(:text => "blah") - end - - part "text/html" do |p| - p.body = render(:inline => "<%= content_tag(:b, 'blah') %>") - end - end - - def multipart_with_utf8_subject(recipient) - recipients recipient - subject "Foo áëô îü" - from "test@example.com" - charset "UTF-8" - - part "text/plain" do |p| - p.body = "blah" - end - - part "text/html" do |p| - p.body = "<b>blah</b>" - end - end - - def explicitly_multipart_example(recipient, ct=nil) - recipients recipient - subject "multipart example" - from "test@example.com" - sent_on Time.local(2004, 12, 12) - content_type ct if ct - - part "text/html" do |p| - p.charset = "iso-8859-1" - p.body = "blah" - end - - attachment :content_type => "image/jpeg", :filename => File.join(File.dirname(__FILE__), "fixtures", "attachments", "foo.jpg"), - :data => "123456789" - - body "plain text default" - end - - def implicitly_multipart_example(recipient, cs = nil, order = nil) - recipients recipient - subject "multipart example" - from "test@example.com" - sent_on Time.local(2004, 12, 12) - - @charset = cs if cs - @recipient = recipient - @implicit_parts_order = order if order - end - - def implicitly_multipart_with_utf8 - recipients "no.one@nowhere.test" - subject "Foo áëô îü" - from "some.one@somewhere.test" - template "implicitly_multipart_example" - - @recipient = "no.one@nowhere.test" - end - - def html_mail(recipient) - recipients recipient - subject "html mail" - from "test@example.com" - content_type "text/html" - - body "<em>Emphasize</em> <strong>this</strong>" - end - - def html_mail_with_underscores(recipient) - subject "html mail with underscores" - body %{<a href="http://google.com" target="_blank">_Google</a>} - end - - def custom_template(recipient) - recipients recipient - subject "[Signed up] Welcome #{recipient}" - from "system@loudthinking.com" - sent_on Time.local(2004, 12, 12) - template "signed_up" - - @recipient = recipient - end - - def custom_templating_extension(recipient) - recipients recipient - subject "[Signed up] Welcome #{recipient}" - from "system@loudthinking.com" - sent_on Time.local(2004, 12, 12) - - @recipient = recipient - end - - def various_newlines(recipient) - recipients recipient - subject "various newlines" - from "test@example.com" - - body "line #1\nline #2\rline #3\r\nline #4\r\r" + - "line #5\n\nline#6\r\n\r\nline #7" - end - - def various_newlines_multipart(recipient) - recipients recipient - subject "various newlines multipart" - from "test@example.com" - content_type "multipart/alternative" - - part :content_type => "text/plain", :body => "line #1\nline #2\rline #3\r\nline #4\r\r" - part :content_type => "text/html", :body => "<p>line #1</p>\n<p>line #2</p>\r<p>line #3</p>\r\n<p>line #4</p>\r\r" - end - - def nested_multipart(recipient) - recipients recipient - subject "nested multipart" - from "test@example.com" - content_type "multipart/mixed" - - part :content_type => "multipart/alternative", :content_disposition => "inline", "foo" => "bar" do |p| - p.part :content_type => "text/plain", :body => "test text\nline #2" - p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2" - end - - attachment :content_type => "application/octet-stream", :filename => "test.txt", :data => "test abcdefghijklmnopqstuvwxyz" - end - - def nested_multipart_with_body(recipient) - recipients recipient - subject "nested multipart with body" - from "test@example.com" - content_type "multipart/mixed" - - part :content_type => "multipart/alternative", :content_disposition => "inline", :body => "Nothing to see here." do |p| - p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>" - end - end - - def attachment_with_custom_header(recipient) - recipients recipient - subject "custom header in attachment" - from "test@example.com" - content_type "multipart/related" - part :content_type => "text/html", :body => 'yo' - attachment :content_type => "image/jpeg", :filename => File.join(File.dirname(__FILE__), "fixtures", "attachments", "test.jpg"), :data => "i am not a real picture", 'Content-ID' => '<test@test.com>' - end - - def unnamed_attachment(recipient) - recipients recipient - subject "nested multipart" - from "test@example.com" - content_type "multipart/mixed" - part :content_type => "text/plain", :body => "hullo" - attachment :content_type => "application/octet-stream", :data => "test abcdefghijklmnopqstuvwxyz" - end - - def headers_with_nonalpha_chars(recipient) - recipients recipient - subject "nonalpha chars" - from "One: Two <test@example.com>" - cc "Three: Four <test@example.com>" - bcc "Five: Six <test@example.com>" - body "testing" - end - - def custom_content_type_attributes - recipients "no.one@nowhere.test" - subject "custom content types" - from "some.one@somewhere.test" - content_type "text/plain; format=flowed" - body "testing" - end - - def return_path - recipients "no.one@nowhere.test" - subject "return path test" - from "some.one@somewhere.test" - headers["return-path"] = "another@somewhere.test" - body "testing" - end - - def subject_with_i18n(recipient) - recipients recipient - from "system@loudthinking.com" - body "testing" - end - - class << self - attr_accessor :received_body - end - - def receive(mail) - self.class.received_body = mail.body - end -end - -class ActionMailerTest < Test::Unit::TestCase - - def encode( text, charset="UTF-8" ) - Mail::Encodings.q_value_encode( text, charset ) - end - - def new_mail( charset="UTF-8" ) - mail = Mail.new - mail.charset = charset - mail.mime_version = "1.0" - mail - end - - def setup - set_delivery_method :test - ActionMailer::Base.perform_deliveries = true - ActionMailer::Base.raise_delivery_errors = true - ActionMailer::Base.deliveries.clear - ActiveSupport::Deprecation.silenced = true - - @recipient = 'test@localhost' - - TestMailer.delivery_method = :test - end - - def teardown - ActiveSupport::Deprecation.silenced = false - restore_delivery_method - end - - def test_nested_parts - created = nil - assert_nothing_raised { created = TestMailer.nested_multipart(@recipient)} - assert_equal 2, created.parts.size - assert_equal 2, created.parts.first.parts.size - - assert_equal "multipart/mixed", created.mime_type - assert_equal "multipart/alternative", created.parts[0].mime_type - assert_equal "bar", created.parts[0].header['foo'].to_s - assert_not_nil created.parts[0].charset - assert_equal "text/plain", created.parts[0].parts[0].mime_type - assert_equal "text/html", created.parts[0].parts[1].mime_type - assert_equal "application/octet-stream", created.parts[1].mime_type - - end - - def test_nested_parts_with_body - created = nil - TestMailer.nested_multipart_with_body(@recipient) - assert_nothing_raised { created = TestMailer.nested_multipart_with_body(@recipient)} - - assert_equal 1,created.parts.size - assert_equal 2,created.parts.first.parts.size - - assert_equal "multipart/mixed", created.mime_type - assert_equal "multipart/alternative", created.parts.first.mime_type - assert_equal "text/plain", created.parts.first.parts.first.mime_type - assert_equal "Nothing to see here.", created.parts.first.parts.first.body.to_s - assert_equal "text/html", created.parts.first.parts.second.mime_type - assert_equal "<b>test</b> HTML<br/>", created.parts.first.parts.second.body.to_s - end - - def test_attachment_with_custom_header - created = nil - assert_nothing_raised { created = TestMailer.attachment_with_custom_header(@recipient) } - assert created.parts.any? { |p| p.header['content-id'].to_s == "<test@test.com>" } - end - - def test_signed_up - TestMailer.delivery_method = :test - - Time.stubs(:now => Time.now) - - expected = new_mail - expected.to = @recipient - expected.subject = "[Signed up] Welcome #{@recipient}" - expected.body = "Hello there,\n\nMr. #{@recipient}" - expected.from = "system@loudthinking.com" - expected.date = Time.now - - created = nil - assert_nothing_raised { created = TestMailer.signed_up(@recipient) } - assert_not_nil created - - expected.message_id = '<123@456>' - created.message_id = '<123@456>' - - assert_equal expected.encoded, created.encoded - - assert_nothing_raised { TestMailer.signed_up(@recipient).deliver } - - delivered = ActionMailer::Base.deliveries.first - assert_not_nil delivered - - expected.message_id = '<123@456>' - delivered.message_id = '<123@456>' - - assert_equal expected.encoded, delivered.encoded - end - - def test_custom_template - expected = new_mail - expected.to = @recipient - expected.subject = "[Signed up] Welcome #{@recipient}" - expected.body = "Hello there,\n\nMr. #{@recipient}" - expected.from = "system@loudthinking.com" - expected.date = Time.local(2004, 12, 12) - - created = nil - assert_nothing_raised { created = TestMailer.custom_template(@recipient) } - assert_not_nil created - expected.message_id = '<123@456>' - created.message_id = '<123@456>' - assert_equal expected.encoded, created.encoded - end - - def test_custom_templating_extension - assert ActionView::Template.template_handler_extensions.include?("haml"), "haml extension was not registered" - - # N.b., custom_templating_extension.text.plain.haml is expected to be in fixtures/test_mailer directory - expected = new_mail - expected.to = @recipient - expected.subject = "[Signed up] Welcome #{@recipient}" - expected.body = "Hello there, \n\nMr. #{@recipient}" - expected.from = "system@loudthinking.com" - expected.date = Time.local(2004, 12, 12) - - # Now that the template is registered, there should be one part. The text/plain part. - created = nil - assert_nothing_raised { created = TestMailer.custom_templating_extension(@recipient) } - assert_not_nil created - assert_equal 2, created.parts.length - assert_equal 'text/plain', created.parts[0].mime_type - assert_equal 'text/html', created.parts[1].mime_type - end - - def test_cancelled_account - expected = new_mail - expected.to = @recipient - expected.subject = "[Cancelled] Goodbye #{@recipient}" - expected.body = "Goodbye, Mr. #{@recipient}" - expected.from = "system@loudthinking.com" - expected.date = Time.local(2004, 12, 12) - - created = nil - assert_nothing_raised { created = TestMailer.cancelled_account(@recipient) } - assert_not_nil created - expected.message_id = '<123@456>' - created.message_id = '<123@456>' - assert_equal expected.encoded, created.encoded - - assert_nothing_raised { TestMailer.cancelled_account(@recipient).deliver } - assert_not_nil ActionMailer::Base.deliveries.first - delivered = ActionMailer::Base.deliveries.first - expected.message_id = '<123@456>' - delivered.message_id = '<123@456>' - - assert_equal expected.encoded, delivered.encoded - end - - def test_cc_bcc - expected = new_mail - expected.to = @recipient - expected.subject = "testing bcc/cc" - expected.body = "Nothing to see here." - expected.from = "system@loudthinking.com" - expected.cc = "nobody@loudthinking.com" - expected.bcc = "root@loudthinking.com" - expected.date = Time.local 2004, 12, 12 - - created = nil - assert_nothing_raised do - created = TestMailer.cc_bcc @recipient - end - assert_not_nil created - expected.message_id = '<123@456>' - created.message_id = '<123@456>' - assert_equal expected.encoded, created.encoded - - assert_nothing_raised do - TestMailer.cc_bcc(@recipient).deliver - end - - assert_not_nil ActionMailer::Base.deliveries.first - delivered = ActionMailer::Base.deliveries.first - expected.message_id = '<123@456>' - delivered.message_id = '<123@456>' - - assert_equal expected.encoded, delivered.encoded - end - - def test_from_without_name_for_smtp - TestMailer.delivery_method = :smtp - TestMailer.from_without_name.deliver - - mail = MockSMTP.deliveries.first - assert_not_nil mail - mail, from, to = mail - - assert_equal 'system@loudthinking.com', from.to_s - end - - def test_from_with_name_for_smtp - TestMailer.delivery_method = :smtp - TestMailer.from_with_name.deliver - - mail = MockSMTP.deliveries.first - assert_not_nil mail - mail, from, to = mail - - assert_equal 'system@loudthinking.com', from - end - - def test_reply_to - TestMailer.delivery_method = :test - - expected = new_mail - - expected.to = @recipient - expected.subject = "testing reply_to" - expected.body = "Nothing to see here." - expected.from = "system@loudthinking.com" - expected.reply_to = "atraver@gmail.com" - expected.date = Time.local 2008, 5, 23 - - created = nil - assert_nothing_raised do - created = TestMailer.different_reply_to @recipient - end - assert_not_nil created - - expected.message_id = '<123@456>' - created.message_id = '<123@456>' - - assert_equal expected.encoded, created.encoded - - assert_nothing_raised do - TestMailer.different_reply_to(@recipient).deliver - end - - delivered = ActionMailer::Base.deliveries.first - assert_not_nil delivered - - expected.message_id = '<123@456>' - delivered.message_id = '<123@456>' - - assert_equal expected.encoded, delivered.encoded - end - - def test_iso_charset - TestMailer.delivery_method = :test - expected = new_mail( "iso-8859-1" ) - expected.to = @recipient - expected.subject = encode "testing isø charsets", "iso-8859-1" - expected.body = "Nothing to see here." - expected.from = "system@loudthinking.com" - expected.cc = "nobody@loudthinking.com" - expected.bcc = "root@loudthinking.com" - expected.date = Time.local 2004, 12, 12 - - created = nil - assert_nothing_raised do - created = TestMailer.iso_charset @recipient - end - assert_not_nil created - - expected.message_id = '<123@456>' - created.message_id = '<123@456>' - - assert_equal expected.encoded, created.encoded - - assert_nothing_raised do - TestMailer.iso_charset(@recipient).deliver - end - - delivered = ActionMailer::Base.deliveries.first - assert_not_nil delivered - - expected.message_id = '<123@456>' - delivered.message_id = '<123@456>' - - assert_equal expected.encoded, delivered.encoded - end - - def test_unencoded_subject - TestMailer.delivery_method = :test - expected = new_mail - expected.to = @recipient - expected.subject = "testing unencoded subject" - expected.body = "Nothing to see here." - expected.from = "system@loudthinking.com" - expected.cc = "nobody@loudthinking.com" - expected.bcc = "root@loudthinking.com" - expected.date = Time.local 2004, 12, 12 - - created = nil - assert_nothing_raised do - created = TestMailer.unencoded_subject @recipient - end - assert_not_nil created - - expected.message_id = '<123@456>' - created.message_id = '<123@456>' - - assert_equal expected.encoded, created.encoded - - assert_nothing_raised do - TestMailer.unencoded_subject(@recipient).deliver - end - - delivered = ActionMailer::Base.deliveries.first - assert_not_nil delivered - - expected.message_id = '<123@456>' - delivered.message_id = '<123@456>' - - assert_equal expected.encoded, delivered.encoded - end - - def test_deliveries_array - assert_not_nil ActionMailer::Base.deliveries - assert_equal 0, ActionMailer::Base.deliveries.size - TestMailer.signed_up(@recipient).deliver - assert_equal 1, ActionMailer::Base.deliveries.size - assert_not_nil ActionMailer::Base.deliveries.first - end - - def test_perform_deliveries_flag - ActionMailer::Base.perform_deliveries = false - TestMailer.signed_up(@recipient).deliver - assert_equal 0, ActionMailer::Base.deliveries.size - ActionMailer::Base.perform_deliveries = true - TestMailer.signed_up(@recipient).deliver - assert_equal 1, ActionMailer::Base.deliveries.size - end - - def test_doesnt_raise_errors_when_raise_delivery_errors_is_false - ActionMailer::Base.raise_delivery_errors = false - Mail::TestMailer.any_instance.expects(:deliver!).raises(Exception) - assert_nothing_raised { TestMailer.signed_up(@recipient).deliver } - end - - def test_performs_delivery_via_sendmail - IO.expects(:popen).once.with('/usr/sbin/sendmail -i -t -f "system@loudthinking.com" test@localhost', 'w+') - TestMailer.delivery_method = :sendmail - TestMailer.signed_up(@recipient).deliver - end - - def test_unquote_quoted_printable_subject - msg = <<EOF -From: me@example.com -Subject: =?UTF-8?Q?testing_testing_=D6=A4?= -Content-Type: text/plain; charset=iso-8859-1 - -The body -EOF - mail = Mail.new(msg) - assert_equal "testing testing \326\244", mail.subject - assert_equal "Subject: =?UTF-8?Q?testing_testing_=D6=A4?=\r\n", mail[:subject].encoded - end - - def test_unquote_7bit_subject - msg = <<EOF -From: me@example.com -Subject: this == working? -Content-Type: text/plain; charset=iso-8859-1 - -The body -EOF - mail = Mail.new(msg) - assert_equal "this == working?", mail.subject - assert_equal "Subject: this == working?\r\n", mail[:subject].encoded - end - - def test_unquote_7bit_body - msg = <<EOF -From: me@example.com -Subject: subject -Content-Type: text/plain; charset=iso-8859-1 -Content-Transfer-Encoding: 7bit - -The=3Dbody -EOF - mail = Mail.new(msg) - assert_equal "The=3Dbody", mail.body.to_s.strip - assert_equal "The=3Dbody", mail.body.encoded.strip - end - - def test_unquote_quoted_printable_body - msg = <<EOF -From: me@example.com -Subject: subject -Content-Type: text/plain; charset=iso-8859-1 -Content-Transfer-Encoding: quoted-printable - -The=3Dbody -EOF - mail = Mail.new(msg) - assert_equal "The=body", mail.body.to_s.strip - assert_equal "The=3Dbody=", mail.body.encoded.strip - end - - def test_unquote_base64_body - msg = <<EOF -From: me@example.com -Subject: subject -Content-Type: text/plain; charset=iso-8859-1 -Content-Transfer-Encoding: base64 - -VGhlIGJvZHk= -EOF - mail = Mail.new(msg) - assert_equal "The body", mail.body.to_s.strip - assert_equal "VGhlIGJvZHk=", mail.body.encoded.strip - end - - def test_extended_headers - @recipient = "Grytøyr <test@localhost>" - - expected = new_mail "iso-8859-1" - expected.to = @recipient - expected.subject = "testing extended headers" - expected.body = "Nothing to see here." - expected.from = "Grytøyr <stian1@example.net>" - expected.cc = "Grytøyr <stian2@example.net>" - expected.bcc = "Grytøyr <stian3@example.net>" - expected.date = Time.local 2004, 12, 12 - - created = nil - assert_nothing_raised do - created = TestMailer.extended_headers @recipient - end - - assert_not_nil created - expected.message_id = '<123@456>' - created.message_id = '<123@456>' - - assert_equal expected.encoded, created.encoded - - assert_nothing_raised do - TestMailer.extended_headers(@recipient).deliver - end - - delivered = ActionMailer::Base.deliveries.first - assert_not_nil delivered - - expected.message_id = '<123@456>' - delivered.message_id = '<123@456>' - - assert_equal expected.encoded, delivered.encoded - end - - def test_utf8_body_is_not_quoted - @recipient = "Foo áëô îü <extended@example.net>" - expected = new_mail "UTF-8" - expected.to = @recipient - expected.subject = "testing UTF-8 body" - expected.body = "åœö blah" - expected.from = @recipient - expected.cc = @recipient - expected.bcc = @recipient - expected.date = Time.local 2004, 12, 12 - - created = TestMailer.utf8_body @recipient - assert_match(/åœö blah/, created.decoded) - end - - def test_multiple_utf8_recipients - @recipient = ["\"Foo áëô îü\" <extended@example.net>", "\"Example Recipient\" <me@example.com>"] - expected = new_mail "UTF-8" - expected.to = @recipient - expected.subject = "testing UTF-8 body" - expected.body = "åœö blah" - expected.from = @recipient.first - expected.cc = @recipient - expected.bcc = @recipient - expected.date = Time.local 2004, 12, 12 - - created = TestMailer.utf8_body @recipient - from_regexp = Regexp.escape('From: Foo =?UTF-8?B?w6HDq8O0?= =?UTF-8?B?IMOuw7w=?=') - assert_match(/#{from_regexp}/m, created.encoded) - - to_regexp = Regexp.escape("To: =?UTF-8?B?Rm9vIMOhw6vDtCDDrsO8?= <extended@example.net>") - assert_match(/#{to_regexp}/m, created.encoded) - end - - def test_receive_decodes_base64_encoded_mail - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email") - TestMailer.receive(fixture) - assert_match(/Jamis/, TestMailer.received_body.to_s) - end - - def test_receive_attachments - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email2") - mail = Mail.new(fixture) - attachment = mail.attachments.last - assert_equal "smime.p7s", attachment.filename - assert_equal "application/pkcs7-signature", mail.parts.last.mime_type - end - - def test_decode_attachment_without_charset - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email3") - mail = Mail.new(fixture) - attachment = mail.attachments.last - assert_equal 1026, attachment.read.length - end - - def test_attachment_using_content_location - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email12") - mail = Mail.new(fixture) - assert_equal 1, mail.attachments.length - assert_equal "Photo25.jpg", mail.attachments.first.filename - end - - def test_attachment_with_text_type - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email13") - mail = Mail.new(fixture) - assert mail.has_attachments? - assert_equal 1, mail.attachments.length - assert_equal "hello.rb", mail.attachments.first.filename - end - - def test_decode_part_without_content_type - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email4") - mail = Mail.new(fixture) - assert_nothing_raised { mail.body } - end - - def test_decode_message_without_content_type - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email5") - mail = Mail.new(fixture) - assert_nothing_raised { mail.body } - end - - def test_decode_message_with_incorrect_charset - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email6") - mail = Mail.new(fixture) - assert_nothing_raised { mail.body } - end - - def test_multipart_with_mime_version - mail = TestMailer.multipart_with_mime_version(@recipient) - assert_equal "1.1", mail.mime_version - end - - def test_multipart_with_utf8_subject - mail = TestMailer.multipart_with_utf8_subject(@recipient) - regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC?=') - assert_match(/#{regex}/, mail.encoded) - string = "Foo áëô îü" - assert_match(string, mail.subject) - end - - def test_implicitly_multipart_with_utf8 - mail = TestMailer.implicitly_multipart_with_utf8 - regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC?=') - assert_match(/#{regex}/, mail.encoded) - string = "Foo áëô îü" - assert_match(string, mail.subject) - end - - def test_explicitly_multipart_messages - mail = TestMailer.explicitly_multipart_example(@recipient) - assert_equal 3, mail.parts.length - assert_equal 'multipart/mixed', mail.mime_type - assert_equal "text/plain", mail.parts[0].mime_type - - assert_equal "text/html", mail.parts[1].mime_type - assert_equal "iso-8859-1", mail.parts[1].charset - - assert_equal "image/jpeg", mail.parts[2].mime_type - - assert_equal "attachment", mail.parts[2][:content_disposition].disposition_type - assert_equal "foo.jpg", mail.parts[2][:content_disposition].filename - assert_equal "foo.jpg", mail.parts[2][:content_type].filename - assert_nil mail.parts[2].charset - end - - def test_explicitly_multipart_with_content_type - mail = TestMailer.explicitly_multipart_example(@recipient, "multipart/alternative") - assert_equal 3, mail.parts.length - assert_equal "multipart/alternative", mail.mime_type - end - - def test_explicitly_multipart_with_invalid_content_type - mail = TestMailer.explicitly_multipart_example(@recipient, "text/xml") - assert_equal 3, mail.parts.length - assert_equal 'multipart/mixed', mail.mime_type - end - - def test_implicitly_multipart_messages - assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered" - - mail = TestMailer.implicitly_multipart_example(@recipient) - assert_equal 3, mail.parts.length - assert_equal "1.0", mail.mime_version.to_s - assert_equal "multipart/alternative", mail.mime_type - assert_equal "text/plain", mail.parts[0].mime_type - assert_equal "UTF-8", mail.parts[0].charset - assert_equal "text/html", mail.parts[1].mime_type - assert_equal "UTF-8", mail.parts[1].charset - assert_equal "application/x-yaml", mail.parts[2].mime_type - assert_equal "UTF-8", mail.parts[2].charset - end - - def test_implicitly_multipart_messages_with_custom_order - assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered" - - mail = TestMailer.implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"]) - assert_equal 3, mail.parts.length - assert_equal "application/x-yaml", mail.parts[0].mime_type - assert_equal "text/plain", mail.parts[1].mime_type - assert_equal "text/html", mail.parts[2].mime_type - end - - def test_implicitly_multipart_messages_with_charset - mail = TestMailer.implicitly_multipart_example(@recipient, 'iso-8859-1') - - assert_equal "multipart/alternative", mail.header['content-type'].content_type - - assert_equal 'iso-8859-1', mail.parts[0].content_type_parameters[:charset] - assert_equal 'iso-8859-1', mail.parts[1].content_type_parameters[:charset] - assert_equal 'iso-8859-1', mail.parts[2].content_type_parameters[:charset] - end - - def test_html_mail - mail = TestMailer.html_mail(@recipient) - assert_equal "text/html", mail.mime_type - end - - def test_html_mail_with_underscores - mail = TestMailer.html_mail_with_underscores(@recipient) - assert_equal %{<a href="http://google.com" target="_blank">_Google</a>}, mail.body.to_s - end - - def test_various_newlines - mail = TestMailer.various_newlines(@recipient) - assert_equal("line #1\nline #2\nline #3\nline #4\n\n" + - "line #5\n\nline#6\n\nline #7", mail.body.to_s) - end - - def test_various_newlines_multipart - mail = TestMailer.various_newlines_multipart(@recipient) - assert_equal "line #1\nline #2\nline #3\nline #4\n\n", mail.parts[0].body.to_s - assert_equal "<p>line #1</p>\n<p>line #2</p>\n<p>line #3</p>\n<p>line #4</p>\n\n", mail.parts[1].body.to_s - assert_equal "line #1\r\nline #2\r\nline #3\r\nline #4\r\n\r\n", mail.parts[0].body.encoded - assert_equal "<p>line #1</p>\r\n<p>line #2</p>\r\n<p>line #3</p>\r\n<p>line #4</p>\r\n\r\n", mail.parts[1].body.encoded - end - - def test_headers_removed_on_smtp_delivery - TestMailer.delivery_method = :smtp - TestMailer.cc_bcc(@recipient).deliver - assert MockSMTP.deliveries[0][2].include?("root@loudthinking.com") - assert MockSMTP.deliveries[0][2].include?("nobody@loudthinking.com") - assert MockSMTP.deliveries[0][2].include?(@recipient) - assert_match %r{^Cc: nobody@loudthinking.com}, MockSMTP.deliveries[0][0] - assert_match %r{^To: #{@recipient}}, MockSMTP.deliveries[0][0] - assert_no_match %r{^Bcc: root@loudthinking.com}, MockSMTP.deliveries[0][0] - end - - def test_file_delivery_should_create_a_file - TestMailer.delivery_method = :file - tmp_location = TestMailer.file_settings[:location] - - result = TestMailer.cc_bcc(@recipient).deliver - assert File.exists?(tmp_location) - assert File.directory?(tmp_location) - assert File.exists?(File.join(tmp_location, @recipient)) - assert File.exists?(File.join(tmp_location, 'nobody@loudthinking.com')) - assert File.exists?(File.join(tmp_location, 'root@loudthinking.com')) - end - - def test_recursive_multipart_processing - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email7") - mail = Mail.new(fixture) - assert_equal(2, mail.parts.length) - assert_equal(4, mail.parts.first.parts.length) - assert_equal("This is the first part.", mail.parts.first.parts.first.body.to_s) - assert_equal("test.rb", mail.parts.first.parts.second.filename) - assert_equal("flowed", mail.parts.first.parts.fourth.content_type_parameters[:format]) - assert_equal('smime.p7s', mail.parts.second.filename) - end - - def test_decode_encoded_attachment_filename - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email8") - mail = Mail.new(fixture) - attachment = mail.attachments.last - - expected = "01 Quien Te Dij\212at. Pitbull.mp3" - - if expected.respond_to?(:force_encoding) - result = attachment.filename.dup - expected.force_encoding(Encoding::ASCII_8BIT) - result.force_encoding(Encoding::ASCII_8BIT) - assert_equal expected, result - else - assert_equal expected, attachment.filename - end - end - - def test_decode_message_with_unknown_charset - fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email10") - mail = Mail.new(fixture) - assert_nothing_raised { mail.body } - end - - def test_empty_header_values_omitted - result = TestMailer.unnamed_attachment(@recipient).encoded - assert_match %r{Content-Type: application/octet-stream}, result - assert_match %r{Content-Disposition: attachment}, result - end - - def test_headers_with_nonalpha_chars - mail = TestMailer.headers_with_nonalpha_chars(@recipient) - assert !mail.from_addrs.empty? - assert !mail.cc_addrs.empty? - assert !mail.bcc_addrs.empty? - assert_match(/:/, mail[:from].decoded) - assert_match(/:/, mail[:cc].decoded) - assert_match(/:/, mail[:bcc].decoded) - end - - def test_with_mail_object_deliver - TestMailer.delivery_method = :test - mail = TestMailer.headers_with_nonalpha_chars(@recipient) - assert_nothing_raised { mail.deliver } - assert_equal 1, TestMailer.deliveries.length - end - - def test_multipart_with_template_path_with_dots - mail = FunkyPathMailer.multipart_with_template_path_with_dots(@recipient) - assert_equal 2, mail.parts.length - assert_equal "text/plain", mail.parts[0].mime_type - assert_equal "text/html", mail.parts[1].mime_type - assert_equal "UTF-8", mail.parts[1].charset - end - - def test_custom_content_type_attributes - mail = TestMailer.custom_content_type_attributes - assert_match %r{format=flowed}, mail.content_type - assert_match %r{charset=UTF-8}, mail.content_type - end - - def test_return_path_with_create - mail = TestMailer.return_path - assert_equal "another@somewhere.test", mail.return_path - end - - def test_return_path_with_deliver - TestMailer.delivery_method = :smtp - TestMailer.return_path.deliver - assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0] - assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s - end - - def test_starttls_is_enabled_if_supported - TestMailer.smtp_settings.merge!(:enable_starttls_auto => true) - MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(true) - MockSMTP.any_instance.expects(:enable_starttls_auto) - TestMailer.delivery_method = :smtp - TestMailer.signed_up(@recipient).deliver - end - - def test_starttls_is_disabled_if_not_supported - TestMailer.smtp_settings.merge!(:enable_starttls_auto => true) - MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(false) - MockSMTP.any_instance.expects(:enable_starttls_auto).never - TestMailer.delivery_method = :smtp - TestMailer.signed_up(@recipient).deliver - end - - def test_starttls_is_not_enabled - TestMailer.smtp_settings.merge!(:enable_starttls_auto => false) - MockSMTP.any_instance.expects(:respond_to?).never - TestMailer.delivery_method = :smtp - TestMailer.signed_up(@recipient).deliver - ensure - TestMailer.smtp_settings.merge!(:enable_starttls_auto => true) - end -end diff --git a/actionmailer/test/old_base/tmail_compat_test.rb b/actionmailer/test/old_base/tmail_compat_test.rb deleted file mode 100644 index 51558c2bfa..0000000000 --- a/actionmailer/test/old_base/tmail_compat_test.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'abstract_unit' - -class TmailCompatTest < ActiveSupport::TestCase - def setup - @silence = ActiveSupport::Deprecation.silenced - ActiveSupport::Deprecation.silenced = false - end - - def teardown - ActiveSupport::Deprecation.silenced = @silence - end - - def test_set_content_type_raises_deprecation_warning - mail = Mail.new - assert_deprecated do - assert_nothing_raised do - mail.set_content_type "text/plain" - end - end - assert_equal mail.mime_type, "text/plain" - end - - def test_transfer_encoding_raises_deprecation_warning - mail = Mail.new - assert_deprecated do - assert_nothing_raised do - mail.transfer_encoding "base64" - end - end - assert_equal mail.content_transfer_encoding, "base64" - end - - def test_transfer_encoding_setter_raises_deprecation_warning - mail = Mail.new - assert_deprecated do - assert_nothing_raised do - mail.transfer_encoding = "base64" - end - end - assert_equal mail.content_transfer_encoding, "base64" - end -end diff --git a/actionpack/Rakefile b/actionpack/Rakefile index 9030db9f7a..66dd88f0c6 100755 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -1,7 +1,7 @@ #!/usr/bin/env rake require 'rake/testtask' require 'rake/packagetask' -require 'rake/gempackagetask' +require 'rubygems/package_task' desc "Default Task" task :default => :test @@ -36,7 +36,7 @@ end spec = eval(File.read('actionpack.gemspec')) -Rake::GemPackageTask.new(spec) do |p| +Gem::PackageTask.new(spec) do |p| p.gem_spec = spec end diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index ccb866f4f7..f3e94df4b9 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -2,7 +2,6 @@ require 'tempfile' require 'stringio' require 'strscan' -require 'active_support/core_ext/module/deprecation' require 'active_support/core_ext/hash/indifferent_access' require 'active_support/core_ext/string/access' require 'active_support/inflector' @@ -26,7 +25,7 @@ module ActionDispatch HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM HTTP_NEGOTIATE HTTP_PRAGMA ].freeze - + ENV_METHODS.each do |env| class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{env.sub(/^HTTP_/n, '').downcase} @@ -134,11 +133,6 @@ module ActionDispatch @fullpath ||= super end - def forgery_whitelisted? - get? - end - deprecate :forgery_whitelisted? => "it is just an alias for 'get?' now, update your code" - def media_type content_mime_type.to_s end diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 76d0857b93..f1e85559a3 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -116,32 +116,9 @@ module ActionDispatch # :nodoc: EMPTY = " " - class BodyBuster #:nodoc: - def initialize(response) - @response = response - @body = "" - end - - def bust(body) - body.call(@response, self) - body.close if body.respond_to?(:close) - @body - end - - def write(string) - @body << string.to_s - end - end - def body=(body) @blank = true if body == EMPTY - if body.respond_to?(:call) - ActiveSupport::Deprecation.warn "Setting a Proc or an object that responds to call " \ - "in response_body is no longer supported", caller - body = BodyBuster.new(self).bust(body) - end - # Explicitly check for strings. This is *wrong* theoretically # but if we don't check this, the performance on string bodies # is bad on Ruby 1.8 (because strings responds to each then). diff --git a/actionpack/lib/action_dispatch/middleware/callbacks.rb b/actionpack/lib/action_dispatch/middleware/callbacks.rb index 1bb2ad7f67..8c0f4052ec 100644 --- a/actionpack/lib/action_dispatch/middleware/callbacks.rb +++ b/actionpack/lib/action_dispatch/middleware/callbacks.rb @@ -19,8 +19,7 @@ module ActionDispatch set_callback(:call, :after, *args, &block) end - def initialize(app, unused = nil) - ActiveSupport::Deprecation.warn "Passing a second argument to ActionDispatch::Callbacks.new is deprecated." unless unused.nil? + def initialize(app) @app = app end diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index 8ad1ad1f2f..a70d814749 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -73,13 +73,7 @@ module ActionDispatch include StaleSessionCheck def destroy_session(env, sid, options) - ActiveSupport::Deprecation.warn "Implementing #destroy in session stores is deprecated. " << - "Please implement destroy_session(env, session_id, options) instead." - destroy(env) - end - - def destroy(env) - raise '#destroy needs to be implemented.' + raise '#destroy_session needs to be implemented.' end end end diff --git a/actionpack/lib/action_dispatch/routing/route.rb b/actionpack/lib/action_dispatch/routing/route.rb index a049510182..10b3d38346 100644 --- a/actionpack/lib/action_dispatch/routing/route.rb +++ b/actionpack/lib/action_dispatch/routing/route.rb @@ -1,5 +1,3 @@ -require 'active_support/core_ext/module/deprecation' - module ActionDispatch module Routing class Route #:nodoc: @@ -47,11 +45,6 @@ module ActionDispatch @segment_keys ||= conditions[:path_info].names.compact.map { |key| key.to_sym } end - def to_a - [@app, @conditions, @defaults, @name] - end - deprecate :to_a - def to_s @to_s ||= begin "%-6s %-40s %s" % [(verb || :any).to_s.upcase, path, requirements.inspect] diff --git a/actionpack/lib/action_view/helpers/asset_paths.rb b/actionpack/lib/action_view/helpers/asset_paths.rb index 38810eea2e..1bc5c9e003 100644 --- a/actionpack/lib/action_view/helpers/asset_paths.rb +++ b/actionpack/lib/action_view/helpers/asset_paths.rb @@ -55,11 +55,11 @@ module ActionView # Pick an asset host for this source. Returns +nil+ if no host is set, # the host if no wildcard is set, the host interpolated with the # numbers 0-3 if it contains <tt>%d</tt> (the number is the source hash mod 4), - # or the value returned from invoking the proc if it's a proc or the value from - # invoking call if it's an object responding to call. + # or the value returned from invoking call on an object responding to call + # (proc or otherwise). def compute_asset_host(source) if host = config.asset_host - if host.is_a?(Proc) || host.respond_to?(:call) + if host.respond_to?(:call) case host.is_a?(Proc) ? host.arity : host.method(:call).arity when 2 request = controller.respond_to?(:request) && controller.request diff --git a/actionpack/lib/action_view/template/handler.rb b/actionpack/lib/action_view/template/handler.rb deleted file mode 100644 index 636f3ebbad..0000000000 --- a/actionpack/lib/action_view/template/handler.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'action_dispatch/http/mime_type' -require 'active_support/core_ext/class/attribute' - -# Legacy TemplateHandler stub -module ActionView - class Template - module Handlers #:nodoc: - module Compilable - def self.included(base) - ActiveSupport::Deprecation.warn "Including Compilable in your template handler is deprecated. " << - "Since Rails 3, all the API your template handler needs to implement is to respond to #call." - base.extend(ClassMethods) - end - - module ClassMethods - def call(template) - new.compile(template) - end - end - - def compile(template) - raise "Need to implement #{self.class.name}#compile(template)" - end - end - end - - class Template::Handler - class_attribute :default_format - self.default_format = Mime::HTML - - def self.inherited(base) - ActiveSupport::Deprecation.warn "Inheriting from ActionView::Template::Handler is deprecated. " << - "Since Rails 3, all the API your template handler needs to implement is to respond to #call." - super - end - - def self.call(template) - raise "Need to implement #{self.class.name}#call(template)" - end - - def render(template, local_assigns) - raise "Need to implement #{self.class.name}#render(template, local_assigns)" - end - end - end - - TemplateHandlers = Template::Handlers - TemplateHandler = Template::Handler -end diff --git a/actionpack/lib/action_view/template/handlers.rb b/actionpack/lib/action_view/template/handlers.rb index 959afa734e..aa693335e3 100644 --- a/actionpack/lib/action_view/template/handlers.rb +++ b/actionpack/lib/action_view/template/handlers.rb @@ -41,12 +41,6 @@ module ActionView #:nodoc: @@default_template_handlers = klass end - def handler_class_for_extension(extension) - ActiveSupport::Deprecation.warn "handler_class_for_extension is deprecated. " << - "Please use handler_for_extension instead", caller - handler_for_extension(extension) - end - def handler_for_extension(extension) registered_template_handler(extension) || @@default_template_handlers end diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb index a1e3fd7768..77720e2bc8 100644 --- a/actionpack/lib/action_view/template/handlers/erb.rb +++ b/actionpack/lib/action_view/template/handlers/erb.rb @@ -1,5 +1,5 @@ +require 'action_dispatch/http/mime_type' require 'active_support/core_ext/class/attribute_accessors' -require 'action_view/template/handler' require 'erubis' module ActionView diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index d0317a148b..2cc85a9f69 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -218,12 +218,6 @@ module ActionView end] end - def _assigns - ActiveSupport::Deprecation.warn "ActionView::TestCase#_assigns is deprecated and will be removed in future versions. " << - "Please use view_assigns instead." - view_assigns - end - def _routes @controller._routes if @controller.respond_to?(:_routes) end diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index db0f02a6ab..7b8a7ad3bb 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -9,15 +9,7 @@ module Sprockets false end - def self.using_scss? - require 'sass' - defined?(Sass) - rescue LoadError - false - end - config.app_generators.javascript_engine :coffee if using_coffee? - config.app_generators.stylesheet_engine :scss if using_scss? # Configure ActionController to use sprockets. initializer "sprockets.set_configs", :after => "action_controller.set_configs" do |app| @@ -28,7 +20,8 @@ module Sprockets # We need to configure this after initialization to ensure we collect # paths from all engines. This hook is invoked exactly before routes - # are compiled. + # are compiled, and so that other Railties have an opportunity to + # register compressors. config.after_initialize do |app| assets = app.config.assets next unless assets.enabled @@ -61,8 +54,8 @@ module Sprockets env.static_root = File.join(app.root.join("public"), assets.prefix) env.paths.concat assets.paths env.logger = Rails.logger - env.js_compressor = expand_js_compressor(assets.js_compressor) - env.css_compressor = expand_css_compressor(assets.css_compressor) + env.js_compressor = expand_js_compressor(assets.js_compressor) if assets.compress + env.css_compressor = expand_css_compressor(assets.css_compressor) if assets.compress env end @@ -84,15 +77,6 @@ module Sprockets def expand_css_compressor(sym) case sym - when :scss - require 'sass' - compressor = Object.new - def compressor.compress(source) - Sass::Engine.new(source, - :syntax => :scss, :style => :compressed - ).render - end - compressor when :yui require 'yui/compressor' YUI::CssCompressor.new diff --git a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb deleted file mode 100644 index 0c02afea36..0000000000 --- a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'abstract_unit' - -class DeprecatedBaseMethodsTest < ActionController::TestCase - class Target < ActionController::Base - def home_url(greeting) - "http://example.com/#{greeting}" - end - - def raises_name_error - this_method_doesnt_exist - end - - def rescue_action(e) raise e end - end - - tests Target - - if defined? Test::Unit::Error - def test_assertion_failed_error_silences_deprecation_warnings - get :raises_name_error - rescue => e - error = Test::Unit::Error.new('testing ur doodz', e) - assert_not_deprecated { error.message } - end - end -end diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index 9f0670ffdf..584d73668a 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -77,7 +77,7 @@ class HelperTest < ActiveSupport::TestCase self.test_helper = LocalAbcHelper end - def test_deprecated_helper + def test_helper assert_equal expected_helper_methods, missing_methods assert_nothing_raised { @controller_class.helper TestHelper } assert_equal [], missing_methods diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index e62f3155c5..be59da9105 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -1023,11 +1023,6 @@ class RenderTest < ActionController::TestCase assert_equal " ", @response.body end - def test_render_to_string_not_deprecated - assert_not_deprecated { get :hello_in_a_string } - assert_equal "How's there? goodbyeHello: davidHello: marygoodbye\n", @response.body - end - def test_render_to_string_doesnt_break_assigns get :render_to_string_with_assigns assert_equal "i'm before the render", assigns(:before) @@ -1106,7 +1101,7 @@ class RenderTest < ActionController::TestCase end def test_yield_content_for - assert_not_deprecated { get :yield_content_for } + get :yield_content_for assert_equal "<title>Putting stuff in the title!</title>\nGreat stuff!\n", @response.body end diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb index 3de1849db8..f5ac886c20 100644 --- a/actionpack/test/controller/view_paths_test.rb +++ b/actionpack/test/controller/view_paths_test.rb @@ -32,17 +32,11 @@ class ViewLoadPathsTest < ActionController::TestCase @controller.send :assign_shortcuts, @request, @response @controller.send :initialize_template_class, @response - # Track the last warning. - @old_behavior = ActiveSupport::Deprecation.behavior - @last_message = nil - ActiveSupport::Deprecation.behavior = Proc.new { |message, callback| @last_message = message } - @paths = TestController.view_paths end def teardown TestController.view_paths = @paths - ActiveSupport::Deprecation.behavior = @old_behavior end def expand(array) @@ -179,7 +173,7 @@ class ViewLoadPathsTest < ActionController::TestCase assert_nothing_raised { C.append_view_path 'c/path' } assert_paths C, "c/path" end - + def test_lookup_context_accessor assert_equal ["test"], TestController.new.lookup_context.prefixes end diff --git a/actionpack/test/dispatch/response_body_is_proc_test.rb b/actionpack/test/dispatch/response_body_is_proc_test.rb deleted file mode 100644 index fd94832624..0000000000 --- a/actionpack/test/dispatch/response_body_is_proc_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'abstract_unit' - -class ResponseBodyIsProcTest < ActionDispatch::IntegrationTest - class TestController < ActionController::Base - def test - self.response_body = proc { |response, output| - output.write 'Hello' - } - end - end - - def test_simple_get - with_test_route_set do - assert_deprecated do - get '/test' - end - assert_response :success - assert_equal 'Hello', response.body - end - end - - private - - def with_test_route_set(options = {}) - with_routing do |set| - set.draw do - match ':action', :to => ::ResponseBodyIsProcTest::TestController - end - - @app = self.class.build_app(set) do |middleware| - middleware.delete "ActionDispatch::ShowExceptions" - end - - yield - end - end -end diff --git a/actionpack/test/fixtures/test/deprecated_nested_layout.erb b/actionpack/test/fixtures/test/deprecated_nested_layout.erb deleted file mode 100644 index 7b6dcbb6c7..0000000000 --- a/actionpack/test/fixtures/test/deprecated_nested_layout.erb +++ /dev/null @@ -1,3 +0,0 @@ -<% content_for :title, "title" -%> -<% content_for :column do -%>column<% end -%> -<% render :layout => 'layouts/column' do -%>content<% end -%>
\ No newline at end of file diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb index 63b92aadf4..0104c20bc7 100644 --- a/actionpack/test/template/number_helper_test.rb +++ b/actionpack/test/template/number_helper_test.rb @@ -19,15 +19,6 @@ class NumberHelperTest < ActionView::TestCase gigabytes(number) * 1024 end - def silence_deprecation_warnings - @old_deprecatios_silenced = ActiveSupport::Deprecation.silenced - ActiveSupport::Deprecation.silenced = true - end - - def restore_deprecation_warnings - ActiveSupport::Deprecation.silenced = @old_deprecatios_silenced - end - def test_number_to_phone assert_equal("555-1234", number_to_phone(5551234)) assert_equal("800-555-1212", number_to_phone(8005551212)) diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb index cd4618a505..f463675a2e 100644 --- a/actionpack/test/template/test_case_test.rb +++ b/actionpack/test/template/test_case_test.rb @@ -141,22 +141,6 @@ module ActionView end end - class AssignsTest < ActionView::TestCase - setup do - ActiveSupport::Deprecation.stubs(:warn) - end - - test "_assigns delegates to user_defined_ivars" do - self.expects(:view_assigns) - _assigns - end - - test "_assigns is deprecated" do - ActiveSupport::Deprecation.expects(:warn) - _assigns - end - end - class ViewAssignsTest < ActionView::TestCase test "view_assigns returns a Hash of user defined ivars" do @a = 'b' diff --git a/activemodel/Rakefile b/activemodel/Rakefile index 0a10912695..c4b020196d 100755 --- a/activemodel/Rakefile +++ b/activemodel/Rakefile @@ -20,11 +20,11 @@ namespace :test do end require 'rake/packagetask' -require 'rake/gempackagetask' +require 'rubygems/package_task' spec = eval(File.read("#{dir}/activemodel.gemspec")) -Rake::GemPackageTask.new(spec) do |p| +Gem::PackageTask.new(spec) do |p| p.gem_spec = spec end diff --git a/activerecord/Rakefile b/activerecord/Rakefile index e414c4fb1c..346c7e8142 100755 --- a/activerecord/Rakefile +++ b/activerecord/Rakefile @@ -1,7 +1,7 @@ #!/usr/bin/env rake require 'rake/testtask' require 'rake/packagetask' -require 'rake/gempackagetask' +require 'rubygems/package_task' require File.expand_path(File.dirname(__FILE__)) + "/test/config" @@ -171,7 +171,7 @@ task :rebuild_frontbase_databases => 'frontbase:rebuild_databases' spec = eval(File.read('activerecord.gemspec')) -Rake::GemPackageTask.new(spec) do |p| +Gem::PackageTask.new(spec) do |p| p.gem_spec = spec end diff --git a/activerecord/lib/active_record/associations/through_association.rb b/activerecord/lib/active_record/associations/through_association.rb index 53c5c3cedf..81172179e0 100644 --- a/activerecord/lib/active_record/associations/through_association.rb +++ b/activerecord/lib/active_record/associations/through_association.rb @@ -16,7 +16,7 @@ module ActiveRecord chain[1..-1].each do |reflection| scope = scope.merge( reflection.klass.scoped.with_default_scope. - except(:select, :create_with) + except(:select, :create_with, :includes) ) end scope diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 19a7965429..cb2c621c79 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -428,6 +428,10 @@ module ActiveRecord #:nodoc: class_attribute :default_scopes, :instance_writer => false self.default_scopes = [] + # Boolean flag to prevent infinite recursion when evaluating default scopes + class_attribute :apply_default_scope, :instance_writer => false + self.apply_default_scope = true + # 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 @@ -1261,11 +1265,14 @@ MSG self.default_scopes = default_scopes + [scope] end + # The apply_default_scope flag is used to prevent an infinite recursion situation where + # a default scope references a scope which has a default scope which references a scope... def build_default_scope #:nodoc: + return unless apply_default_scope + self.apply_default_scope = false + if method(:default_scope).owner != Base.singleton_class - # Use relation.scoping to ensure we ignore whatever the current value of - # self.current_scope may be. - relation.scoping { default_scope } + default_scope elsif default_scopes.any? default_scopes.inject(relation) do |default_scope, scope| if scope.is_a?(Hash) @@ -1277,6 +1284,8 @@ MSG end end end + ensure + self.apply_default_scope = true end # Returns the class type of the record using the current module as a prefix. So descendants of @@ -1861,12 +1870,16 @@ MSG # Returns the contents of the record as a nicely formatted string. def inspect - attributes_as_nice_string = self.class.column_names.collect { |name| - if has_attribute?(name) - "#{name}: #{attribute_for_inspect(name)}" - end - }.compact.join(", ") - "#<#{self.class} #{attributes_as_nice_string}>" + inspection = if @attributes + self.class.column_names.collect { |name| + if has_attribute?(name) + "#{name}: #{attribute_for_inspect(name)}" + end + }.compact.join(", ") + else + "not initialized" + end + "#<#{self.class} #{inspection}>" end protected diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 49df63d585..1f31722a7c 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -385,11 +385,11 @@ class FixturesFileNotFound < StandardError; end # # first: # name: Smurf -# <<: *DEFAULTS +# *DEFAULTS # # second: # name: Fraggle -# <<: *DEFAULTS +# *DEFAULTS # # Any fixture labeled "DEFAULTS" is safely ignored. diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index b9041f44d8..e84a479a13 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -33,7 +33,11 @@ module ActiveRecord # +save+ returns +false+. See ActiveRecord::Callbacks for further # details. def save(*) - create_or_update + begin + create_or_update + rescue ActiveRecord::RecordInvalid + false + end end # Saves the model. diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb index bae2ded244..47133e77e8 100644 --- a/activerecord/lib/active_record/railtie.rb +++ b/activerecord/lib/active_record/railtie.rb @@ -29,8 +29,8 @@ module ActiveRecord # When loading console, force ActiveRecord::Base to be loaded # to avoid cross references when loading a constant for the # first time. Also, make it output to STDERR. - console do |sandbox| - require "active_record/railties/console_sandbox" if sandbox + console do |app| + require "active_record/railties/console_sandbox" if app.sandbox? ActiveRecord::Base.logger = Logger.new(STDERR) end diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 089bbed08a..6f8f84d50b 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -27,7 +27,7 @@ db_namespace = namespace :db do # # development: # database: blog_development - # <<: *defaults + # *defaults next unless config['database'] # Only connect to local databases local_database?(config) { create_database(config) } @@ -481,8 +481,7 @@ db_namespace = namespace :db do # desc "Creates a sessions migration for use with ActiveRecord::SessionStore" task :create => :environment do raise 'Task unavailable to this database (no migration support)' unless ActiveRecord::Base.connection.supports_migrations? - require 'rails/generators' - Rails::Generators.configure! + Rails.application.load_generators require 'rails/generators/rails/session_migration/session_migration_generator' Rails::Generators::SessionMigrationGenerator.start [ ENV['MIGRATION'] || 'add_sessions_table' ] end diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index ae9afad48a..65e2ad0963 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -102,24 +102,30 @@ module ActiveRecord def to_a return @records if loaded? - @records = if @readonly_value.nil? && !@klass.locking_enabled? - eager_loading? ? find_with_associations : @klass.find_by_sql(arel.to_sql, @bind_values) - else - IdentityMap.without do + default_scoped = with_default_scope + + if default_scoped.equal?(self) + @records = if @readonly_value.nil? && !@klass.locking_enabled? eager_loading? ? find_with_associations : @klass.find_by_sql(arel.to_sql, @bind_values) + else + IdentityMap.without do + eager_loading? ? find_with_associations : @klass.find_by_sql(arel.to_sql, @bind_values) + end end - end - preload = @preload_values - preload += @includes_values unless eager_loading? - preload.each do |associations| - ActiveRecord::Associations::Preloader.new(@records, associations).run - end + preload = @preload_values + preload += @includes_values unless eager_loading? + preload.each do |associations| + ActiveRecord::Associations::Preloader.new(@records, associations).run + end - # @readonly_value is true only if set explicitly. @implicit_readonly is true if there - # are JOINS and no explicit SELECT. - readonly = @readonly_value.nil? ? @implicit_readonly : @readonly_value - @records.each { |record| record.readonly! } if readonly + # @readonly_value is true only if set explicitly. @implicit_readonly is true if there + # are JOINS and no explicit SELECT. + readonly = @readonly_value.nil? ? @implicit_readonly : @readonly_value + @records.each { |record| record.readonly! } if readonly + else + @records = default_scoped.to_a + end @loaded = true @records @@ -418,9 +424,10 @@ module ActiveRecord end def with_default_scope #:nodoc: - if default_scoped? - default_scope = @klass.send(:build_default_scope) - default_scope ? default_scope.merge(self) : self + if default_scoped? && default_scope = klass.send(:build_default_scope) + default_scope = default_scope.merge(self) + default_scope.default_scoped = false + default_scope else self end diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index 3e92a77830..5028cee32d 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -448,6 +448,12 @@ class EagerAssociationTest < ActiveRecord::TestCase assert_equal post_tags, eager_post_tags end + def test_eager_with_has_many_through_join_model_ignores_default_includes + assert_nothing_raised do + authors(:david).comments_on_posts_with_default_include.to_a + end + end + def test_eager_with_has_many_and_limit posts = Post.find(:all, :order => 'posts.id asc', :include => [ :author, :comments ], :limit => 2) assert_equal 2, posts.size @@ -675,6 +681,46 @@ class EagerAssociationTest < ActiveRecord::TestCase } end + def test_eager_with_default_scope + developer = EagerDeveloperWithDefaultScope.where(:name => 'David').first + projects = Project.order(:id).all + assert_no_queries do + assert_equal(projects, developer.projects) + end + end + + def test_eager_with_default_scope_as_class_method + developer = EagerDeveloperWithClassMethodDefaultScope.where(:name => 'David').first + projects = Project.order(:id).all + assert_no_queries do + assert_equal(projects, developer.projects) + end + end + + def test_eager_with_default_scope_as_lambda + developer = EagerDeveloperWithLambdaDefaultScope.where(:name => 'David').first + projects = Project.order(:id).all + assert_no_queries do + assert_equal(projects, developer.projects) + end + end + + def test_eager_with_default_scope_as_block + developer = EagerDeveloperWithBlockDefaultScope.where(:name => 'David').first + projects = Project.order(:id).all + assert_no_queries do + assert_equal(projects, developer.projects) + end + end + + def test_eager_with_default_scope_as_callable + developer = EagerDeveloperWithCallableDefaultScope.where(:name => 'David').first + projects = Project.order(:id).all + assert_no_queries do + assert_equal(projects, developer.projects) + end + end + def find_all_ordered(className, include=nil) className.find(:all, :order=>"#{className.table_name}.#{className.primary_key}", :include=>include) end diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index 89117593fd..877148bd5e 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -766,4 +766,46 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert_equal [category.name], post.named_category_ids # checks when target loaded assert_equal [category.name], post.reload.named_category_ids # checks when target no loaded end + + def test_create_should_not_raise_exception_when_join_record_has_errors + repair_validations(Categorization) do + Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' } + Category.create(:name => 'Fishing', :authors => [Author.first]) + end + end + + def test_save_should_not_raise_exception_when_join_record_has_errors + repair_validations(Categorization) do + Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' } + c = Category.create(:name => 'Fishing', :authors => [Author.first]) + c.save + end + end + + def test_create_bang_should_raise_exception_when_join_record_has_errors + repair_validations(Categorization) do + Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' } + assert_raises(ActiveRecord::RecordInvalid) do + Category.create!(:name => 'Fishing', :authors => [Author.first]) + end + end + end + + def test_save_bang_should_raise_exception_when_join_record_has_errors + repair_validations(Categorization) do + Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' } + c = Category.new(:name => 'Fishing', :authors => [Author.first]) + assert_raises(ActiveRecord::RecordInvalid) do + c.save! + end + end + end + + def test_create_bang_returns_falsy_when_join_record_has_errors + repair_validations(Categorization) do + Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' } + c = Category.new(:name => 'Fishing', :authors => [Author.first]) + assert !c.save + end + end end diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 5074ae50ab..54c4d4ae90 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -109,6 +109,14 @@ class AttributeMethodsTest < ActiveRecord::TestCase assert_respond_to topic, :title end + # IRB inspects the return value of "MyModel.allocate" + # by inspecting it. + def test_allocated_object_can_be_inspected + topic = Topic.allocate + assert_nothing_raised { topic.inspect } + assert topic.inspect, "#<Topic not initialized>" + end + def test_array_content topic = Topic.new topic.content = %w( one two three ) diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index c215602567..8f8e72f052 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -312,6 +312,14 @@ class DefaultScopingTest < ActiveRecord::TestCase assert_equal [developers(:david).becomes(ClassMethodDeveloperCalledDavid)], ClassMethodDeveloperCalledDavid.all end + def test_default_scope_as_class_method_referencing_scope + assert_equal [developers(:david).becomes(ClassMethodReferencingScopeDeveloperCalledDavid)], ClassMethodReferencingScopeDeveloperCalledDavid.all + end + + def test_default_scope_as_block_referencing_scope + assert_equal [developers(:david).becomes(LazyBlockReferencingScopeDeveloperCalledDavid)], LazyBlockReferencingScopeDeveloperCalledDavid.all + end + def test_default_scope_with_lambda assert_equal [developers(:david).becomes(LazyLambdaDeveloperCalledDavid)], LazyLambdaDeveloperCalledDavid.all end diff --git a/activerecord/test/fixtures/parrots.yml b/activerecord/test/fixtures/parrots.yml index 8b73b8cdf6..8425ef98e0 100644 --- a/activerecord/test/fixtures/parrots.yml +++ b/activerecord/test/fixtures/parrots.yml @@ -24,4 +24,4 @@ DEFAULTS: &DEFAULTS parrot_sti_class: LiveParrot davey: - <<: *DEFAULTS + *DEFAULTS diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb index e0cbc44265..23db5650d4 100644 --- a/activerecord/test/models/author.rb +++ b/activerecord/test/models/author.rb @@ -138,6 +138,9 @@ class Author < ActiveRecord::Base has_many :misc_post_first_blue_tags_2, :through => :posts, :source => :first_blue_tags_2, :conditions => { :posts => { :title => ['misc post by bob', 'misc post by mary'] } } + has_many :posts_with_default_include, :class_name => 'PostWithDefaultInclude' + has_many :comments_on_posts_with_default_include, :through => :posts_with_default_include, :source => :comments + scope :relation_include_posts, includes(:posts) scope :relation_include_tags, includes(:tags) diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index 152f804e16..41c52f7df0 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -127,6 +127,21 @@ class ClassMethodDeveloperCalledDavid < ActiveRecord::Base end end +class ClassMethodReferencingScopeDeveloperCalledDavid < ActiveRecord::Base + self.table_name = 'developers' + scope :david, where(:name => 'David') + + def self.default_scope + david + end +end + +class LazyBlockReferencingScopeDeveloperCalledDavid < ActiveRecord::Base + self.table_name = 'developers' + scope :david, where(:name => 'David') + default_scope { david } +end + class DeveloperCalledJamis < ActiveRecord::Base self.table_name = 'developers' @@ -165,4 +180,39 @@ class ModuleIncludedPoorDeveloperCalledJamis < DeveloperCalledJamis include SalaryDefaultScope end +class EagerDeveloperWithDefaultScope < ActiveRecord::Base + self.table_name = 'developers' + has_and_belongs_to_many :projects, :foreign_key => 'developer_id', :join_table => 'developers_projects', :order => 'projects.id' + + default_scope includes(:projects) +end +class EagerDeveloperWithClassMethodDefaultScope < ActiveRecord::Base + self.table_name = 'developers' + has_and_belongs_to_many :projects, :foreign_key => 'developer_id', :join_table => 'developers_projects', :order => 'projects.id' + + def self.default_scope + includes(:projects) + end +end + +class EagerDeveloperWithLambdaDefaultScope < ActiveRecord::Base + self.table_name = 'developers' + has_and_belongs_to_many :projects, :foreign_key => 'developer_id', :join_table => 'developers_projects', :order => 'projects.id' + + default_scope lambda { includes(:projects) } +end + +class EagerDeveloperWithBlockDefaultScope < ActiveRecord::Base + self.table_name = 'developers' + has_and_belongs_to_many :projects, :foreign_key => 'developer_id', :join_table => 'developers_projects', :order => 'projects.id' + + default_scope { includes(:projects) } +end + +class EagerDeveloperWithCallableDefaultScope < ActiveRecord::Base + self.table_name = 'developers' + has_and_belongs_to_many :projects, :foreign_key => 'developer_id', :join_table => 'developers_projects', :order => 'projects.id' + + default_scope OpenStruct.new(:call => includes(:projects)) +end diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 80296032bb..f2ab7b053e 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -162,3 +162,9 @@ class FirstPost < ActiveRecord::Base has_many :comments, :foreign_key => :post_id has_one :comment, :foreign_key => :post_id end + +class PostWithDefaultInclude < ActiveRecord::Base + self.table_name = 'posts' + default_scope includes(:comments) + has_many :comments, :foreign_key => :post_id +end
\ No newline at end of file diff --git a/activeresource/Rakefile b/activeresource/Rakefile index 42e450da66..b1c18ff189 100755 --- a/activeresource/Rakefile +++ b/activeresource/Rakefile @@ -1,7 +1,7 @@ #!/usr/bin/env rake require 'rake/testtask' require 'rake/packagetask' -require 'rake/gempackagetask' +require 'rubygems/package_task' desc "Default Task" task :default => [ :test ] @@ -26,7 +26,7 @@ end spec = eval(File.read('activeresource.gemspec')) -Rake::GemPackageTask.new(spec) do |p| +Gem::PackageTask.new(spec) do |p| p.gem_spec = spec end diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb index e90580be4f..6167c1420e 100644 --- a/activeresource/lib/active_resource/http_mock.rb +++ b/activeresource/lib/active_resource/http_mock.rb @@ -55,7 +55,7 @@ module ActiveResource @responses = responses end - for method in [ :post, :put, :get, :delete, :head ] + [ :post, :put, :get, :delete, :head ].each do |method| # def post(path, request_headers = {}, body = nil, status = 200, response_headers = {}) # @responses[Request.new(:post, path, nil, request_headers)] = Response.new(body || "", status, response_headers) # end diff --git a/activesupport/Rakefile b/activesupport/Rakefile index d117ca6356..822c9d98ae 100755 --- a/activesupport/Rakefile +++ b/activesupport/Rakefile @@ -1,5 +1,5 @@ require 'rake/testtask' -require 'rake/gempackagetask' +require 'rubygems/package_task' task :default => :test Rake::TestTask.new do |t| @@ -20,7 +20,7 @@ dist_dirs = [ "lib", "test"] spec = eval(File.read('activesupport.gemspec')) -Rake::GemPackageTask.new(spec) do |p| +Gem::PackageTask.new(spec) do |p| p.gem_spec = spec end diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb index 2668087f57..26412cd7f4 100644 --- a/activesupport/lib/active_support/buffered_logger.rb +++ b/activesupport/lib/active_support/buffered_logger.rb @@ -77,7 +77,7 @@ module ActiveSupport # def info # def warn # def debug - for severity in Severity.constants + Severity.constants.each do |severity| class_eval <<-EOT, __FILE__, __LINE__ + 1 def #{severity.downcase}(message = nil, progname = nil, &block) # def debug(message = nil, progname = nil, &block) add(#{severity}, message, progname, &block) # add(DEBUG, message, progname, &block) diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index d22fe14b33..c2c45e9f9d 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -14,6 +14,7 @@ require 'time' require 'active_support/core_ext/time/conversions' require 'active_support/core_ext/date_time/conversions' require 'active_support/core_ext/date/conversions' +require 'set' module ActiveSupport class << self @@ -39,7 +40,7 @@ module ActiveSupport def initialize(options = nil) @options = options - @seen = [] + @seen = Set.new end def encode(value, use_options = true) @@ -71,13 +72,12 @@ module ActiveSupport private def check_for_circular_references(value) - if @seen.any? { |object| object.equal?(value) } + unless @seen.add?(value.__id__) raise CircularReferenceError, 'object references itself' end - @seen.unshift value yield ensure - @seen.shift + @seen.delete(value.__id__) end end diff --git a/activesupport/lib/active_support/testing/performance/jruby.rb b/activesupport/lib/active_support/testing/performance/jruby.rb index 6b27959840..326904bbac 100644 --- a/activesupport/lib/active_support/testing/performance/jruby.rb +++ b/activesupport/lib/active_support/testing/performance/jruby.rb @@ -1,6 +1,6 @@ require 'jruby/profiler' require 'java' -import java.lang.management.ManagementFactory +java_import java.lang.management.ManagementFactory module ActiveSupport module Testing diff --git a/activesupport/lib/active_support/xml_mini/jdom.rb b/activesupport/lib/active_support/xml_mini/jdom.rb index 48c1cb3fe9..7aefabfdd1 100644 --- a/activesupport/lib/active_support/xml_mini/jdom.rb +++ b/activesupport/lib/active_support/xml_mini/jdom.rb @@ -5,12 +5,12 @@ include Java require 'active_support/core_ext/object/blank' -import javax.xml.parsers.DocumentBuilder unless defined? DocumentBuilder -import javax.xml.parsers.DocumentBuilderFactory unless defined? DocumentBuilderFactory -import java.io.StringReader unless defined? StringReader -import org.xml.sax.InputSource unless defined? InputSource -import org.xml.sax.Attributes unless defined? Attributes -import org.w3c.dom.Node unless defined? Node +java_import javax.xml.parsers.DocumentBuilder unless defined? DocumentBuilder +java_import javax.xml.parsers.DocumentBuilderFactory unless defined? DocumentBuilderFactory +java_import java.io.StringReader unless defined? StringReader +java_import org.xml.sax.InputSource unless defined? InputSource +java_import org.xml.sax.Attributes unless defined? Attributes +java_import org.w3c.dom.Node unless defined? Node # = XmlMini JRuby JDOM implementation module ActiveSupport diff --git a/activesupport/test/xml_mini/jdom_engine_test.rb b/activesupport/test/xml_mini/jdom_engine_test.rb index 6b1edcbc9b..3fe5e4fd78 100644 --- a/activesupport/test/xml_mini/jdom_engine_test.rb +++ b/activesupport/test/xml_mini/jdom_engine_test.rb @@ -1,39 +1,38 @@ -require 'abstract_unit' -require 'active_support/xml_mini' -require 'active_support/core_ext/hash/conversions' - if RUBY_PLATFORM =~ /java/ + require 'abstract_unit' + require 'active_support/xml_mini' + require 'active_support/core_ext/hash/conversions' -class JDOMEngineTest < Test::Unit::TestCase - include ActiveSupport + class JDOMEngineTest < Test::Unit::TestCase + include ActiveSupport - def setup - @default_backend = XmlMini.backend - XmlMini.backend = 'JDOM' - end + def setup + @default_backend = XmlMini.backend + XmlMini.backend = 'JDOM' + end - def teardown - XmlMini.backend = @default_backend - end + def teardown + XmlMini.backend = @default_backend + end - # def test_file_from_xml - # hash = Hash.from_xml(<<-eoxml) - # <blog> - # <logo type="file" name="logo.png" content_type="image/png"> - # </logo> - # </blog> - # eoxml - # assert hash.has_key?('blog') - # assert hash['blog'].has_key?('logo') - # - # file = hash['blog']['logo'] - # assert_equal 'logo.png', file.original_filename - # assert_equal 'image/png', file.content_type - # end - - def test_exception_thrown_on_expansion_attack - assert_raise NativeException do - attack_xml = <<-EOT + # def test_file_from_xml + # hash = Hash.from_xml(<<-eoxml) + # <blog> + # <logo type="file" name="logo.png" content_type="image/png"> + # </logo> + # </blog> + # eoxml + # assert hash.has_key?('blog') + # assert hash['blog'].has_key?('logo') + # + # file = hash['blog']['logo'] + # assert_equal 'logo.png', file.original_filename + # assert_equal 'image/png', file.content_type + # end + + def test_exception_thrown_on_expansion_attack + assert_raise NativeException do + attack_xml = <<-EOT <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE member [ <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;"> @@ -47,91 +46,91 @@ class JDOMEngineTest < Test::Unit::TestCase <member> &a; </member> - EOT - Hash.from_xml(attack_xml) + EOT + Hash.from_xml(attack_xml) + end end - end - def test_setting_JDOM_as_backend - XmlMini.backend = 'JDOM' - assert_equal XmlMini_JDOM, XmlMini.backend - end + def test_setting_JDOM_as_backend + XmlMini.backend = 'JDOM' + assert_equal XmlMini_JDOM, XmlMini.backend + end - def test_blank_returns_empty_hash - assert_equal({}, XmlMini.parse(nil)) - assert_equal({}, XmlMini.parse('')) - end + def test_blank_returns_empty_hash + assert_equal({}, XmlMini.parse(nil)) + assert_equal({}, XmlMini.parse('')) + end - def test_array_type_makes_an_array - assert_equal_rexml(<<-eoxml) + def test_array_type_makes_an_array + assert_equal_rexml(<<-eoxml) <blog> <posts type="array"> <post>a post</post> <post>another post</post> </posts> </blog> - eoxml - end + eoxml + end - def test_one_node_document_as_hash - assert_equal_rexml(<<-eoxml) + def test_one_node_document_as_hash + assert_equal_rexml(<<-eoxml) <products/> - eoxml - end + eoxml + end - def test_one_node_with_attributes_document_as_hash - assert_equal_rexml(<<-eoxml) + def test_one_node_with_attributes_document_as_hash + assert_equal_rexml(<<-eoxml) <products foo="bar"/> - eoxml - end + eoxml + end - def test_products_node_with_book_node_as_hash - assert_equal_rexml(<<-eoxml) + def test_products_node_with_book_node_as_hash + assert_equal_rexml(<<-eoxml) <products> <book name="awesome" id="12345" /> </products> - eoxml - end + eoxml + end - def test_products_node_with_two_book_nodes_as_hash - assert_equal_rexml(<<-eoxml) + def test_products_node_with_two_book_nodes_as_hash + assert_equal_rexml(<<-eoxml) <products> <book name="awesome" id="12345" /> <book name="america" id="67890" /> </products> - eoxml - end + eoxml + end - def test_single_node_with_content_as_hash - assert_equal_rexml(<<-eoxml) + def test_single_node_with_content_as_hash + assert_equal_rexml(<<-eoxml) <products> hello world </products> - eoxml - end + eoxml + end - def test_children_with_children - assert_equal_rexml(<<-eoxml) + def test_children_with_children + assert_equal_rexml(<<-eoxml) <root> <products> <book name="america" id="67890" /> </products> </root> - eoxml - end + eoxml + end - def test_children_with_text - assert_equal_rexml(<<-eoxml) + def test_children_with_text + assert_equal_rexml(<<-eoxml) <root> <products> hello everyone </products> </root> - eoxml - end + eoxml + end - def test_children_with_non_adjacent_text - assert_equal_rexml(<<-eoxml) + def test_children_with_non_adjacent_text + assert_equal_rexml(<<-eoxml) <root> good <products> @@ -139,15 +138,15 @@ class JDOMEngineTest < Test::Unit::TestCase </products> morning </root> - eoxml - end + eoxml + end - private - def assert_equal_rexml(xml) - hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) } - assert_equal(hash, XmlMini.parse(xml)) + private + def assert_equal_rexml(xml) + hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) } + assert_equal(hash, XmlMini.parse(xml)) + end end -end else # don't run these test because we aren't running in JRuby diff --git a/railties/Rakefile b/railties/Rakefile index 827b2ba0cd..be9a77d4e4 100755 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -1,6 +1,6 @@ #!/usr/bin/env rake require 'rake/testtask' -require 'rake/gempackagetask' +require 'rubygems/package_task' require 'date' require 'rbconfig' @@ -55,7 +55,7 @@ end spec = eval(File.read('railties.gemspec')) -Rake::GemPackageTask.new(spec) do |pkg| +Gem::PackageTask.new(spec) do |pkg| pkg.gem_spec = spec end diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 99527bb051..953233d774 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -50,7 +50,9 @@ module Rails end end - attr_accessor :assets + attr_accessor :assets, :sandbox + alias_method :sandbox?, :sandbox + delegate :default_url_options, :default_url_options=, :to => :routes # This method is called just after an application inherits from Rails::Application, @@ -96,24 +98,25 @@ module Rails self end - def load_tasks + def load_tasks(app=self) initialize_tasks - railties.all { |r| r.load_tasks } + railties.all { |r| r.load_tasks(app) } super self end - def load_generators + def load_generators(app=self) initialize_generators - railties.all { |r| r.load_generators } + railties.all { |r| r.load_generators(app) } + Rails::Generators.configure!(app.config.generators) super self end - def load_console(sandbox=false) - initialize_console(sandbox) - railties.all { |r| r.load_console(sandbox) } - super() + def load_console(app=self) + initialize_console + railties.all { |r| r.load_console(app) } + super self end @@ -196,7 +199,7 @@ module Rails require "rails/generators" end - def initialize_console(sandbox=false) + def initialize_console require "pp" require "rails/console/app" require "rails/console/helpers" diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index 4a082aedb8..39627a3094 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -15,6 +15,8 @@ command = aliases[command] || command case command when 'generate', 'destroy', 'plugin' + require 'rails/generators' + if command == 'plugin' && ARGV.first == 'new' require "rails/commands/plugin_new" else @@ -22,7 +24,9 @@ when 'generate', 'destroy', 'plugin' Rails.application.require_environment! if defined?(ENGINE_PATH) && engine = Rails::Engine.find(ENGINE_PATH) - Rails.application = engine + Rails.application.load_generators(engine) + else + Rails.application.load_generators end require "rails/commands/#{command}" diff --git a/railties/lib/rails/commands/application.rb b/railties/lib/rails/commands/application.rb index f3fa1fd54d..1cf23a8b92 100644 --- a/railties/lib/rails/commands/application.rb +++ b/railties/lib/rails/commands/application.rb @@ -12,7 +12,6 @@ else end require 'rubygems' if ARGV.include?("--dev") - require 'rails/generators' require 'rails/generators/rails/app/app_generator' diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb index 66dbb5d11e..32e361d421 100644 --- a/railties/lib/rails/commands/console.rb +++ b/railties/lib/rails/commands/console.rb @@ -23,7 +23,8 @@ module Rails opt.parse!(ARGV) end - @app.load_console(options[:sandbox]) + @app.sandbox = options[:sandbox] + @app.load_console if options[:debugger] begin diff --git a/railties/lib/rails/commands/destroy.rb b/railties/lib/rails/commands/destroy.rb index 2a84e2a6df..ae354eca97 100644 --- a/railties/lib/rails/commands/destroy.rb +++ b/railties/lib/rails/commands/destroy.rb @@ -1,8 +1,6 @@ require 'rails/generators' require 'active_support/core_ext/object/inclusion' -Rails::Generators.configure! - if ARGV.first.in?([nil, "-h", "--help"]) Rails::Generators.help 'destroy' exit diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb index 28c1c56352..b6f9a003d1 100644 --- a/railties/lib/rails/commands/generate.rb +++ b/railties/lib/rails/commands/generate.rb @@ -1,8 +1,6 @@ require 'rails/generators' require 'active_support/core_ext/object/inclusion' -Rails::Generators.configure! - if ARGV.first.in?([nil, "-h", "--help"]) Rails::Generators.help 'generate' exit diff --git a/railties/lib/rails/commands/plugin_new.rb b/railties/lib/rails/commands/plugin_new.rb index 8baa8ebfd4..0287ba0638 100644 --- a/railties/lib/rails/commands/plugin_new.rb +++ b/railties/lib/rails/commands/plugin_new.rb @@ -1,3 +1,5 @@ +require 'rubygems' if ARGV.include?("--dev") + if ARGV.first != "new" ARGV[0] = "--help" else @@ -6,5 +8,4 @@ end require 'rails/generators' require 'rails/generators/rails/plugin_new/plugin_new_generator' - -Rails::Generators::PluginNewGenerator.start +Rails::Generators::PluginNewGenerator.start
\ No newline at end of file diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 66fab0a760..f8ad17773a 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -43,6 +43,7 @@ module Rails class Generators #:nodoc: attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging + attr_reader :hidden_namespaces def initialize @aliases = Hash.new { |h,k| h[k] = {} } @@ -50,6 +51,7 @@ module Rails @fallbacks = {} @templates = [] @colorize_logging = true + @hidden_namespaces = [] end def initialize_copy(source) @@ -59,6 +61,10 @@ module Rails @templates = @templates.dup end + def hide_namespace(namespace) + @hidden_namespaces << namespace + end + def method_missing(method, *args) method = method.to_s.sub(/=$/, '').to_sym diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 81a0350724..0d01a818f5 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -387,7 +387,7 @@ module Rails delegate :middleware, :root, :paths, :to => :config delegate :engine_name, :isolated?, :to => "self.class" - def load_tasks + def load_tasks(*) super paths["lib/tasks"].existent.sort.each { |ext| load(ext) } end diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 85c67af19a..09e505a75b 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -57,7 +57,7 @@ module Rails :resource_controller => :controller, :scaffold_controller => :scaffold_controller, :stylesheets => true, - :stylesheet_engine => nil, + :stylesheet_engine => :css, :test_framework => false, :template_engine => :erb }, @@ -68,13 +68,14 @@ module Rails } } - def self.configure!(config = Rails.application.config.generators) #:nodoc: + def self.configure!(config) #:nodoc: no_color! unless config.colorize_logging aliases.deep_merge! config.aliases options.deep_merge! config.options fallbacks.merge! config.fallbacks templates_path.concat config.templates templates_path.uniq! + hide_namespaces *config.hidden_namespaces end def self.templates_path @@ -175,6 +176,7 @@ module Rails orm = options[:rails][:orm] test = options[:rails][:test_framework] template = options[:rails][:template_engine] + css = options[:rails][:stylesheet_engine] [ "rails", @@ -194,7 +196,11 @@ module Rails "#{test}:plugin", "#{template}:controller", "#{template}:scaffold", - "#{template}:mailer" + "#{template}:mailer", + "#{css}:scaffold", + "#{css}:assets", + "css:assets", + "css:scaffold" ] end end @@ -280,7 +286,6 @@ module Rails # Receives namespaces in an array and tries to find matching generators # in the load path. def self.lookup(namespaces) #:nodoc: - load_generators_from_railties! paths = namespaces_to_paths(namespaces) paths.each do |raw_path| @@ -304,8 +309,6 @@ module Rails # This will try to load any generator in the load path to show in help. def self.lookup! #:nodoc: - load_generators_from_railties! - $LOAD_PATH.each do |base| Dir[File.join(base, "{rails/generators,generators}", "**", "*_generator.rb")].each do |path| begin @@ -318,13 +321,6 @@ module Rails end end - # Allow generators to be loaded from custom paths. - def self.load_generators_from_railties! #:nodoc: - return if defined?(@generators_from_railties) || Rails.application.nil? - @generators_from_railties = true - Rails.application.load_generators - end - # Convert namespaces to paths by replacing ":" for "/" and adding # an extra lookup. For example, "rails:model" should be searched # in both: "rails/model/model_generator" and "rails/model_generator". diff --git a/railties/lib/rails/generators/css/assets/assets_generator.rb b/railties/lib/rails/generators/css/assets/assets_generator.rb new file mode 100644 index 0000000000..492177ca2e --- /dev/null +++ b/railties/lib/rails/generators/css/assets/assets_generator.rb @@ -0,0 +1,13 @@ +require "rails/generators/named_base" + +module Css + module Generators + class AssetsGenerator < Rails::Generators::NamedBase + source_root File.expand_path("../templates", __FILE__) + + def copy_stylesheet + copy_file "stylesheet.css", File.join('app/assets/stylesheets', class_path, "#{file_name}.css") + end + end + end +end diff --git a/railties/lib/rails/generators/rails/assets/templates/stylesheet.css.scss b/railties/lib/rails/generators/css/assets/templates/stylesheet.css index ba95e217cc..afad32db02 100644 --- a/railties/lib/rails/generators/rails/assets/templates/stylesheet.css.scss +++ b/railties/lib/rails/generators/css/assets/templates/stylesheet.css @@ -1,5 +1,4 @@ -/* +/* Place all the styles related to the matching controller here. They will automatically be included in application.css. - You can use Sass (SCSS) here: http://sass-lang.com/ */ diff --git a/railties/lib/rails/generators/css/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/css/scaffold/scaffold_generator.rb new file mode 100644 index 0000000000..1d7fe9fac0 --- /dev/null +++ b/railties/lib/rails/generators/css/scaffold/scaffold_generator.rb @@ -0,0 +1,16 @@ +require "rails/generators/named_base" + +module Css + module Generators + class ScaffoldGenerator < Rails::Generators::NamedBase + # In order to allow the Sass generators to pick up the default Rails CSS and + # transform it, we leave it in a standard location for the CSS stylesheet + # generators to handle. For the simple, default case, just copy it over. + def copy_stylesheet + dir = Rails::Generators::ScaffoldGenerator.source_root + file = File.join(dir, "scaffold.css") + create_file "app/assets/stylesheets/scaffold.css", File.read(file) + end + end + end +end diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index cf5bf9ca57..ebe38bf8e6 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -7,7 +7,7 @@ source 'http://rubygems.org' <%= "gem 'jruby-openssl'\n" if defined?(JRUBY_VERSION) -%> # Asset template engines <%= "gem 'json'\n" if RUBY_VERSION < "1.9.2" -%> -gem 'sass' +gem 'sass-rails' gem 'coffee-script' gem 'uglifier' diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index 8ff80c6fd3..a097c77391 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -39,17 +39,6 @@ module <%= app_const_base %> # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de - # Please note that JavaScript expansions are *ignored altogether* if the asset - # pipeline is enabled (see config.assets.enabled below). Put your defaults in - # app/assets/javascripts/application.js in that case. - # - # JavaScript files you want as :defaults (application.js is always included). -<% if options[:skip_javascript] -%> - # config.action_view.javascript_expansions[:defaults] = %w() -<% else -%> - # config.action_view.javascript_expansions[:defaults] = %w(prototype prototype_ujs) -<% end -%> - # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 066aa54862..dcf4ace264 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -21,4 +21,7 @@ # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin + + # Do not compress assets + config.assets.compress = false end diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index 1c3dc1117f..60e26755fe 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -11,9 +11,11 @@ # Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_assets = false - # Compress both stylesheets and JavaScripts + # Compress JavaScripts and CSS + config.assets.compress = true + + # Specify the default JavaScript compressor config.assets.js_compressor = :uglifier - config.assets.css_compressor = :scss # Specifies the header that your server uses for sending files # (comment out if your front-end server doesn't support this) diff --git a/railties/lib/rails/generators/rails/assets/assets_generator.rb b/railties/lib/rails/generators/rails/assets/assets_generator.rb index 2d52da77eb..db3422fe83 100644 --- a/railties/lib/rails/generators/rails/assets/assets_generator.rb +++ b/railties/lib/rails/generators/rails/assets/assets_generator.rb @@ -13,12 +13,6 @@ module Rails File.join('app/assets/javascripts', class_path, "#{asset_name}.#{javascript_extension}") end - def create_stylesheet_files - return unless options.stylesheets? - copy_file "stylesheet.#{stylesheet_extension}", - File.join('app/assets/stylesheets', class_path, "#{asset_name}.#{stylesheet_extension}") - end - protected def asset_name @@ -30,9 +24,8 @@ module Rails "js.#{options.javascript_engine}" : "js" end - def stylesheet_extension - options.stylesheet_engine.present? ? - "css.#{options.stylesheet_engine}" : "css" + hook_for :stylesheet_engine do |stylesheet_engine| + invoke stylesheet_engine, [name] if options[:stylesheets] end end end diff --git a/railties/lib/rails/generators/rails/plugin/USAGE b/railties/lib/rails/generators/rails/plugin/USAGE deleted file mode 100644 index 1bcfcf190d..0000000000 --- a/railties/lib/rails/generators/rails/plugin/USAGE +++ /dev/null @@ -1,13 +0,0 @@ -Description: - Stubs out a new plugin at vendor/plugins. Pass the plugin name, either - CamelCased or under_scored, as an argument. - -Example: - `rails generate plugin BrowserFilters` - - creates a standard browser_filters plugin: - vendor/plugins/browser_filters/README - vendor/plugins/browser_filters/init.rb - vendor/plugins/browser_filters/install.rb - vendor/plugins/browser_filters/lib/browser_filters.rb - vendor/plugins/browser_filters/test/browser_filters_test.rb diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb deleted file mode 100644 index 97f681d826..0000000000 --- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb +++ /dev/null @@ -1,54 +0,0 @@ - -require 'rails/generators/rails/generator/generator_generator' - -module Rails - module Generators - class PluginGenerator < NamedBase - class_option :tasks, :desc => "When supplied creates tasks base files." - - def show_deprecation - return unless behavior == :invoke - message = "Plugin generator is deprecated, please use 'rails plugin new' command to generate plugin structure." - ActiveSupport::Deprecation.warn message - end - - check_class_collision - - def create_root_files - directory '.', plugin_dir, :recursive => false - end - - def create_lib_files - directory 'lib', plugin_dir('lib'), :recursive => false - end - - def create_tasks_files - return unless options[:tasks] - directory 'lib/tasks', plugin_dir('lib/tasks') - end - - hook_for :generator do |generator| - inside plugin_dir, :verbose => true do - invoke generator, [ name ], :namespace => false - end - end - - hook_for :test_framework do |test_framework| - inside plugin_dir, :verbose => true do - invoke test_framework - end - end - - protected - - def plugin_dir(join=nil) - if join - File.join(plugin_dir, join) - else - "vendor/plugins/#{file_name}" - end - end - - end - end -end diff --git a/railties/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt b/railties/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt deleted file mode 100644 index 8717df053d..0000000000 --- a/railties/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) <%= Date.today.year %> [name of plugin creator] - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/railties/lib/rails/generators/rails/plugin/templates/README.tt b/railties/lib/rails/generators/rails/plugin/templates/README.tt deleted file mode 100644 index 702db07cb1..0000000000 --- a/railties/lib/rails/generators/rails/plugin/templates/README.tt +++ /dev/null @@ -1,13 +0,0 @@ -<%= class_name %> -<%= "=" * class_name.size %> - -Introduction goes here. - - -Example -======= - -Example goes here. - - -Copyright (c) <%= Date.today.year %> [name of plugin creator], released under the MIT license diff --git a/railties/lib/rails/generators/rails/plugin/templates/Rakefile.tt b/railties/lib/rails/generators/rails/plugin/templates/Rakefile.tt deleted file mode 100644 index 77149ae351..0000000000 --- a/railties/lib/rails/generators/rails/plugin/templates/Rakefile.tt +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env rake -require 'rake/testtask' -require 'rake/rdoctask' - -desc 'Default: run unit tests.' -task :default => :test - -desc 'Test the <%= file_name %> plugin.' -Rake::TestTask.new(:test) do |t| - t.libs << 'lib' - t.libs << 'test' - t.pattern = 'test/**/*_test.rb' - t.verbose = true -end - -desc 'Generate documentation for the <%= file_name %> plugin.' -Rake::RDocTask.new(:rdoc) do |rdoc| - rdoc.rdoc_dir = 'rdoc' - rdoc.title = '<%= class_name %>' - rdoc.options << '--line-numbers' << '--inline-source' - rdoc.rdoc_files.include('README') - rdoc.rdoc_files.include('lib/**/*.rb') -end
\ No newline at end of file diff --git a/railties/lib/rails/generators/rails/plugin/templates/init.rb b/railties/lib/rails/generators/rails/plugin/templates/init.rb deleted file mode 100644 index 3c19a743c9..0000000000 --- a/railties/lib/rails/generators/rails/plugin/templates/init.rb +++ /dev/null @@ -1 +0,0 @@ -# Include hook code here diff --git a/railties/lib/rails/generators/rails/plugin/templates/install.rb b/railties/lib/rails/generators/rails/plugin/templates/install.rb deleted file mode 100644 index f7732d3796..0000000000 --- a/railties/lib/rails/generators/rails/plugin/templates/install.rb +++ /dev/null @@ -1 +0,0 @@ -# Install hook code here diff --git a/railties/lib/rails/generators/rails/plugin/templates/lib/%file_name%.rb.tt b/railties/lib/rails/generators/rails/plugin/templates/lib/%file_name%.rb.tt deleted file mode 100644 index d8d908a959..0000000000 --- a/railties/lib/rails/generators/rails/plugin/templates/lib/%file_name%.rb.tt +++ /dev/null @@ -1 +0,0 @@ -# <%= class_name %> diff --git a/railties/lib/rails/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt b/railties/lib/rails/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt deleted file mode 100644 index 72920a9d3a..0000000000 --- a/railties/lib/rails/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt +++ /dev/null @@ -1,4 +0,0 @@ -# desc "Explaining what the task does" -# task :<%= file_name %> do -# # Task goes here -# end diff --git a/railties/lib/rails/generators/rails/plugin/templates/uninstall.rb b/railties/lib/rails/generators/rails/plugin/templates/uninstall.rb deleted file mode 100644 index 9738333463..0000000000 --- a/railties/lib/rails/generators/rails/plugin/templates/uninstall.rb +++ /dev/null @@ -1 +0,0 @@ -# Uninstall hook code here diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 9ddb3cae33..4967d1793c 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -202,7 +202,7 @@ task :default => :test end def create_test_dummy_files - return if options[:skip_test_unit] + return if options[:skip_test_unit] && options[:dummy_path] == 'test/dummy' create_dummy_app end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile b/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile index 5704e75a29..1bf9c8c831 100755 --- a/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile +++ b/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile @@ -5,9 +5,9 @@ rescue LoadError puts 'You must `gem install bundler` and `bundle install` to run rake tasks' end -require 'rake/rdoctask' +require 'rdoc/task' -Rake::RDocTask.new(:rdoc) do |rdoc| +RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = '<%= camelized %>' rdoc.options << '--line-numbers' << '--inline-source' diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb index aa9b45c5a5..03a61a035e 100644 --- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb @@ -11,21 +11,12 @@ module Rails hook_for :scaffold_controller, :required => true - def copy_stylesheets_file - if behavior == :invoke && options.stylesheets? - template "scaffold.#{stylesheet_extension}", "app/assets/stylesheets/scaffold.#{stylesheet_extension}" - end - end - hook_for :assets do |assets| invoke assets, [controller_name] end - private - - def stylesheet_extension - options.stylesheet_engine.present? ? - "css.#{options.stylesheet_engine}" : "css" + hook_for :stylesheet_engine do |stylesheet_engine| + invoke stylesheet_engine, [controller_name] if options[:stylesheets] && behavior == :invoke end end end diff --git a/railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss b/railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss deleted file mode 100644 index 45116b53f6..0000000000 --- a/railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss +++ /dev/null @@ -1,58 +0,0 @@ -body { background-color: #fff; color: #333; } - -body, p, ol, ul, td { - font-family: verdana, arial, helvetica, sans-serif; - font-size: 13px; - line-height: 18px; -} - -pre { - background-color: #eee; - padding: 10px; - font-size: 11px; -} - -a { - color: #000; - &:visited { color: #666; } - &:hover { color: #fff; background-color:#000; } -} - -div.field, div.actions { - margin-bottom: 10px; -} - -#notice { - color: green; -} - -.field_with_errors { - padding: 2px; - background-color: red; - display: table; -} - -#error_explanation { - width: 450px; - border: 2px solid red; - padding: 7px; - padding-bottom: 0; - margin-bottom: 20px; - background-color: #f0f0f0; - - h2 { - text-align: left; - font-weight: bold; - padding: 5px 5px 5px 15px; - font-size: 12px; - margin: -7px; - margin-bottom: 0px; - background-color: #c00; - color: #fff; - } - - ul li { - font-size: 12px; - list-style: square; - } -}
\ No newline at end of file diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 5d217dcb10..09ff0ef378 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -2,29 +2,11 @@ require 'set' module Rails module Paths - module PathParent #:nodoc: - def method_missing(id, *args) - match = id.to_s.match(/^(.*)=$/) - full = [@current, $1 || id].compact.join("/") - - ActiveSupport::Deprecation.warn 'config.paths.app.controller API is deprecated in ' << - 'favor of config.paths["app/controller"] API.' - - if match || args.any? - @root[full] = Path.new(@root, full, *args) - elsif path = @root[full] - path - else - super - end - end - end - # This object is an extended hash that behaves as root of the Rails::Paths system. # It allows you to collect information about how you want to structure your application # paths by a Hash like API. It requires you to give a physical path on initialization. # - # root = Root.new + # root = Root.new "/rails" # root.add "app/controllers", :eager_load => true # # The command above creates a new root object and add "app/controllers" as a path. @@ -54,8 +36,7 @@ module Rails # # Finally, the Path object also provides a few helpers: # - # root = Root.new - # root.path = "/rails" + # root = Root.new "/rails" # root.add "app/controllers" # # root["app/controllers"].expanded # => ["/rails/app/controllers"] @@ -63,11 +44,10 @@ module Rails # # Check the Path documentation for more information. class Root < ::Hash - include PathParent attr_accessor :path def initialize(path) - raise if path.is_a?(Array) + raise "Argument should be a String of the physical root path" if path.is_a?(Array) @current = nil @path = path @root = self @@ -121,8 +101,6 @@ module Rails end class Path < Array - include PathParent - attr_reader :path attr_accessor :glob @@ -194,11 +172,6 @@ module Rails expanded.select { |f| File.exists?(f) } end - def paths - ActiveSupport::Deprecation.warn "paths is deprecated. Please call expand instead." - expanded - end - alias to_a expanded end end diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 0a65840c2b..65c567d72f 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -173,24 +173,24 @@ module Rails def eager_load! end - def load_console(sandbox=false) - self.class.console.each { |block| block.call(sandbox) } + def load_console(app) + self.class.console.each { |block| block.call(app) } end - def load_tasks + def load_tasks(app) extend Rake::DSL if defined? Rake::DSL - self.class.rake_tasks.each(&:call) + self.class.rake_tasks.each { |block| block.call(app) } # load also tasks from all superclasses klass = self.class.superclass while klass.respond_to?(:rake_tasks) - klass.rake_tasks.each { |t| self.instance_exec(&t) } + klass.rake_tasks.each { |t| self.instance_exec(app, &t) } klass = klass.superclass end end - def load_generators - self.class.generators.each(&:call) + def load_generators(app) + self.class.generators.each { |block| block.call(app) } end end end diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/lib/rails/railtie/configuration.rb index bfd2a73aeb..f888684117 100644 --- a/railties/lib/rails/railtie/configuration.rb +++ b/railties/lib/rails/railtie/configuration.rb @@ -26,11 +26,6 @@ module Rails @@app_generators end - def generators(&block) #:nodoc - ActiveSupport::Deprecation.warn "config.generators in Rails::Railtie is deprecated. Please use config.app_generators instead." - app_generators(&block) - end - # First configurable block to run. Called before any initializers are run. def before_configuration(&block) ActiveSupport.on_load(:before_configuration, :yield => true, &block) diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake index edd716d7d0..c8b4040151 100644 --- a/railties/lib/rails/tasks/documentation.rake +++ b/railties/lib/rails/tasks/documentation.rake @@ -1,7 +1,7 @@ -require 'rake/rdoctask' +require 'rdoc/task' # Monkey-patch to remove redoc'ing and clobber descriptions to cut down on rake -T noise -class RDocTaskWithoutDescriptions < Rake::RDocTask +class RDocTaskWithoutDescriptions < RDoc::Task def define task rdoc_task_name diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index 5ae6323345..db8f1f2ac6 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -10,7 +10,8 @@ class ConsoleTest < Test::Unit::TestCase def load_environment(sandbox = false) require "#{rails_root}/config/environment" - Rails.application.load_console(sandbox) + Rails.application.sandbox = sandbox + Rails.application.load_console end def test_app_method_should_return_integration_session @@ -78,8 +79,8 @@ class ConsoleTest < Test::Unit::TestCase value = false Class.new(Rails::Railtie) do - console do |sandbox| - value = sandbox + console do |app| + value = app.sandbox? end end diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index 8b840fffd0..1ca9515335 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -68,8 +68,7 @@ module ApplicationTests # Initialize the application require "#{app_path}/config/environment" - require "rails/generators" - Rails::Generators.configure! + Rails.application.load_generators assert_equal :rspec, Rails::Generators.options[:rails][:test_framework] assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework] @@ -84,8 +83,7 @@ module ApplicationTests # Initialize the application require "#{app_path}/config/environment" - require "rails/generators" - Rails::Generators.configure! + Rails.application.load_generators assert_equal Thor::Base.shell, Thor::Shell::Basic end diff --git a/railties/test/application/paths_test.rb b/railties/test/application/paths_test.rb index b1ff6e9cb1..03e0247556 100644 --- a/railties/test/application/paths_test.rb +++ b/railties/test/application/paths_test.rb @@ -61,7 +61,7 @@ module ApplicationTests end test "environments has a glob equal to the current environment" do - assert_equal "#{Rails.env}.rb", @paths.config.environments.glob + assert_equal "#{Rails.env}.rb", @paths["config/environments"].glob end test "load path includes each of the paths in config.paths as long as the directories exist" do diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 03353301cb..c31c65a27d 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -174,7 +174,6 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_jquery_is_the_default_javascript_library run_generator - assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype prototype_ujs\)/ assert_file "app/assets/javascripts/application.js" do |contents| assert_match %r{^//= require jquery}, contents assert_match %r{^//= require jquery_ujs}, contents @@ -186,7 +185,6 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_other_javascript_libraries run_generator [destination_root, '-j', 'prototype'] - assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype prototype_ujs\)/ assert_file "app/assets/javascripts/application.js" do |contents| assert_match %r{^//= require prototype}, contents assert_match %r{^//= require prototype_ujs}, contents @@ -198,7 +196,6 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_javascript_is_skipped_if_required run_generator [destination_root, "--skip-javascript"] - assert_file "config/application.rb", /^\s+# config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(\)/ assert_file "app/assets/javascripts/application.js" do |contents| assert_no_match %r{^//=\s+require\s}, contents end diff --git a/railties/test/generators/assets_generator_test.rb b/railties/test/generators/assets_generator_test.rb index 375632e5bc..2d20982d04 100644 --- a/railties/test/generators/assets_generator_test.rb +++ b/railties/test/generators/assets_generator_test.rb @@ -9,17 +9,17 @@ class AssetsGeneratorTest < Rails::Generators::TestCase def test_assets run_generator assert_file "app/assets/javascripts/posts.js.coffee" - assert_file "app/assets/stylesheets/posts.css.scss" + assert_file "app/assets/stylesheets/posts.css" end def test_skipping_assets content = run_generator ["posts", "--no-stylesheets", "--no-javascripts"] assert_no_file "app/assets/javascripts/posts.js.coffee" - assert_no_file "app/assets/stylesheets/posts.css.scss" + assert_no_file "app/assets/stylesheets/posts.css" end def test_vanilla_assets - run_generator ["posts", "--no-javascript-engine", "--no-stylesheet-engine"] + run_generator ["posts", "--no-javascript-engine"] assert_file "app/assets/javascripts/posts.js" assert_file "app/assets/stylesheets/posts.css" end diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index 46533b70be..3adf7be118 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -40,7 +40,7 @@ class ControllerGeneratorTest < Rails::Generators::TestCase def test_invokes_assets run_generator assert_file "app/assets/javascripts/account.js.coffee" - assert_file "app/assets/stylesheets/account.css.scss" + assert_file "app/assets/stylesheets/account.css" end def test_invokes_default_test_framework diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index 1b9a8fd8a7..7fdd54fc30 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -12,7 +12,7 @@ Rails.application.config.generators.templates = [File.join(Rails.root, "lib", "t # Call configure to load the settings from # Rails.application.config.generators to Rails::Generators -Rails::Generators.configure! +Rails.application.load_generators require 'active_record' require 'action_dispatch' diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb index 6f8a9b4280..17cbac0912 100644 --- a/railties/test/generators/namespaced_generators_test.rb +++ b/railties/test/generators/namespaced_generators_test.rb @@ -252,7 +252,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase assert_file "test/unit/helpers/test_app/product_lines_helper_test.rb" # Stylesheets - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" end def test_scaffold_on_revoke @@ -283,7 +283,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase assert_no_file "test/unit/helpers/test_app/product_lines_helper_test.rb" # Stylesheets (should not be removed) - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" end def test_scaffold_with_namespace_on_invoke @@ -324,7 +324,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase assert_file "test/unit/helpers/test_app/admin/roles_helper_test.rb" # Stylesheets - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" end def test_scaffold_with_namespace_on_revoke @@ -356,6 +356,6 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase assert_no_file "test/unit/helpers/test_app/admin/roles_helper_test.rb" # Stylesheets (should not be removed) - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" end end diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb deleted file mode 100644 index 5c0774ddbd..0000000000 --- a/railties/test/generators/plugin_generator_test.rb +++ /dev/null @@ -1,71 +0,0 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/plugin/plugin_generator' - -class PluginGeneratorTest < Rails::Generators::TestCase - include GeneratorsTestHelper - arguments %w(plugin_fu) - - def test_plugin_skeleton_is_created - silence(:stderr) { run_generator } - year = Date.today.year - - %w( - vendor/plugins - vendor/plugins/plugin_fu - vendor/plugins/plugin_fu/init.rb - vendor/plugins/plugin_fu/install.rb - vendor/plugins/plugin_fu/uninstall.rb - vendor/plugins/plugin_fu/lib - vendor/plugins/plugin_fu/lib/plugin_fu.rb - vendor/plugins/plugin_fu/Rakefile - ).each{ |path| assert_file path } - - %w( - vendor/plugins/plugin_fu/README - ).each{ |path| assert_file path, /PluginFu/ } - - %w( - vendor/plugins/plugin_fu/README - vendor/plugins/plugin_fu/MIT-LICENSE - ).each{ |path| assert_file path, /#{year}/ } - end - - def test_check_class_collision - content = capture(:stderr){ run_generator ["object"] } - assert_match(/The name 'Object' is either already used in your application or reserved/, content) - end - - def test_invokes_default_test_framework - silence(:stderr) { run_generator } - assert_file "vendor/plugins/plugin_fu/test/plugin_fu_test.rb", /class PluginFuTest < ActiveSupport::TestCase/ - assert_file "vendor/plugins/plugin_fu/test/test_helper.rb" - end - - def test_logs_if_the_test_framework_cannot_be_found - content = nil - silence(:stderr) { content = run_generator ["plugin_fu", "--test-framework=rspec"] } - assert_match(/rspec \[not found\]/, content) - end - - def test_creates_tasks_if_required - silence(:stderr) { run_generator ["plugin_fu", "--tasks"] } - assert_file "vendor/plugins/plugin_fu/lib/tasks/plugin_fu_tasks.rake" - end - - def test_creates_generator_if_required - silence(:stderr) { run_generator ["plugin_fu", "--generator"] } - assert_file "vendor/plugins/plugin_fu/lib/generators/templates" - assert_file "vendor/plugins/plugin_fu/lib/generators/plugin_fu_generator.rb", - /class PluginFuGenerator < Rails::Generators::NamedBase/ - end - - def test_plugin_generator_on_revoke - silence(:stderr) { run_generator } - run_generator ["plugin_fu"], :behavior => :revoke - end - - def test_deprecation - output = capture(:stderr) { run_generator } - assert_match(/Plugin generator is deprecated, please use 'rails plugin new' command to generate plugin structure./, output) - end -end diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 60bec5b27f..1b01c9dbc1 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -187,6 +187,13 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_file "spec/dummy/config/application.rb" assert_no_file "test/dummy" end + + def test_creating_dummy_without_tests_but_with_dummy_path + run_generator [destination_root, "--dummy_path", "spec/dummy", "--skip-test-unit"] + assert_file "spec/dummy" + assert_file "spec/dummy/config/application.rb" + assert_no_file "test" + end def test_skipping_gemspec run_generator [destination_root, "--skip-gemspec"] diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 4b07f8bcbe..2135ffac81 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -80,9 +80,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "test/unit/helpers/product_lines_helper_test.rb" # Assets - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" assert_file "app/assets/javascripts/product_lines.js.coffee" - assert_file "app/assets/stylesheets/product_lines.css.scss" + assert_file "app/assets/stylesheets/product_lines.css" end def test_scaffold_on_revoke @@ -113,9 +113,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_no_file "test/unit/helpers/product_lines_helper_test.rb" # Assets - assert_file "app/assets/stylesheets/scaffold.css.scss", /&:visited/ + assert_file "app/assets/stylesheets/scaffold.css", /:visited/ assert_no_file "app/assets/javascripts/product_lines.js.coffee" - assert_no_file "app/assets/stylesheets/product_lines.css.scss" + assert_no_file "app/assets/stylesheets/product_lines.css" end def test_scaffold_with_namespace_on_invoke @@ -189,9 +189,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "test/unit/helpers/admin/roles_helper_test.rb" # Assets - assert_file "app/assets/stylesheets/scaffold.css.scss", /&:visited/ + assert_file "app/assets/stylesheets/scaffold.css", /:visited/ assert_file "app/assets/javascripts/admin/roles.js.coffee" - assert_file "app/assets/stylesheets/admin/roles.css.scss" + assert_file "app/assets/stylesheets/admin/roles.css" end def test_scaffold_with_namespace_on_revoke @@ -223,9 +223,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_no_file "test/unit/helpers/admin/roles_helper_test.rb" # Assets - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" assert_no_file "app/assets/javascripts/admin/roles.js.coffee" - assert_no_file "app/assets/stylesheets/admin/roles.css.scss" + assert_no_file "app/assets/stylesheets/admin/roles.css" end def test_scaffold_generator_on_revoke_does_not_mutilate_legacy_map_parameter @@ -245,27 +245,27 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase def test_scaffold_generator_no_assets run_generator [ "posts", "--no-assets" ] - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" assert_no_file "app/assets/javascripts/posts.js.coffee" - assert_no_file "app/assets/stylesheets/posts.css.scss" + assert_no_file "app/assets/stylesheets/posts.css" end def test_scaffold_generator_no_stylesheets run_generator [ "posts", "--no-stylesheets" ] - assert_no_file "app/assets/stylesheets/scaffold.css.scss" + assert_no_file "app/assets/stylesheets/scaffold.css" assert_file "app/assets/javascripts/posts.js.coffee" - assert_no_file "app/assets/stylesheets/posts.css.scss" + assert_no_file "app/assets/stylesheets/posts.css" end def test_scaffold_generator_no_javascripts run_generator [ "posts", "--no-javascripts" ] - assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/stylesheets/scaffold.css" assert_no_file "app/assets/javascripts/posts.js.coffee" - assert_file "app/assets/stylesheets/posts.css.scss" + assert_file "app/assets/stylesheets/posts.css" end - def test_scaffold_generator_no_negines - run_generator [ "posts", "--no-javascript-engine", "--no-stylesheet-engine" ] + def test_scaffold_generator_no_engines + run_generator [ "posts", "--no-javascript-engine" ] assert_file "app/assets/stylesheets/scaffold.css" assert_file "app/assets/javascripts/posts.js" assert_file "app/assets/stylesheets/posts.css" diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 1264ac7764..301ae80bcf 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -185,13 +185,6 @@ class GeneratorsTest < Rails::Generators::TestCase Rails::Generators.subclasses.delete(WithOptionsGenerator) end - def test_load_generators_from_railties - Rails::Generators::ModelGenerator.expects(:start).with(["Account"], {}) - Rails::Generators.send(:remove_instance_variable, :@generators_from_railties) - Rails.application.expects(:load_generators) - Rails::Generators.invoke("model", ["Account"]) - end - def test_rails_root_templates template = File.join(Rails.root, "lib", "templates", "active_record", "model", "model.rb") diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index 6e4e3446b3..c0f3887263 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -227,57 +227,4 @@ class PathsTest < ActiveSupport::TestCase assert @root["app"].autoload? assert_equal ["/app"], @root.autoload_paths end - - # Deprecated API tests - - test "reading a root level path with assignment" do - @root.add "app" - assert_deprecated do - assert_equal ["/foo/bar/app"], @root.app.to_a - end - end - - test "creating a root level path with assignment" do - assert_deprecated do - @root.app = "/foo/bar" - end - assert_equal ["/foo/bar"], @root["app"].to_a - end - - test "creating a root level path without assignment" do - assert_deprecated do - @root.app "/foo/bar" - end - assert_equal ["/foo/bar"], @root["app"].to_a - end - - test "reading a nested level path with assignment" do - @root.add "app" - @root.add "app/model" - assert_deprecated do - assert_equal ["/foo/bar/app/model"], @root.app.model.to_a - end - end - - test "creating a nested level path with assignment" do - @root.add "app" - assert_deprecated do - @root.app.model = "/foo/bar" - end - assert_equal ["/foo/bar"], @root["app/model"].to_a - end - - test "creating a nested level path without assignment" do - @root.add "app" - assert_deprecated do - @root.app.model "/foo/bar" - end - assert_equal ["/foo/bar"], @root["app/model"].to_a - end - - test "trying to access a path that does not exist raises NoMethodError" do - assert_deprecated do - assert_raises(NoMethodError) { @root.app } - end - end end diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb index 7ea8364ae9..18fdf59fe3 100644 --- a/railties/test/railties/railtie_test.rb +++ b/railties/test/railties/railtie_test.rb @@ -97,7 +97,7 @@ module RailtiesTest assert !$ran_block require 'rake' require 'rake/testtask' - require 'rake/rdoctask' + require 'rdoc/task' AppTemplate::Application.load_tasks assert $ran_block @@ -121,7 +121,7 @@ module RailtiesTest assert_equal [], $ran_block require 'rake' require 'rake/testtask' - require 'rake/rdoctask' + require 'rdoc/task' AppTemplate::Application.load_tasks assert $ran_block.include?("my_tie") diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index e5debf29ae..659551d08a 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -237,7 +237,7 @@ module RailtiesTest boot_rails require 'rake' - require 'rake/rdoctask' + require 'rdoc/task' require 'rake/testtask' Rails.application.load_tasks Rake::Task[:foo].invoke |