hash_dealer 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +17 -0
- data/Guardfile +20 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/hash_dealer.gemspec +74 -0
- data/lib/core_extensions.rb +22 -0
- data/lib/hash_dealer.rb +62 -0
- data/lib/matcher.rb +18 -0
- data/lib/path_string.rb +73 -0
- data/spec/lib/hash_dealer_spec.rb +56 -0
- data/spec/lib/matcher_spec.rb +8 -0
- data/spec/lib/path_string_spec.rb +40 -0
- data/spec/spec_helper.rb +13 -0
- metadata +150 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "activesupport", :require => "active_support"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "bundler"
|
12
|
+
gem "jeweler"
|
13
|
+
gem "rspec"
|
14
|
+
gem "rcov"
|
15
|
+
gem "guard-rspec", "=0.4.0"
|
16
|
+
gem "ruby-debug19", :require => "ruby-debug"
|
17
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^spec/.+_spec\.rb$})
|
11
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
13
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
14
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
15
|
+
watch('spec/spec_helper.rb') { "spec" }
|
16
|
+
watch('config/routes.rb') { "spec/routing" }
|
17
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
18
|
+
# Capybara request specs
|
19
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
20
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Dan Langevin
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= hash_factory
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to hash_factory
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Dan Langevin. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "hash_dealer"
|
18
|
+
gem.homepage = "http://github.com/LifebookerInc/hash_dealer"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Hash Factory - like Factory Girl but for Hashes only}
|
21
|
+
gem.description = %Q{Like Factory Girl but for Hashes only}
|
22
|
+
gem.email = "dan.langevin@lifebooker.com"
|
23
|
+
gem.authors = ["Dan Langevin"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "testgem #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/hash_dealer.gemspec
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{hash_dealer}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Dan Langevin"]
|
12
|
+
s.date = %q{2011-08-11}
|
13
|
+
s.description = %q{Like Factory Girl but for Hashes only}
|
14
|
+
s.email = %q{dan.langevin@lifebooker.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Guardfile",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"hash_dealer.gemspec",
|
29
|
+
"lib/core_extensions.rb",
|
30
|
+
"lib/hash_dealer.rb",
|
31
|
+
"lib/matcher.rb",
|
32
|
+
"lib/path_string.rb",
|
33
|
+
"spec/lib/hash_dealer_spec.rb",
|
34
|
+
"spec/lib/matcher_spec.rb",
|
35
|
+
"spec/lib/path_string_spec.rb",
|
36
|
+
"spec/spec_helper.rb"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/LifebookerInc/hash_dealer}
|
39
|
+
s.licenses = ["MIT"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = %q{1.7.2}
|
42
|
+
s.summary = %q{Hash Factory - like Factory Girl but for Hashes only}
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<guard-rspec>, ["= 0.4.0"])
|
54
|
+
s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
57
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
58
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
59
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
60
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
61
|
+
s.add_dependency(%q<guard-rspec>, ["= 0.4.0"])
|
62
|
+
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
63
|
+
end
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
66
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
67
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
68
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
69
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
70
|
+
s.add_dependency(%q<guard-rspec>, ["= 0.4.0"])
|
71
|
+
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Hash
|
2
|
+
def pathify_strings!
|
3
|
+
self.each_pair do |k,v|
|
4
|
+
if v.is_a?(Array) || v.is_a?(Hash)
|
5
|
+
v.pathify_strings!
|
6
|
+
elsif v.instance_of?(String)
|
7
|
+
self[k] = PathString.new(URI.decode(v))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
class Array
|
13
|
+
def pathify_strings!
|
14
|
+
self.each_with_index do |v,k|
|
15
|
+
if v.is_a?(Array) || v.is_a?(Hash)
|
16
|
+
v.pathify_strings!
|
17
|
+
elsif v.instance_of?(String)
|
18
|
+
self[k] = PathString.new(URI.decode(v))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/hash_dealer.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'path_string'
|
2
|
+
require 'core_extensions'
|
3
|
+
require 'matcher'
|
4
|
+
|
5
|
+
class HashDealer
|
6
|
+
|
7
|
+
attr_accessor :parent
|
8
|
+
|
9
|
+
# cattr_accessor
|
10
|
+
def self.hashes
|
11
|
+
@hashes ||= {}
|
12
|
+
end
|
13
|
+
|
14
|
+
# define a method of the request factory
|
15
|
+
def self.define(name, opts = {}, &block)
|
16
|
+
self.hashes[name] = self.new(opts, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.roll(name, *args)
|
20
|
+
raise Exception.new("No HashDealer called #{name}") unless self.hashes[name]
|
21
|
+
self.hashes[name].attributes(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
# initializer just calls the block from within our DSL
|
25
|
+
def initialize(opts = {}, &block)
|
26
|
+
@parent = opts[:parent]
|
27
|
+
instance_eval(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
# set the value as the root element for attributes
|
31
|
+
def root(value)
|
32
|
+
@attributes = value
|
33
|
+
end
|
34
|
+
|
35
|
+
# method missing
|
36
|
+
def method_missing(meth, *args, &block)
|
37
|
+
raise Exception.new("Please provide either a String or a block to #{meth}") unless (args.length == 1 || (args.empty? && block_given?))
|
38
|
+
@attributes ||= {}
|
39
|
+
if block_given?
|
40
|
+
@attributes[meth.to_sym] = block
|
41
|
+
else
|
42
|
+
@attributes[meth.to_sym] = args.first
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def attributes(*args)
|
47
|
+
# allows us to set a root value
|
48
|
+
return @attributes unless @attributes.is_a?(Hash)
|
49
|
+
att = @parent ? HashDealer.roll(@parent.to_sym) : {}
|
50
|
+
@attributes.each do |k,v|
|
51
|
+
att[k] = v.is_a?(Proc) ? v.call(*args) : v
|
52
|
+
end
|
53
|
+
# if we have a hash as the first arg, it would override the attributes
|
54
|
+
if args.first.is_a?(Hash)
|
55
|
+
args.first.each_pair do |k,v|
|
56
|
+
att[k.to_sym] = v if att.has_key?(k.to_sym)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
att
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
data/lib/matcher.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# just in case it's not loaded
|
2
|
+
require 'rspec'
|
3
|
+
|
4
|
+
RSpec::Matchers.define(:match_response) do |actual|
|
5
|
+
|
6
|
+
match do |expected|
|
7
|
+
PathString.as_sorted_json(actual) == PathString.as_sorted_json(expected)
|
8
|
+
end
|
9
|
+
|
10
|
+
failure_message_for_should do |container|
|
11
|
+
"expected #{PathString.as_sorted_json(actual)}\n to equal\n #{PathString.as_sorted_json(container)}"
|
12
|
+
end
|
13
|
+
|
14
|
+
failure_message_for_should_not do |container|
|
15
|
+
"expected #{PathString.as_sorted_json(actual)}\n not to equal\n #{PathString.as_sorted_json(container)}"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/lib/path_string.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require "active_support"
|
2
|
+
|
3
|
+
class PathString < String
|
4
|
+
|
5
|
+
def == (other)
|
6
|
+
# if either is a string that starts with a :, return true
|
7
|
+
if self =~ /^:/ || other =~ /^:/
|
8
|
+
return true
|
9
|
+
elsif self =~ /\/:/ || other =~ /\/:/
|
10
|
+
return self.paths_match?(self, other)
|
11
|
+
else
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.paths_match?(a, b)
|
17
|
+
self.get_zipped_array(a, b).each do |kp, ep|
|
18
|
+
# only known path can have things prefixed with colons which is protected
|
19
|
+
if kp.nil? || ep.nil?
|
20
|
+
return false
|
21
|
+
elsif String.new(kp) != String.new(ep) && !kp.start_with?(":") && !ep.start_with?(":")
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
return true
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.as_sorted_json(val)
|
29
|
+
val = val.is_a?(String) ? ActiveSupport::JSON.decode(val).sort : ActiveSupport::JSON.decode(ActiveSupport::JSON.encode(val)).sort
|
30
|
+
val.pathify_strings!
|
31
|
+
val
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
#
|
36
|
+
def self.extract_params(known_path, entered_path)
|
37
|
+
params = {}.with_indifferent_access
|
38
|
+
|
39
|
+
self.get_zipped_array(known_path, entered_path).each do |kp, ep|
|
40
|
+
if kp.nil? || ep.nil?
|
41
|
+
raise Exception.new("Cannot extract params for routes that don't match")
|
42
|
+
end
|
43
|
+
if kp.start_with?(":")
|
44
|
+
if params[kp[1..-1]]
|
45
|
+
raise Exception.new("Cannot define a route containing two parameters with the same name")
|
46
|
+
else
|
47
|
+
params[kp[1..-1]] = ep
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
return params
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def self.get_zipped_array(known_path, entered_path)
|
56
|
+
# make these strings
|
57
|
+
known_path, entered_path = known_path.to_s, entered_path.to_s
|
58
|
+
# Remove the any beginning or trailing slashes from both paths if they exist
|
59
|
+
known_path = known_path[1..-1] if known_path.start_with?("/")
|
60
|
+
known_path = known_path[0..-2] if known_path.end_with?("/")
|
61
|
+
entered_path = entered_path[1..-1] if entered_path.start_with?("/")
|
62
|
+
entered_path = entered_path[0..-2] if entered_path.end_with?("/")
|
63
|
+
known_path = known_path.split("/")
|
64
|
+
entered_path = entered_path.split("/")
|
65
|
+
if known_path.length < entered_path.length
|
66
|
+
(entered_path.length - known_path.length).times do
|
67
|
+
known_path << nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
return known_path.zip(entered_path)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe HashDealer do
|
4
|
+
|
5
|
+
it "should be able to define parameter sets" do
|
6
|
+
HashDealer.define(:valid_request) do
|
7
|
+
abc("defg")
|
8
|
+
dan("test")
|
9
|
+
end
|
10
|
+
HashDealer.roll(:valid_request).should eql(:abc => "defg", :dan => "test")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be able to define paramter sets that return variable data" do
|
14
|
+
HashDealer.define(:valid_request) do
|
15
|
+
abc{[0,1,2,3].sample}
|
16
|
+
end
|
17
|
+
[0,1,2,3].should include HashDealer.roll(:valid_request)[:abc]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should implement inheritance" do
|
21
|
+
HashDealer.define(:valid_request) do
|
22
|
+
v("my val")
|
23
|
+
abc("first val")
|
24
|
+
end
|
25
|
+
HashDealer.define(:special_valid_request, :parent => :valid_request) do
|
26
|
+
abc("another value")
|
27
|
+
end
|
28
|
+
HashDealer.roll(:special_valid_request)[:abc].should eql("another value")
|
29
|
+
HashDealer.roll(:special_valid_request)[:v].should eql("my val")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should provide a way to return an Array as the root element inheritance" do
|
33
|
+
HashDealer.define(:array) do
|
34
|
+
root([1,2,3])
|
35
|
+
end
|
36
|
+
HashDealer.roll(:array).should eql([1,2,3])
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
it "should provide arguments to a block when given" do
|
41
|
+
HashDealer.define(:variable) do
|
42
|
+
abc{|val| val["test"]}
|
43
|
+
end
|
44
|
+
HashDealer.roll(:variable, {"test" => "123"})[:abc].should eql("123")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should overwrite attributes if provided with extra options" do
|
48
|
+
HashDealer.define(:variable) do
|
49
|
+
abc("test")
|
50
|
+
end
|
51
|
+
HashDealer.roll(:variable, {"abc" => "123"})[:abc].should eql("123")
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe PathString do
|
4
|
+
|
5
|
+
it "should match values with a ':' as wildcards" do
|
6
|
+
PathString.new(":test").should == PathString.new("abcdefg")
|
7
|
+
end
|
8
|
+
it "should work on nested hashes and arrays" do
|
9
|
+
PathString.as_sorted_json(:abc => [":1",":2",":3"]).should == PathString.as_sorted_json({:abc => ["1","2","3"]})
|
10
|
+
a = {
|
11
|
+
"provider[address][address_name]" => ":name",
|
12
|
+
"provider[address][city]" => ":city",
|
13
|
+
"provider[address][state]" => ":state",
|
14
|
+
"provider[address][street_line_1]" => ":street",
|
15
|
+
"provider[address][zip]" => ":zip",
|
16
|
+
"provider[current_step]" => "2",
|
17
|
+
"provider[payment_type_ids]" => [":id"],
|
18
|
+
"provider[statement_of_business]" => ":statement",
|
19
|
+
"provider[url]" => ":url"
|
20
|
+
}
|
21
|
+
b = {
|
22
|
+
"provider[address][address_name]" => "Brady+Rowe",
|
23
|
+
"provider[address][city]" => "New+York",
|
24
|
+
"provider[address][state]" => "NY",
|
25
|
+
"provider[address][street_line_1]" => "708+Kutch+Squares",
|
26
|
+
"provider[address][zip]" => "10024",
|
27
|
+
"provider[current_step]" => "2",
|
28
|
+
"provider[payment_type_ids]" => ["1"],
|
29
|
+
"provider[statement_of_business]" => "Hic+nulla+tempora+voluptatibus+nemo.+Mollitia+qui+deleniti+rerum.+Ut+omnis+adipisci+eos.",
|
30
|
+
"provider[url]" => "http%3A%2F%2Ffoo.com"
|
31
|
+
}
|
32
|
+
|
33
|
+
PathString.as_sorted_json(a).should == PathString.as_sorted_json(b)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should match wildcard paths" do
|
37
|
+
PathString.paths_match?("/a/1/test/2", "/a/:1/test/:2").should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'bundler'
|
4
|
+
require 'hash_dealer'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Bundler.require(:default, :development)
|
9
|
+
|
10
|
+
Debugger.start
|
11
|
+
|
12
|
+
Dir[File.join(File.dirname(__FILE__), '..', 'spec/support/**/*.rb')].each {|f| require f}
|
13
|
+
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hash_dealer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Langevin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-08-11 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: bundler
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: jeweler
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rcov
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: guard-rspec
|
72
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - "="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.4.0
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: ruby-debug19
|
83
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "0"
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *id007
|
92
|
+
description: Like Factory Girl but for Hashes only
|
93
|
+
email: dan.langevin@lifebooker.com
|
94
|
+
executables: []
|
95
|
+
|
96
|
+
extensions: []
|
97
|
+
|
98
|
+
extra_rdoc_files:
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.rdoc
|
101
|
+
files:
|
102
|
+
- .document
|
103
|
+
- .rspec
|
104
|
+
- Gemfile
|
105
|
+
- Guardfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.rdoc
|
108
|
+
- Rakefile
|
109
|
+
- VERSION
|
110
|
+
- hash_dealer.gemspec
|
111
|
+
- lib/core_extensions.rb
|
112
|
+
- lib/hash_dealer.rb
|
113
|
+
- lib/matcher.rb
|
114
|
+
- lib/path_string.rb
|
115
|
+
- spec/lib/hash_dealer_spec.rb
|
116
|
+
- spec/lib/matcher_spec.rb
|
117
|
+
- spec/lib/path_string_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
homepage: http://github.com/LifebookerInc/hash_dealer
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
hash: -457040019791943522
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
version: "0"
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: "0"
|
142
|
+
requirements: []
|
143
|
+
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 1.7.2
|
146
|
+
signing_key:
|
147
|
+
specification_version: 3
|
148
|
+
summary: Hash Factory - like Factory Girl but for Hashes only
|
149
|
+
test_files: []
|
150
|
+
|