mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Merge pull request #1066 from rails-api/appveyor
Adding appveyor to the project
This commit is contained in:
commit
af280abbb7
3
Gemfile
3
Gemfile
@ -15,3 +15,6 @@ if version == "master"
|
|||||||
else
|
else
|
||||||
gem "rails", "~> #{version}.0"
|
gem "rails", "~> #{version}.0"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
||||||
|
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
[](https://travis-ci.org/rails-api/active_model_serializers)
|
[](https://travis-ci.org/rails-api/active_model_serializers)
|
||||||
|
|
||||||
|
Windows Build Status - [
|
||||||
|
|
||||||
ActiveModel::Serializer brings convention over configuration to your JSON generation.
|
ActiveModel::Serializer brings convention over configuration to your JSON generation.
|
||||||
|
|
||||||
AMS does this through two components: **serializers** and **adapters**.
|
AMS does this through two components: **serializers** and **adapters**.
|
||||||
|
|||||||
25
appveyor.yml
Normal file
25
appveyor.yml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
version: '{build}'
|
||||||
|
|
||||||
|
skip_tags: true
|
||||||
|
|
||||||
|
environment:
|
||||||
|
matrix:
|
||||||
|
- ruby_version: "193"
|
||||||
|
- ruby_version: "193-x64"
|
||||||
|
- ruby_version: "200"
|
||||||
|
- ruby_version: "200-x64"
|
||||||
|
- ruby_version: "21"
|
||||||
|
- ruby_version: "21-x64"
|
||||||
|
|
||||||
|
install:
|
||||||
|
- SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
|
||||||
|
- ruby --version
|
||||||
|
- gem --version
|
||||||
|
- gem install bundler
|
||||||
|
- bundler --version
|
||||||
|
- bundle install --retry=3
|
||||||
|
|
||||||
|
test_script:
|
||||||
|
- bundle exec rake
|
||||||
|
|
||||||
|
build: off
|
||||||
@ -12,6 +12,22 @@ module ActiveModel
|
|||||||
include Configuration
|
include Configuration
|
||||||
include Associations
|
include Associations
|
||||||
|
|
||||||
|
|
||||||
|
# Matches
|
||||||
|
# "c:/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb:1:in `<top (required)>'"
|
||||||
|
# AND
|
||||||
|
# "/c/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb:1:in `<top (required)>'"
|
||||||
|
# AS
|
||||||
|
# c/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb
|
||||||
|
CALLER_FILE = /
|
||||||
|
\A # start of string
|
||||||
|
\S+ # one or more non-spaces
|
||||||
|
(?= # stop previous match when
|
||||||
|
:\d+ # a colon is followed by one or more digits
|
||||||
|
:in # followed by a colon followed by in
|
||||||
|
)
|
||||||
|
/x
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
attr_accessor :_attributes
|
attr_accessor :_attributes
|
||||||
attr_accessor :_attributes_keys
|
attr_accessor :_attributes_keys
|
||||||
@ -29,8 +45,7 @@ module ActiveModel
|
|||||||
base._attributes = self._attributes.try(:dup) || []
|
base._attributes = self._attributes.try(:dup) || []
|
||||||
base._attributes_keys = self._attributes_keys.try(:dup) || {}
|
base._attributes_keys = self._attributes_keys.try(:dup) || {}
|
||||||
base._urls = []
|
base._urls = []
|
||||||
serializer_file = File.open(caller.first[/^[^:]+/])
|
base._cache_digest = digest_caller_file(caller.first)
|
||||||
base._cache_digest = Digest::MD5.hexdigest(serializer_file.read)
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -161,6 +176,12 @@ module ActiveModel
|
|||||||
@serializers_cache ||= ThreadSafe::Cache.new
|
@serializers_cache ||= ThreadSafe::Cache.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.digest_caller_file(caller_line)
|
||||||
|
serializer_file_path = caller_line[CALLER_FILE]
|
||||||
|
serializer_file_contents = IO.read(serializer_file_path)
|
||||||
|
Digest::MD5.hexdigest(serializer_file_contents)
|
||||||
|
end
|
||||||
|
|
||||||
attr_reader :options
|
attr_reader :options
|
||||||
|
|
||||||
def self.get_serializer_for(klass)
|
def self.get_serializer_for(klass)
|
||||||
|
|||||||
@ -46,7 +46,11 @@ class SerializerGeneratorTest < Rails::Generators::TestCase
|
|||||||
def test_with_no_attributes_does_not_add_extra_space
|
def test_with_no_attributes_does_not_add_extra_space
|
||||||
run_generator ["account"]
|
run_generator ["account"]
|
||||||
assert_file "app/serializers/account_serializer.rb" do |content|
|
assert_file "app/serializers/account_serializer.rb" do |content|
|
||||||
|
if RUBY_PLATFORM =~ /mingw/
|
||||||
|
assert_no_match /\r\n\r\nend/, content
|
||||||
|
else
|
||||||
assert_no_match /\n\nend/, content
|
assert_no_match /\n\nend/, content
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
require 'tempfile'
|
||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class CacheTest < Minitest::Test
|
class CacheTest < Minitest::Test
|
||||||
@ -125,10 +126,34 @@ module ActiveModel
|
|||||||
assert_equal(@blog_serializer.attributes, ActionController::Base.cache_store.fetch(@blog.cache_key_with_digest))
|
assert_equal(@blog_serializer.attributes, ActionController::Base.cache_store.fetch(@blog.cache_key_with_digest))
|
||||||
end
|
end
|
||||||
|
|
||||||
def _cache_digest_definition
|
def test_cache_digest_definition
|
||||||
assert_equal(::Model::FILE_DIGEST, @post_serializer.class._cache_digest)
|
assert_equal(::Model::FILE_DIGEST, @post_serializer.class._cache_digest)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_serializer_file_path_on_nix
|
||||||
|
path = "/Users/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb"
|
||||||
|
caller_line = "#{path}:1:in `<top (required)>'"
|
||||||
|
assert_equal caller_line[ActiveModel::Serializer::CALLER_FILE], path
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_serializer_file_path_on_windows
|
||||||
|
path = "c:/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb"
|
||||||
|
caller_line = "#{path}:1:in `<top (required)>'"
|
||||||
|
assert_equal caller_line[ActiveModel::Serializer::CALLER_FILE], path
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_digest_caller_file
|
||||||
|
contents = "puts 'AMS rocks'!"
|
||||||
|
file = Tempfile.new("some_ruby.rb")
|
||||||
|
file.write(contents)
|
||||||
|
path = file.path
|
||||||
|
caller_line = "#{path}:1:in `<top (required)>'"
|
||||||
|
file.close
|
||||||
|
assert_equal ActiveModel::Serializer.digest_caller_file(caller_line), Digest::MD5.hexdigest(contents)
|
||||||
|
ensure
|
||||||
|
file.unlink
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def render_object_with_cache(obj)
|
def render_object_with_cache(obj)
|
||||||
ActiveModel::SerializableResource.new(obj).serializable_hash
|
ActiveModel::SerializableResource.new(obj).serializable_hash
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user