Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings #1620

Merged
merged 2 commits into from
Mar 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion active_model_serializers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'bundler', '~> 1.6'
spec.add_development_dependency 'simplecov', '~> 0.11'
spec.add_development_dependency 'timecop', '~> 0.7'
spec.add_development_dependency 'minitest-reporters'
spec.add_development_dependency 'grape', ['>= 0.13', '< 1.0']
spec.add_development_dependency 'json_schema'
spec.add_development_dependency 'rake', ['>= 10.0', '< 12.0']
Expand Down
1 change: 1 addition & 0 deletions lib/active_model/serializer/reflection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def initialize(*)
super
@_links = {}
@_include_data = true
@_meta = nil
end

def link(name, value = nil, &block)
Expand Down
9 changes: 3 additions & 6 deletions lib/active_model_serializers/adapter/json_api/link.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'active_support/core_ext/module/delegation'

module ActiveModelSerializers
module Adapter
class JsonApi
Expand Down Expand Up @@ -41,8 +39,7 @@ class JsonApi
# meta: meta,
# }.reject! {|_,v| v.nil? }
class Link
include SerializationContext.url_helpers
delegate :default_url_options, to: SerializationContext
include SerializationContext::UrlHelpers

def initialize(serializer, value)
@object = serializer.object
Expand Down Expand Up @@ -70,8 +67,8 @@ def as_json
return @value if @value

hash = {}
hash[:href] = @href if @href
hash[:meta] = @meta if @meta
hash[:href] = @href if defined?(@href)
hash[:meta] = @meta if defined?(@meta)

hash
end
Expand Down
24 changes: 16 additions & 8 deletions lib/active_model_serializers/serialization_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ module ActiveModelSerializers
class SerializationContext
class << self
attr_writer :url_helpers, :default_url_options
def url_helpers
@url_helpers ||= Module.new
end

def default_url_options
@default_url_options ||= {}
end
end
module UrlHelpers
def self.included(base)
base.send(:include, SerializationContext.url_helpers)
end

def default_url_options
SerializationContext.default_url_options
end
end

attr_reader :request_url, :query_parameters, :key_transform
Expand All @@ -13,13 +29,5 @@ def initialize(request, options = {})
@default_url_options = options.delete(:default_url_options) || self.class.default_url_options
@key_transform = options.delete(:key_transform)
end

def self.url_helpers
@url_helpers ||= Module.new
end

def self.default_url_options
@default_url_options ||= {}
end
end
end
2 changes: 1 addition & 1 deletion test/adapter/json_api/resource_identifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_id_defined_on_serializer
end

def test_id_defined_on_fragmented
FragmentedSerializer.fragmented(WithDefinedIdSerializer.new(@author))
FragmentedSerializer.fragmented(WithDefinedIdSerializer.new(@model))
test_id(FragmentedSerializer, 'special_id')
end

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Schema.define do
self.verbose = false
create_table :posts, force: true do |t|
t.string :title
t.text :body
Expand Down
2 changes: 0 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
# https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest/autorun.rb
# https://github.com/seattlerb/minitest/blob/e21fdda9d/lib/minitest.rb#L45-L59
end
require 'minitest/reporters'
Minitest::Reporters.use!

require 'support/rails_app'

Expand Down