superdupe 0.5.0 → 1.0.0
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/superdupe/mock.rb
CHANGED
@@ -49,17 +49,12 @@ class Dupe
|
|
49
49
|
|
50
50
|
when Dupe::Database::Record
|
51
51
|
# if a namespace is available, demodulize the modelname
|
52
|
-
|
53
|
-
resp = resp.to_xml_safe(:root => resp.__model__.name.to_s.demodulize)
|
54
|
-
else
|
55
|
-
resp = resp.to_xml_safe(:root => resp.__model__.name.to_s)
|
56
|
-
end
|
57
|
-
|
52
|
+
resp = resp.to_xml_safe(:root => resp.demodulize)
|
58
53
|
when Array
|
59
54
|
if resp.empty?
|
60
55
|
resp = [].to_xml :root => 'results'
|
61
56
|
else
|
62
|
-
resp = resp.map {|r| HashPruner.prune(r)}.to_xml(:root => resp.first.
|
57
|
+
resp = resp.map {|r| HashPruner.prune(r)}.to_xml(:root => resp.first.demodulize.pluralize)
|
63
58
|
end
|
64
59
|
end
|
65
60
|
Dupe.network.log.add_request :get, url, resp
|
data/lib/superdupe/record.rb
CHANGED
@@ -35,9 +35,17 @@ class Dupe
|
|
35
35
|
inspection << ">"
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
alias_method :hash_inspect, :inspect
|
40
40
|
alias_method :inspect, :record_inspect
|
41
|
+
|
42
|
+
def demodulize
|
43
|
+
if self.__model__.name.to_s.include?('::')
|
44
|
+
self.__model__.name.to_s.demodulize
|
45
|
+
else
|
46
|
+
self.__model__.name.to_s
|
47
|
+
end
|
48
|
+
end
|
41
49
|
|
42
50
|
private
|
43
51
|
def attempting_to_assign(method_name)
|
@@ -45,4 +53,4 @@ class Dupe
|
|
45
53
|
end
|
46
54
|
end
|
47
55
|
end
|
48
|
-
end
|
56
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Ns
|
4
|
+
class Ns::Customer < ActiveResource::Base
|
5
|
+
self.site = ''
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Ns::Customer do
|
10
|
+
before(:each) do
|
11
|
+
Dupe.reset
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have none url patterns registered" do
|
15
|
+
[:post, :get, :delete, :put].each do |verb|
|
16
|
+
Dupe.network.mocks[verb].should be_blank
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
context "registerd" do
|
22
|
+
before(:each) do
|
23
|
+
Dupe.create Ns::Customer, :name => 'Ribi', :state => 'active'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be registered as get mock" do
|
27
|
+
Dupe.network.mocks[:get].size == 2
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should generate a GetMock" do
|
31
|
+
customer = Dupe.find :"Ns::Customer"
|
32
|
+
customer.should_not be_nil
|
33
|
+
customer.class.should == Dupe::Database::Record
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should generate a valid url pattern" do
|
37
|
+
Dupe.network.mocks[:get].each_with_index do |mock, index|
|
38
|
+
mock.url_pattern.class.should == Regexp
|
39
|
+
if index == 0
|
40
|
+
mock.url_pattern.inspect.should == (%r{^\/customers\.xml$}).inspect
|
41
|
+
else
|
42
|
+
mock.url_pattern.inspect.should == %r{^\/customers\/(\d+)\.xml$}.inspect
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
context "find single resource" do
|
49
|
+
before(:each) { @customer = Ns::Customer.find 1 }
|
50
|
+
|
51
|
+
it "should find customer with id 1" do
|
52
|
+
@customer.should_not be_blank
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
context "find every resource" do
|
58
|
+
before(:each) { @customers = Ns::Customer.find :all }
|
59
|
+
|
60
|
+
it "should return an array" do
|
61
|
+
@customers.class.should == Array
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should include customer number one" do
|
65
|
+
@customers.should be_include(Ns::Customer.find(1))
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should have size of one" do
|
69
|
+
@customers.size.should == 1
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
context "find every resource with a param-filter" do
|
75
|
+
before(:each) do
|
76
|
+
Dupe.create Ns::Customer, :name => 'Marco', :state => 'inactive'
|
77
|
+
Get %r{\/customers\.xml\?state=(active|inactive)} do |state|
|
78
|
+
if state == 'active'
|
79
|
+
Dupe.find(:"Ns::Customers") {|customer| customer.state == 'active'}
|
80
|
+
elsif state == 'inactive'
|
81
|
+
Dupe.find(:"Ns::Customers") {|customer| customer.state == 'inactive'}
|
82
|
+
else
|
83
|
+
Dupe.find(:"Ns::Customers")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should find all active customers" do
|
89
|
+
active_customers = Ns::Customer.find :all, :params => {:state => 'active'}
|
90
|
+
active_customers.size.should == 1
|
91
|
+
active_customers.should be_include(Ns::Customer.find(1))
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should find all inactive customers" do
|
95
|
+
inactive_customers = Ns::Customer.find :all, :params => {:state => 'inactive'}
|
96
|
+
inactive_customers.size.should == 1
|
97
|
+
inactive_customers.should be_include(Ns::Customer.find(2))
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should find all customers without a filter" do
|
101
|
+
customers = Ns::Customer.find :all, :params => {}
|
102
|
+
customers.size.should == 2
|
103
|
+
customers.should == Ns::Customer.find(:all)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
metadata
CHANGED
@@ -1,27 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superdupe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
- 5
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Marco Ribi
|
14
|
+
- Felipe Kaufmann
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-09-
|
19
|
+
date: 2010-09-14 00:00:00 +02:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
+
type: :runtime
|
23
24
|
prerelease: false
|
24
|
-
|
25
|
+
name: activeresource
|
26
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
27
|
none: false
|
26
28
|
requirements:
|
27
29
|
- - ">="
|
@@ -32,8 +34,7 @@ dependencies:
|
|
32
34
|
- 3
|
33
35
|
- 3
|
34
36
|
version: 2.3.3
|
35
|
-
|
36
|
-
version_requirements: *id001
|
37
|
+
requirement: *id001
|
37
38
|
description: |-
|
38
39
|
SuperDupe is a fork of the originally Dupe and rides on top of ActiveResource to allow you to cuke the client side of
|
39
40
|
a service-oriented app without having to worry about whether or not the service is live or available while cuking.
|
@@ -70,6 +71,7 @@ files:
|
|
70
71
|
- rails_generators/dupe/templates/definitions.rb
|
71
72
|
- rails_generators/dupe/templates/load_dupe.rb
|
72
73
|
- spec/lib_specs/active_resource_extensions_spec.rb
|
74
|
+
- spec/lib_specs/namespaced_active_resource_extensions_spec.rb
|
73
75
|
- spec/spec_helper.rb
|
74
76
|
has_rdoc: true
|
75
77
|
homepage: http://github.com/screenconcept/dupe
|
@@ -107,4 +109,5 @@ specification_version: 3
|
|
107
109
|
summary: A tool that helps you mock services while cuking.
|
108
110
|
test_files:
|
109
111
|
- spec/lib_specs/active_resource_extensions_spec.rb
|
112
|
+
- spec/lib_specs/namespaced_active_resource_extensions_spec.rb
|
110
113
|
- spec/spec_helper.rb
|