mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Merge pull request #1358 from rwstauner/dirs-with-spaces
Match file paths with spaces in caller regexp
This commit is contained in:
commit
b3b9a46eeb
@ -27,6 +27,7 @@ Features:
|
||||
Fixes:
|
||||
- [#1239](https://github.com/rails-api/active_model_serializers/pull/1239) Fix duplicates in JSON API compound documents (@beauby)
|
||||
- [#1214](https://github.com/rails-api/active_model_serializers/pull/1214) retrieve the key from the reflection options when building associations (@NullVoxPopuli, @hut8)
|
||||
- [#1358](https://github.com/rails-api/active_model_serializers/pull/1358) Handle serializer file paths with spaces (@rwstauner, @bf4)
|
||||
|
||||
Misc:
|
||||
- [#1233](https://github.com/rails-api/active_model_serializers/pull/1233) Top-level meta and meta_key options no longer handled at serializer level (@beauby)
|
||||
|
||||
@ -23,7 +23,7 @@ module ActiveModel
|
||||
# c/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb
|
||||
CALLER_FILE = /
|
||||
\A # start of string
|
||||
\S+ # one or more non-spaces
|
||||
.+ # file path (one or more characters)
|
||||
(?= # stop previous match when
|
||||
:\d+ # a colon is followed by one or more digits
|
||||
:in # followed by a colon followed by in
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
require 'test_helper'
|
||||
require 'tmpdir'
|
||||
require 'tempfile'
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
@ -160,9 +161,23 @@ module ActiveModel
|
||||
assert_equal caller_line[ActiveModel::Serializer::CALLER_FILE], path
|
||||
end
|
||||
|
||||
def test_serializer_file_path_with_space
|
||||
path = '/Users/git/ember js/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_with_submatch
|
||||
# The submatch in the path ensures we're using a correctly greedy regexp.
|
||||
path = '/Users/git/ember js/ember:123:in x/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')
|
||||
dir = Dir.mktmpdir('space char')
|
||||
file = Tempfile.new('some_ruby.rb', dir)
|
||||
file.write(contents)
|
||||
path = file.path
|
||||
caller_line = "#{path}:1:in `<top (required)>'"
|
||||
@ -170,6 +185,7 @@ module ActiveModel
|
||||
assert_equal ActiveModel::Serializer.digest_caller_file(caller_line), Digest::MD5.hexdigest(contents)
|
||||
ensure
|
||||
file.unlink
|
||||
FileUtils.remove_entry dir
|
||||
end
|
||||
|
||||
def test_warn_on_serializer_not_defined_in_file
|
||||
|
||||
Loading…
Reference in New Issue
Block a user