Merge pull request #2784 from chancancode/upgrade-to-rails-master-4-2

[WIP] Upgrade to rails master/4.2
This commit is contained in:
Sam 2014-11-11 09:46:02 +11:00
commit 1a775aa784
15 changed files with 208 additions and 131 deletions

View File

@ -1,5 +1,21 @@
language: ruby
env:
global:
- DISCOURSE_HOSTNAME=www.example.com
- RUBY_GC_MALLOC_LIMIT=50000000
matrix:
- "RAILS_MASTER=1"
- "RAILS_MASTER=0"
matrix:
allow_failures:
- rvm: 2.0.0
env: "RAILS_MASTER=1"
- rvm: 2.1
env: "RAILS_MASTER=1"
fast_finish: true
rvm:
- 2.0.0
- 2.1
@ -11,11 +27,6 @@ sudo: false
cache: bundler
env:
global:
- DISCOURSE_HOSTNAME=www.example.com
- RUBY_GC_MALLOC_LIMIT=50000000
before_install:
- npm i -g jshint
- jshint .

12
Gemfile
View File

@ -4,7 +4,7 @@ source 'https://rubygems.org'
module ::Kernel
def rails_master?
ENV["RAILS_MASTER"]
ENV["RAILS_MASTER"] == '1'
end
end
@ -71,11 +71,11 @@ gem 'seed-fu', '~> 2.3.3'
if rails_master?
gem 'rails', git: 'https://github.com/rails/rails.git'
gem 'actionpack-action_caching', git: 'https://github.com/rails/actionpack-action_caching.git'
else
gem 'rails'
gem 'actionpack-action_caching'
end
gem 'actionpack-action_caching'
gem 'rails-observers'
# Rails 4.1.6+ will relax the mail gem version requirement to `~> 2.5, >= 2.5.4`.
@ -91,7 +91,11 @@ gem 'redis', require: ["redis", "redis/connection/hiredis"]
# We use some ams 0.8.0 features, need to amend code
# to support 0.9 etc, bench needs to run and ensure no
# perf regressions
gem 'active_model_serializers', '~> 0.8.0'
if rails_master?
gem 'active_model_serializers', github: 'rails-api/active_model_serializers', branch: '0-8-stable'
else
gem 'active_model_serializers', '~> 0.8.0'
end
gem 'onebox'

View File

@ -1,63 +1,64 @@
GIT
remote: https://github.com/rails/actionpack-action_caching.git
revision: a9f3f09477b12b51faa6756005eee4103f7f4030
remote: git://github.com/rails-api/active_model_serializers.git
revision: b6b01d0b7396f3deaa6e661cedf4bc5efe2f4525
branch: 0-8-stable
specs:
actionpack-action_caching (1.1.0)
actionpack (>= 4.0.0, < 5.0)
active_model_serializers (0.8.2)
activemodel (>= 3.0)
GIT
remote: https://github.com/rails/rails.git
revision: 316962d0922992fbe756521bd7c94a751aa1253e
revision: aa6637d140c2ebd28bbd23fc250af033a065dbe8
specs:
actionmailer (4.2.0.beta1)
actionpack (= 4.2.0.beta1)
actionview (= 4.2.0.beta1)
activejob (= 4.2.0.beta1)
actionmailer (4.2.0.beta4)
actionpack (= 4.2.0.beta4)
actionview (= 4.2.0.beta4)
activejob (= 4.2.0.beta4)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.2)
actionpack (4.2.0.beta1)
actionview (= 4.2.0.beta1)
activesupport (= 4.2.0.beta1)
rails-dom-testing (~> 1.0, >= 1.0.4)
actionpack (4.2.0.beta4)
actionview (= 4.2.0.beta4)
activesupport (= 4.2.0.beta4)
rack (~> 1.6.0.beta)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.2)
rails-html-sanitizer (~> 1.0)
actionview (4.2.0.beta1)
activesupport (= 4.2.0.beta1)
rails-dom-testing (~> 1.0, >= 1.0.4)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
actionview (4.2.0.beta4)
activesupport (= 4.2.0.beta4)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.2)
rails-html-sanitizer (~> 1.0)
activejob (4.2.0.beta1)
activesupport (= 4.2.0.beta1)
globalid (>= 0.2.3)
activemodel (4.2.0.beta1)
activesupport (= 4.2.0.beta1)
rails-dom-testing (~> 1.0, >= 1.0.4)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
activejob (4.2.0.beta4)
activesupport (= 4.2.0.beta4)
globalid (>= 0.3.0)
activemodel (4.2.0.beta4)
activesupport (= 4.2.0.beta4)
builder (~> 3.1)
activerecord (4.2.0.beta1)
activemodel (= 4.2.0.beta1)
activesupport (= 4.2.0.beta1)
arel (>= 6.0.0.beta1, < 6.1)
activesupport (4.2.0.beta1)
activerecord (4.2.0.beta4)
activemodel (= 4.2.0.beta4)
activesupport (= 4.2.0.beta4)
arel (>= 6.0.0.beta2, < 6.1)
activesupport (4.2.0.beta4)
i18n (>= 0.7.0.beta1, < 0.8)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
rails (4.2.0.beta1)
actionmailer (= 4.2.0.beta1)
actionpack (= 4.2.0.beta1)
actionview (= 4.2.0.beta1)
activejob (= 4.2.0.beta1)
activemodel (= 4.2.0.beta1)
activerecord (= 4.2.0.beta1)
activesupport (= 4.2.0.beta1)
rails (4.2.0.beta4)
actionmailer (= 4.2.0.beta4)
actionpack (= 4.2.0.beta4)
actionview (= 4.2.0.beta4)
activejob (= 4.2.0.beta4)
activemodel (= 4.2.0.beta4)
activerecord (= 4.2.0.beta4)
activesupport (= 4.2.0.beta4)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.0.beta1)
railties (= 4.2.0.beta4)
sprockets-rails (~> 3.0.0.beta1)
railties (4.2.0.beta1)
actionpack (= 4.2.0.beta1)
activesupport (= 4.2.0.beta1)
railties (4.2.0.beta4)
actionpack (= 4.2.0.beta4)
activesupport (= 4.2.0.beta4)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
@ -79,16 +80,13 @@ PATH
GEM
remote: https://rubygems.org/
specs:
active_model_serializers (0.8.2)
activemodel (>= 3.0)
actionpack-action_caching (1.1.1)
actionpack (>= 4.0.0, < 5.0)
addressable (2.3.6)
airbrake (3.1.2)
activesupport
builder
annotate (2.6.5)
activerecord (>= 2.3.0)
rake (>= 0.8.7)
arel (6.0.0.beta1)
arel (6.0.0.beta2)
barber (0.4.2)
ember-source
execjs
@ -114,25 +112,25 @@ GEM
dotenv-deployment (~> 0.0.2)
dotenv-deployment (0.0.2)
email_reply_parser-discourse (0.6)
ember-data-source (1.0.0.beta.9)
ember-data-source (0.14)
ember-source
ember-rails (0.15.0)
ember-rails (0.14.1)
active_model_serializers
barber (>= 0.4.1)
ember-data-source (>= 1.0.0.beta.5)
ember-source (>= 1.1.0)
ember-data-source
ember-source
execjs (>= 1.2)
handlebars-source (> 1.0.0)
handlebars-source
jquery-rails (>= 1.0.17)
railties (>= 3.1)
ember-source (1.6.0.beta.2)
handlebars-source (~> 1.0)
erubis (2.7.0)
eventmachine (1.0.3)
excon (0.39.5)
excon (0.39.6)
execjs (2.2.1)
exifr (1.1.3)
fabrication (2.11.3)
fabrication (2.9.8)
fakeweb (1.3.0)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
@ -146,7 +144,7 @@ GEM
fast_xs (0.8.0)
fastimage (1.6.3)
addressable (~> 2.3, >= 2.3.5)
ffi (1.9.3)
ffi (1.9.5)
flamegraph (0.0.5)
fast_stack
fog (1.22.1)
@ -155,7 +153,7 @@ GEM
fog-json
ipaddress (~> 0.5)
nokogiri (~> 1.5, >= 1.5.11)
fog-brightbox (0.5.0)
fog-brightbox (0.5.1)
fog-core (~> 1.22)
fog-json
inflecto
@ -176,7 +174,7 @@ GEM
gctools (0.2.3)
given_core (3.5.4)
sorcerer (>= 0.3.7)
globalid (0.2.3)
globalid (0.3.0)
activesupport (>= 4.1.0)
guess_html_encoding (0.0.9)
handlebars-source (1.3.0)
@ -205,7 +203,7 @@ GEM
librarian (0.1.2)
highline
thor (~> 0.15)
libv8 (3.16.14.3)
libv8 (3.16.14.7)
listen (0.7.3)
logster (0.1.6)
loofah (2.0.1)
@ -215,15 +213,15 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
memory_profiler (0.0.4)
message_bus (0.9.5)
message_bus (1.0.5)
eventmachine
rack (>= 1.1.3)
redis
metaclass (0.0.4)
method_source (0.8.2)
mime-types (1.25.1)
mini_portile (0.6.0)
minitest (5.4.1)
mini_portile (0.6.1)
minitest (5.4.2)
mocha (1.1.0)
metaclass (~> 0.0.1)
mock_redis (0.13.2)
@ -237,8 +235,8 @@ GEM
net-ssh (>= 2.6.5)
net-ssh (2.9.1)
netrc (0.7.7)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
nokogiri (1.6.4.1)
mini_portile (~> 0.6.0)
nokogumbo (1.1.12)
nokogiri
oauth (0.4.7)
@ -274,7 +272,7 @@ GEM
omniauth-twitter (1.0.1)
multi_json (~> 1.3)
omniauth-oauth (~> 1.0)
onebox (1.4.9)
onebox (1.5.3)
moneta (~> 0.7)
multi_json (~> 1.7)
mustache (~> 0.99)
@ -293,7 +291,7 @@ GEM
pry (>= 0.9.10, < 0.11.0)
pry-rails (0.3.2)
pry (>= 0.9.10)
puma (2.9.0)
puma (2.9.1)
rack (>= 1.1, < 2.0)
qunit-rails (0.0.7)
railties
@ -307,13 +305,13 @@ GEM
rack
rack-test (0.6.2)
rack (>= 1.0)
rails-deprecated_sanitizer (1.0.2)
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.2)
activesupport
rails-dom-testing (1.0.4)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.0)
rails-html-sanitizer (1.0.1)
loofah (~> 2.0)
rails-observers (0.1.2)
activemodel (~> 4.0)
@ -338,29 +336,28 @@ GEM
netrc (~> 0.7)
rinku (1.7.3)
rmmseg-cpp (0.2.9)
rspec (3.0.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-core (3.0.4)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.4)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-collection_matchers (1.0.0)
rspec-expectations (>= 2.99.0.beta1)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rspec-given (3.5.4)
given_core (= 3.5.4)
rspec (>= 2.12)
rspec-mocks (3.0.4)
rspec-support (~> 3.0.0)
rspec-rails (3.0.2)
rspec-mocks (2.99.2)
rspec-rails (2.99.0)
actionpack (>= 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0)
rspec-support (3.0.4)
rspec-collection_matchers
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rtlit (0.0.5)
ruby-openid (2.5.0)
ruby-readability (0.7.0)
@ -370,7 +367,7 @@ GEM
crass (~> 0.2.0)
nokogiri (>= 1.4.4)
nokogumbo (= 1.1.12)
sass (3.4.2)
sass (3.2.19)
seed-fu (2.3.3)
activerecord (>= 3.1, < 4.2)
activesupport (>= 3.1, < 4.2)
@ -380,16 +377,16 @@ GEM
shoulda-context (1.2.1)
shoulda-matchers (2.7.0)
activesupport (>= 3.0.0)
sidekiq (3.2.3)
celluloid (>= 0.15.2)
sidekiq (3.2.5)
celluloid (= 0.15.2)
connection_pool (>= 2.0.0)
json
redis (>= 3.0.6)
redis-namespace (>= 1.3.1)
simple-rss (1.3.1)
simplecov (0.9.0)
simplecov (0.9.1)
docile (~> 1.1.0)
multi_json
multi_json (~> 1.0)
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
sinatra (1.4.5)
@ -402,7 +399,7 @@ GEM
spork-rails (4.0.0)
rails (>= 3.0.0, < 5)
spork (>= 1.0rc0)
sprockets (2.12.1)
sprockets (2.12.3)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
@ -445,9 +442,8 @@ PLATFORMS
ruby
DEPENDENCIES
actionpack-action_caching!
active_model_serializers (~> 0.8.0)
airbrake (= 3.1.2)
actionpack-action_caching
active_model_serializers!
annotate
barber
better_errors
@ -457,7 +453,7 @@ DEPENDENCIES
ember-rails
ember-source (= 1.6.0.beta.2)
eventmachine
fabrication
fabrication (= 2.9.8)
fakeweb (~> 1.3.0)
fast_blank
fast_xor
@ -514,6 +510,7 @@ DEPENDENCIES
rest-client
rinku
rmmseg-cpp
rspec (= 2.99.0)
rspec-given
rspec-rails
rtlit

View File

@ -12,7 +12,7 @@ module HasCustomFields
end
end
CUSTOM_FIELD_TRUE = ['t','true', 'T', 'True', 'TRUE'].freeze unless defined? CUSTOM_FIELD_TRUE
CUSTOM_FIELD_TRUE = ['1', 't', 'true', 'T', 'True', 'TRUE'].freeze unless defined? CUSTOM_FIELD_TRUE
def self.cast_custom_field(key, value, types)
return value unless types && type = types[key]

View File

@ -70,7 +70,7 @@
<span class='footer-notice'>
<%=raw(t :'user_notifications.digest.unsubscribe',
site_link: html_site_link,
unsubscribe_link: link_to(t('user_notifications.digest.click_here'), email_unsubscribe_path(host: Discourse.base_url, key: @user.temporary_key, only_path: false))) %>
unsubscribe_link: link_to(t('user_notifications.digest.click_here'), email_unsubscribe_url(host: Discourse.base_url, key: @user.temporary_key))) %>
</span>
</td>
</tr>

View File

@ -33,7 +33,6 @@
<%=raw(t :'user_notifications.digest.unsubscribe',
site_link: site_link,
unsubscribe_link: raw(@markdown_linker.create(t('user_notifications.digest.click_here'), email_unsubscribe_path(key: @user.temporary_key)))) %>
unsubscribe_link: raw(@markdown_linker.create(t('user_notifications.digest.click_here'), email_unsubscribe_url(key: @user.temporary_key, only_path: true)))) %>
<%= raw(@markdown_linker.references) %>

View File

@ -110,6 +110,11 @@ module Discourse
# see: http://stackoverflow.com/questions/11894180/how-does-one-correctly-add-custom-sql-dml-in-migrations/11894420#11894420
config.active_record.schema_format = :sql
if rails_master?
# Opt-into the default behavior in Rails 5
# config.active_record.raise_in_transactional_callbacks = true
end
# per https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet
config.pbkdf2_iterations = 64000
config.pbkdf2_algorithm = "sha256"

View File

@ -0,0 +1,8 @@
unless rails_master?
class Mail::Message
alias_method :deliver_now, :deliver
alias_method :deliver_now!, :deliver!
end
end

View File

@ -115,7 +115,7 @@ module Email
end
begin
@message.deliver
@message.deliver_now
rescue *SMTP_CLIENT_ERRORS => e
return skip(e.message)
end

View File

@ -1,6 +1,29 @@
if rails_master?
class ActiveRecord::ConnectionAdapters::AbstractAdapter
module LastUseExtension
attr_reader :last_use
def initialize(connection, logger = nil, pool = nil)
super
@last_use = false
end
def lease
synchronize do
unless in_use?
@last_use = Time.now
super
end
end
end
end
prepend LastUseExtension
end
end
class ActiveRecord::ConnectionAdapters::ConnectionPool
# drain all idle connections
# if idle_time is specified only connections idle for N seconds will be drained
def drain(idle_time=nil)
@ -29,5 +52,4 @@ class ActiveRecord::ConnectionAdapters::ConnectionPool
false
end
end

View File

@ -1,4 +1,5 @@
require_dependency 'sass/discourse_sass_importer'
require 'pathname'
class DiscourseSassCompiler
@ -41,7 +42,8 @@ class DiscourseSassCompiler
env = env.instance_variable_get('@environment')
end
context = env.context_class.new(env, "#{@target}.scss", "app/assets/stylesheets/#{@target}.scss")
pathname = Pathname.new("app/assets/stylesheets/#{@target}.scss")
context = env.context_class.new(env, "#{@target}.scss", pathname)
debug_opts = Rails.env.production? ? {} : {
line_numbers: true,

View File

@ -71,11 +71,20 @@ class SqlBuilder
#AS reloads this on tests
remove_const :FTYPE_MAP if defined? FTYPE_MAP
FTYPE_MAP = {
23 => :value_to_integer,
1114 => :string_to_time,
16 => :value_to_boolean
}
if rails_master?
FTYPE_MAP = {
23 => ActiveRecord::Type::Integer.new,
1114 => ActiveRecord::Type::DateTime.new,
16 => ActiveRecord::Type::Boolean.new
}
else
FTYPE_MAP = {
23 => :value_to_integer,
1114 => :string_to_time,
16 => :value_to_boolean
}
end
def self.map_exec(klass, sql, args = {})
self.new(sql).map_exec(klass, args)
@ -93,7 +102,11 @@ class SqlBuilder
setters.each_with_index do |mapper, index|
translated = row[index]
if mapper[1] && !translated.nil?
translated = ActiveRecord::ConnectionAdapters::Column.send mapper[1], translated
if rails_master?
translated = mapper[1].type_cast_from_database(translated)
else
translated = ActiveRecord::ConnectionAdapters::Column.send mapper[1], translated
end
end
mapped.send mapper[0], translated
end

View File

@ -38,7 +38,7 @@ end
message = EmailTestMailer.email_test(MAILFROM, MAILTO)
begin
message.deliver()
message.deliver_now()
rescue SocketError => e
print "Delivery failed: "+e.message.strip()+"\n"
print " Is the server hostname correct?\n"

View File

@ -5,25 +5,25 @@ describe Email::Sender do
it "doesn't deliver mail when mails are disabled" do
SiteSetting.expects(:disable_emails).returns(true)
Mail::Message.any_instance.expects(:deliver).never
Mail::Message.any_instance.expects(:deliver_now).never
message = Mail::Message.new(to: "hello@world.com" , body: "hello")
Email::Sender.new(message, :hello).send
end
it "doesn't deliver mail when the message is nil" do
Mail::Message.any_instance.expects(:deliver).never
Mail::Message.any_instance.expects(:deliver_now).never
Email::Sender.new(nil, :hello).send
end
it "doesn't deliver when the to address is nil" do
message = Mail::Message.new(body: 'hello')
message.expects(:deliver).never
message.expects(:deliver_now).never
Email::Sender.new(message, :hello).send
end
it "doesn't deliver when the body is nil" do
message = Mail::Message.new(to: 'eviltrout@test.domain')
message.expects(:deliver).never
message.expects(:deliver_now).never
Email::Sender.new(message, :hello).send
end
@ -53,14 +53,14 @@ describe Email::Sender do
let(:message) do
message = Mail::Message.new to: 'eviltrout@test.domain',
body: '**hello**'
message.stubs(:deliver)
message.stubs(:deliver_now)
message
end
let(:email_sender) { Email::Sender.new(message, :valid_type) }
it 'calls deliver' do
message.expects(:deliver).once
message.expects(:deliver_now).once
email_sender.send
end
@ -131,7 +131,7 @@ describe Email::Sender do
context 'with a user' do
let(:message) do
message = Mail::Message.new to: 'eviltrout@test.domain', body: 'test body'
message.stubs(:deliver)
message.stubs(:deliver_now)
message
end

View File

@ -112,14 +112,21 @@ describe UserNotifications do
# in mailing list mode user_replies is not sent through
response.user.mailing_list_mode = true
mail = UserNotifications.user_replied(response.user, post: response, notification: notification)
mail.class.should == ActionMailer::Base::NullMail
if rails_master?
mail.message.class.should == ActionMailer::Base::NullMail
else
mail.class.should == ActionMailer::Base::NullMail
end
response.user.mailing_list_mode = nil
mail = UserNotifications.user_replied(response.user, post: response, notification: notification)
mail.class.should_not == ActionMailer::Base::NullMail
if rails_master?
mail.message.class.should_not == ActionMailer::Base::NullMail
else
mail.class.should_not == ActionMailer::Base::NullMail
end
end
end
@ -183,7 +190,16 @@ describe UserNotifications do
def expects_build_with(condition)
UserNotifications.any_instance.expects(:build_email).with(user.email, condition)
UserNotifications.send(mail_type, user, notification: notification, post: notification.post)
mailer = UserNotifications.send(mail_type, user, notification: notification, post: notification.post)
if rails_master?
# Starting from Rails 4.2, calling MyMailer.some_method no longer result
# in an immediate call to MyMailer#some_method. Instead, a "lazy proxy" is
# returned (this is changed to support #deliver_later). As a quick hack to
# fix the test, calling #message (or anything, really) would force the
# Mailer object to be created and the method invoked.
mailer.message
end
end
shared_examples "supports reply by email" do