dupe 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/dupe/cucumber_hooks.rb +9 -7
- data/lib/dupe/dupe.rb +2 -1
- data/lib/dupe/record.rb +55 -11
- data/spec/lib_specs/dupe_record_spec.rb +57 -0
- data/spec/lib_specs/dupe_spec.rb +4 -0
- data/spec/spec_helper.rb +11 -0
- metadata +6 -4
data/lib/dupe/cucumber_hooks.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
After
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
if defined?(After)
|
2
|
+
After do |scenario| #:nodoc:
|
3
|
+
if Dupe.global_configuration.config[:debug] == true
|
4
|
+
ActiveResource::Connection.print_request_log
|
5
|
+
ActiveResource::Connection.flush_request_log
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
end
|
8
|
+
Dupe.flush
|
9
|
+
end
|
10
|
+
end
|
data/lib/dupe/dupe.rb
CHANGED
@@ -336,7 +336,7 @@ class Dupe
|
|
336
336
|
# "find the first author record where the author's name equals `name`".
|
337
337
|
#
|
338
338
|
# Dupe decided to return only a single record because we specified <tt>find(:author)</tt>.
|
339
|
-
# Had we instead specified <tt>find(:authors)</tt>,
|
339
|
+
# Had we instead specified <tt>find(:authors)</tt>, Dupe would have instead returned an array of results.
|
340
340
|
#
|
341
341
|
# More examples:
|
342
342
|
#
|
@@ -432,6 +432,7 @@ class Dupe
|
|
432
432
|
def generate_services_for(records, records_already_processed=false) #:nodoc:
|
433
433
|
records = process_records records unless records_already_processed
|
434
434
|
@mocker.run_mocks(@records, @config.config[:record_identifiers])
|
435
|
+
records.length == 1 ? records.first : records
|
435
436
|
end
|
436
437
|
|
437
438
|
def find_records_like(match) #:nodoc:
|
data/lib/dupe/record.rb
CHANGED
@@ -1,19 +1,63 @@
|
|
1
1
|
class Dupe
|
2
|
-
class Record
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
v
|
9
|
-
else
|
10
|
-
v
|
2
|
+
class Record
|
3
|
+
attr_accessor :internal_attributes_hash
|
4
|
+
|
5
|
+
def initialize(hash={})
|
6
|
+
@internal_attributes_hash =
|
7
|
+
hash.merge(hash) do |k,v|
|
8
|
+
process_value(v)
|
11
9
|
end
|
12
|
-
end
|
13
10
|
end
|
14
11
|
|
12
|
+
# allows you to access a record like:
|
13
|
+
# irb> book = Dupe::Record.new :title => 'The Carpet Makers', :author => {:name => 'Andreas Eschbach'}
|
14
|
+
# irb> book.title
|
15
|
+
# ==> 'The Carpet Makers'
|
16
|
+
# irb> book.author.name
|
17
|
+
# ==> 'Andreas Eschbach'
|
18
|
+
# irb> book.genre = 'Science Fiction'
|
19
|
+
# irb> book.genre
|
20
|
+
# ==> 'Science Fiction'
|
15
21
|
def method_missing(method_name, *args, &block)
|
16
|
-
|
22
|
+
if method_name.to_s[-1..-1] == '='
|
23
|
+
@internal_attributes_hash[method_name.to_s[0..-2].to_sym] =
|
24
|
+
process_value(args[0])
|
25
|
+
else
|
26
|
+
@internal_attributes_hash[method_name.to_sym]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# allows you to access a record like:
|
31
|
+
# irb> book = Dupe::Record.new :title => 'The Carpet Makers', :author => {:name => 'Andreas Eschbach'}
|
32
|
+
# irb> book[:title]
|
33
|
+
# ==> 'The Carpet Makers'
|
34
|
+
# irb> book[:author][:name]
|
35
|
+
# ==> 'Andreas Eschbach'
|
36
|
+
# irb> book.genre = 'Science Fiction'
|
37
|
+
# irb> book.genre
|
38
|
+
# ==> 'Science Fiction'
|
39
|
+
def [](key)
|
40
|
+
@internal_attributes_hash[key.to_sym]
|
41
|
+
end
|
42
|
+
|
43
|
+
# allows you to set a record like:
|
44
|
+
# irb> book = Dupe::Record.new :title => 'The Carpet Makers', :author => {:name => 'Andreas Eschbach'}
|
45
|
+
# irb> book[:genre] = 'Science Fiction'
|
46
|
+
# irb> book[:genre]
|
47
|
+
# ==> 'Science Fiction'
|
48
|
+
def []=(key, value)
|
49
|
+
@internal_attributes_hash[key.to_sym] = process_value(value)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def process_value(v)
|
54
|
+
if v.is_a?(Hash)
|
55
|
+
Record.new(v)
|
56
|
+
elsif v.is_a?(Array)
|
57
|
+
v.map {|r| process_value(r)}
|
58
|
+
else
|
59
|
+
v
|
60
|
+
end
|
17
61
|
end
|
18
62
|
end
|
19
63
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Dupe::Record" do
|
4
|
+
describe "the new method" do
|
5
|
+
it "should setup an empty internal hash when created with no parameters" do
|
6
|
+
r = Dupe::Record.new
|
7
|
+
r.internal_attributes_hash.should == {}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be accessible via missing methods" do
|
11
|
+
book = Dupe::Record.new :title => 'Bible', :author => {:name => 'Jebus'}
|
12
|
+
book.title.should == 'Bible'
|
13
|
+
book.author.name.should == 'Jebus'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be accessible via hash accessors" do
|
17
|
+
book = Dupe::Record.new :title => 'Bible', :author => {:name => 'Jebus'}
|
18
|
+
book[:title].should == 'Bible'
|
19
|
+
book[:author][:name].should == 'Jebus'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should let you set attributes via method missing" do
|
23
|
+
book = Dupe::Record.new :title => 'Bible', :author => {:name => 'Jebus'}
|
24
|
+
book.genre = 'Superstition'
|
25
|
+
book.genre.should == 'Superstition'
|
26
|
+
book.chapters = [
|
27
|
+
{:title => 'Hair', :start => 1},
|
28
|
+
{:title => 'Carpet', :start => 15}
|
29
|
+
]
|
30
|
+
book.chapters.first.title.should == 'Hair'
|
31
|
+
book.chapters.first.start.should == 1
|
32
|
+
book.chapters.last.title.should == 'Carpet'
|
33
|
+
book.chapters.last.start.should == 15
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should let you set attributes via has accessors" do
|
37
|
+
book = Dupe::Record.new :title => 'Bible', :author => {:name => 'Jebus'}
|
38
|
+
|
39
|
+
# setting existing attributes
|
40
|
+
book[:title] = 'The Carpet Makers'
|
41
|
+
book[:author][:name] = 'Andreas Eschbach'
|
42
|
+
book[:title].should == 'The Carpet Makers'
|
43
|
+
book[:author][:name].should == 'Andreas Eschbach'
|
44
|
+
|
45
|
+
# setting new attributes
|
46
|
+
book[:genre] = 'Science Fiction'
|
47
|
+
book[:genre].should == 'Science Fiction'
|
48
|
+
|
49
|
+
# setting hash attributes
|
50
|
+
book[:chapters] = [
|
51
|
+
{:title => 'Hair', :start => 1},
|
52
|
+
{:title => 'Carpet', :start => 15}
|
53
|
+
]
|
54
|
+
book[:chapters][0][:title].should == 'Hair'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dupe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Parker
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-28 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -76,5 +76,7 @@ rubygems_version: 1.3.5
|
|
76
76
|
signing_key:
|
77
77
|
specification_version: 3
|
78
78
|
summary: A tool that helps you mock services while cuking.
|
79
|
-
test_files:
|
80
|
-
|
79
|
+
test_files:
|
80
|
+
- spec/lib_specs/dupe_record_spec.rb
|
81
|
+
- spec/lib_specs/dupe_spec.rb
|
82
|
+
- spec/spec_helper.rb
|