This is the discourse patch to work with ActiveModel::Serializers rewrite branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 81489f460de836707689f235e27364e05a191f9f Mon Sep 17 00:00:00 2001 | |
From: Santiago Pastorino <santiago@wyeworks.com> | |
Date: Thu, 9 Jan 2014 12:24:58 -0200 | |
Subject: [PATCH] Use ActiveModel::Serializers 0.9.0.alpha1 | |
--- | |
Gemfile | 2 +- | |
Gemfile_rails4.lock | 6 +++--- | |
app/models/discourse_version_check.rb | 4 +++- | |
app/serializers/application_serializer.rb | 9 ++++++++- | |
lib/trust_level.rb | 2 ++ | |
spec/controllers/admin/users_controller_spec.rb | 2 +- | |
6 files changed, 18 insertions(+), 7 deletions(-) | |
diff --git a/Gemfile b/Gemfile | |
index 3d27f91..60f048b 100644 | |
--- a/Gemfile | |
+++ b/Gemfile | |
@@ -69,7 +69,7 @@ end | |
gem 'hiredis' | |
gem 'redis', :require => ["redis", "redis/connection/hiredis"] | |
-gem 'active_model_serializers' | |
+gem 'active_model_serializers', '~> 0.9.0.alpha1' | |
gem 'html_truncator' | |
diff --git a/Gemfile_rails4.lock b/Gemfile_rails4.lock | |
index 4fb81a0..47f8a89 100644 | |
--- a/Gemfile_rails4.lock | |
+++ b/Gemfile_rails4.lock | |
@@ -22,8 +22,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) | |
+ active_model_serializers (0.9.0.alpha1) | |
+ activemodel (>= 3.2) | |
activemodel (4.0.2) | |
activesupport (= 4.0.2) | |
builder (~> 3.1.0) | |
@@ -387,7 +387,7 @@ PLATFORMS | |
DEPENDENCIES | |
actionpack-action_caching | |
- active_model_serializers | |
+ active_model_serializers (~> 0.9.0.alpha1) | |
airbrake (= 3.1.2) | |
annotate | |
barber | |
diff --git a/app/models/discourse_version_check.rb b/app/models/discourse_version_check.rb | |
index 01a1a9d..0012190 100644 | |
--- a/app/models/discourse_version_check.rb | |
+++ b/app/models/discourse_version_check.rb | |
@@ -1,4 +1,6 @@ | |
class DiscourseVersionCheck | |
+ include ActiveModel::SerializerSupport | |
+ | |
if rails4? | |
include ActiveModel::Model | |
else | |
@@ -14,4 +16,4 @@ class DiscourseVersionCheck | |
DiscourseVersionCheckSerializer | |
end | |
end | |
-end | |
\ No newline at end of file | |
+end | |
diff --git a/app/serializers/application_serializer.rb b/app/serializers/application_serializer.rb | |
index ad57026..bf6b4e9 100644 | |
--- a/app/serializers/application_serializer.rb | |
+++ b/app/serializers/application_serializer.rb | |
@@ -1,3 +1,10 @@ | |
class ApplicationSerializer < ActiveModel::Serializer | |
- embed :ids, include: true | |
+ embed :ids | |
+ | |
+ def filter(keys) | |
+ keys.select do |name| | |
+ method = "include_#{name}?" | |
+ !respond_to?(method) || send(method) | |
+ end | |
+ end | |
end | |
diff --git a/lib/trust_level.rb b/lib/trust_level.rb | |
index 31de49f..2c9eee2 100644 | |
--- a/lib/trust_level.rb | |
+++ b/lib/trust_level.rb | |
@@ -1,6 +1,8 @@ | |
require_dependency 'enum' | |
class TrustLevel | |
+ include ActiveModel::SerializerSupport | |
+ | |
attr_reader :id, :name | |
class << self | |
diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb | |
index 358aefb..e99fb29 100644 | |
--- a/spec/controllers/admin/users_controller_spec.rb | |
+++ b/spec/controllers/admin/users_controller_spec.rb | |
@@ -66,7 +66,7 @@ describe Admin::UsersController do | |
let(:evil_trout) { Fabricate(:evil_trout) } | |
it 'calls generate_api_key' do | |
- User.any_instance.expects(:generate_api_key).with(@user) | |
+ User.any_instance.expects(:generate_api_key).with(@user).returns(ApiKey.new) | |
xhr :post, :generate_api_key, user_id: evil_trout.id | |
end | |
end | |
-- | |
1.8.5.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment