From f99acebdaa2f64fb4fd1ab6d029a8509a181961a Mon Sep 17 00:00:00 2001 From: Stephan Kaag Date: Tue, 23 Jul 2013 20:42:52 +0200 Subject: [PATCH] Rails 4 updates --- Gemfile | 5 ++--- Gemfile.lock | 15 +++++---------- Gemfile_rails4.lock | 16 ++++------------ app/models/discourse_version_check.rb | 7 ++++--- app/models/topic.rb | 2 +- lib/diff_engine.rb | 2 +- lib/trashable.rb | 12 ++++++++++-- spec/controllers/static_controller_spec.rb | 12 ++++++++++-- spec/models/post_mover_spec.rb | 1 + spec/models/topic_spec.rb | 6 +++--- 10 files changed, 41 insertions(+), 37 deletions(-) diff --git a/Gemfile b/Gemfile index 24e12e0bc..51300610f 100644 --- a/Gemfile +++ b/Gemfile @@ -36,7 +36,6 @@ if rails4? gem 'rails', '4.0.0' gem 'redis-rails', :git => 'git://github.com/SamSaffron/redis-store.git' gem 'rails-observers' - gem 'protected_attributes' gem 'actionpack-action_caching' gem 'seed-fu' , github: 'mbleigh/seed-fu' gem 'spork-rails', :github => 'sporkrb/spork-rails' @@ -62,7 +61,7 @@ gem 'redis' gem 'hiredis' gem 'em-redis' -gem 'active_model_serializers', git: 'https://github.com/rails-api/active_model_serializers.git' +gem 'active_model_serializers' # we had issues with latest, stick to the rev till we figure this out # PR that makes it all hang together welcome @@ -120,7 +119,7 @@ gem 'sinatra', require: nil gem 'slim' # required for sidekiq-web gem 'therubyracer', require: 'v8' gem 'thin', require: false -gem 'diffy', require: false +gem 'diffy', '>= 3.0', require: false gem 'highline', require: false # Gem that enables support for plugins. It is required. diff --git a/Gemfile.lock b/Gemfile.lock index 296c8ab67..5de745416 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -59,13 +59,6 @@ GIT specs: email_reply_parser (0.6) -GIT - remote: https://github.com/rails-api/active_model_serializers.git - revision: fe84e0ad5268f1439123fd9a1f9fd12e25a54cd3 - specs: - active_model_serializers (0.8.1) - activemodel (>= 3.0) - GIT remote: https://github.com/zhangyuan/vestal_versions revision: 0ea75ec4e269b5a9e609639919ade0f36381a446 @@ -114,6 +107,8 @@ GEM active_attr (0.7.0) activemodel (>= 3.0.2, < 4.1) activesupport (>= 3.0.2, < 4.1) + active_model_serializers (0.8.1) + activemodel (>= 3.0) activemodel (3.2.12) activesupport (= 3.2.12) builder (~> 3.0.0) @@ -161,7 +156,7 @@ GEM daemons (1.1.9) debug_inspector (0.0.2) diff-lcs (1.2.4) - diffy (2.1.4) + diffy (3.0.1) em-redis (0.3.0) eventmachine ember-rails (0.10.0) @@ -467,7 +462,7 @@ PLATFORMS DEPENDENCIES active_attr - active_model_serializers! + active_model_serializers activerecord-postgres-hstore airbrake (= 3.1.2) annotate! @@ -476,7 +471,7 @@ DEPENDENCIES binding_of_caller certified clockwork - diffy + diffy (>= 3.0) discourse_emoji! discourse_plugin! em-redis diff --git a/Gemfile_rails4.lock b/Gemfile_rails4.lock index 3afaed13f..0308fcbc6 100644 --- a/Gemfile_rails4.lock +++ b/Gemfile_rails4.lock @@ -89,13 +89,6 @@ GIT specs: email_reply_parser (0.6) -GIT - remote: https://github.com/rails-api/active_model_serializers.git - revision: 8ac4bf90067eef442a6208848f86e55892d724f1 - specs: - active_model_serializers (0.8.1) - activemodel (>= 3.2) - GIT remote: https://github.com/zhangyuan/vestal_versions revision: 0ea75ec4e269b5a9e609639919ade0f36381a446 @@ -139,6 +132,8 @@ GEM rack-test (~> 0.6.2) actionpack-action_caching (1.0.0) actionpack (>= 4.0.0.beta, < 5.0) + active_model_serializers (0.8.1) + activemodel (>= 3.0) activemodel (4.0.0) activesupport (= 4.0.0) builder (~> 3.1.0) @@ -318,8 +313,6 @@ GEM pg (0.15.1) polyglot (0.3.3) progress (2.4.0) - protected_attributes (1.0.3) - activemodel (>= 4.0.0, < 5.0) pry (0.9.12.2) coderay (~> 1.0.5) method_source (~> 0.8) @@ -477,7 +470,7 @@ PLATFORMS DEPENDENCIES actionpack-action_caching - active_model_serializers! + active_model_serializers airbrake (= 3.1.2) annotate! barber @@ -485,7 +478,7 @@ DEPENDENCIES binding_of_caller certified clockwork - diffy + diffy (>= 3.0) discourse_emoji! discourse_plugin! em-redis @@ -525,7 +518,6 @@ DEPENDENCIES omniauth-twitter openid-redis-store pg - protected_attributes pry-nav pry-rails qunit-rails diff --git a/app/models/discourse_version_check.rb b/app/models/discourse_version_check.rb index 8cf79a96b..00e21d04f 100644 --- a/app/models/discourse_version_check.rb +++ b/app/models/discourse_version_check.rb @@ -9,8 +9,9 @@ class DiscourseVersionCheck attr_accessor :latest_version, :critical_updates, :installed_version, :installed_sha, :missing_versions_count, :updated_at - def active_model_serializer - DiscourseVersionCheckSerializer + unless rails4? + def active_model_serializer + DiscourseVersionCheckSerializer + end end - end \ No newline at end of file diff --git a/app/models/topic.rb b/app/models/topic.rb index 56f9f6bbb..090ce6750 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -468,7 +468,7 @@ class Topic < ActiveRecord::Base # Chooses which topic users to feature def feature_topic_users(args={}) - reload + reload unless rails4? # Don't include the OP or the last poster to_feature = posts.where('user_id NOT IN (?, ?)', user_id, last_post_user_id) diff --git a/lib/diff_engine.rb b/lib/diff_engine.rb index bbcd5e573..4de246c35 100644 --- a/lib/diff_engine.rb +++ b/lib/diff_engine.rb @@ -13,7 +13,7 @@ class DiffEngine # # returns: html containing decorations indicating the changes def self.html_diff(html_before, html_after) - Diffy::Diff.new(html_before, html_after).to_s(:html) + Diffy::Diff.new(html_before, html_after, {allow_empty_diff: false}).to_s(:html) end # same as html diff, except that it operates on markdown diff --git a/lib/trashable.rb b/lib/trashable.rb index 37580e4d3..ef6fd7243 100644 --- a/lib/trashable.rb +++ b/lib/trashable.rb @@ -15,13 +15,21 @@ module Trashable # # with this in place Post.limit(10).with_deleted, will work as expected # - scope = self.scoped.with_default_scope + if rails4? + scope = self.all.with_default_scope + else + scope = self.scoped.with_default_scope + end scope.where_values.delete(with_deleted_scope_sql) scope end def with_deleted_scope_sql - scoped.table[:deleted_at].eq(nil).to_sql + if rails4? + all.table[:deleted_at].eq(nil).to_sql + else + scoped.table[:deleted_at].eq(nil).to_sql + end end end diff --git a/spec/controllers/static_controller_spec.rb b/spec/controllers/static_controller_spec.rb index c97c0c233..cad411e07 100644 --- a/spec/controllers/static_controller_spec.rb +++ b/spec/controllers/static_controller_spec.rb @@ -13,7 +13,11 @@ describe StaticController do end it "renders the file" do - response.should render_template('faq') + if rails4? + response.should render_template('static/faq.en') + else + response.should render_template('faq') + end end end @@ -23,7 +27,11 @@ describe StaticController do context "when #{setting_name} site setting is NOT set" do it "renders the #{id} page" do - expect(subject).to render_template(id) + if rails4? + expect(subject).to render_template("static/#{id}.en") + else + expect(subject).to render_template(id) + end end end diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb index 08deeb789..605e2b24a 100644 --- a/spec/models/post_mover_spec.rb +++ b/spec/models/post_mover_spec.rb @@ -147,6 +147,7 @@ describe PostMover do it "copies the OP, doesn't delete it" do new_topic.should be_present + new_topic.posts.reload new_topic.posts.first.raw.should == p1.raw new_topic.reload diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index fd0799245..3f2cb5147 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -661,7 +661,7 @@ describe Topic do end describe 'meta data' do - let(:topic) { Fabricate(:topic, meta_data: {hello: 'world'}) } + let(:topic) { Fabricate(:topic, meta_data: {'hello' => 'world'}) } it 'allows us to create a topic with meta data' do topic.meta_data['hello'].should == 'world' @@ -671,7 +671,7 @@ describe Topic do context 'existing key' do before do - topic.update_meta_data(hello: 'bane') + topic.update_meta_data('hello' => 'bane') end it 'updates the key' do @@ -681,7 +681,7 @@ describe Topic do context 'new key' do before do - topic.update_meta_data(city: 'gotham') + topic.update_meta_data('city' => 'gotham') end it 'adds the new key' do