dozuki-mapper 0.0.2 → 0.1.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/README.markdown CHANGED
@@ -54,6 +54,7 @@ integer, float, date) to come.
54
54
  * [Float](https://github.com/jamesalmond/dozuki-mapper/tree/master/features/float_mapping.feature)
55
55
  * [Int](https://github.com/jamesalmond/dozuki-mapper/tree/master/features/int_mapping.feature)
56
56
  * [Date](https://github.com/jamesalmond/dozuki-mapper/tree/master/features/date_mapping.feature)
57
+ * [Boolean](https://github.com/jamesalmond/dozuki-mapper/tree/master/features/boolean_mapping.feature)
57
58
 
58
59
  ## Mapping object hierarchies
59
60
 
@@ -0,0 +1,25 @@
1
+ Feature: mapping a document with boolean elements to an object
2
+ So that I don't have to spend all my time typing in repetitive XPaths
3
+ As an API consumer
4
+ I want to map boolean fields to an object
5
+
6
+ @boolean
7
+ Scenario: I have a simple mapping
8
+ Given I have a bar with open, busy and dodgy
9
+ And I have the XML:
10
+ """
11
+ <bar>
12
+ <open>true</open>
13
+ <busy>1</busy>
14
+ <dodgy>0</dodgy>
15
+ </bar>
16
+ """
17
+ When I map the bar node to a bar object with:
18
+ """
19
+ map.boolean :open
20
+ map.boolean :busy
21
+ map.boolean :dodgy
22
+ """
23
+ Then the bar should be open
24
+ And the bar should be busy
25
+ And the bar should not be dodgy
@@ -0,0 +1,24 @@
1
+ Given /^I have a bar with open, busy and dodgy$/ do
2
+ class Bar
3
+ include Dozuki::Mapper
4
+ attr_accessor :open, :busy, :dodgy
5
+ end
6
+ end
7
+
8
+ When /^I map the bar node to a bar object with:$/ do |string|
9
+ Bar.instance_eval %Q{
10
+ map_with do |map|
11
+ #{string}
12
+ end
13
+ }
14
+ @bar = Bar.from_node(@doc.get('/bar'))
15
+ end
16
+
17
+ Then /^the bar should be (.*)$/ do |field|
18
+ @bar.send(field).should == true
19
+ end
20
+
21
+ Then /^the bar should not be (.*)$/ do |field|
22
+ @bar.send(field).should == false
23
+ end
24
+
@@ -24,6 +24,10 @@ module Dozuki
24
24
  self.receiver.send("#{attribute}=", from_node.float("./#{attribute}"))
25
25
  end
26
26
 
27
+ def boolean(attribute)
28
+ self.receiver.send("#{attribute}=", from_node.boolean("./#{attribute}"))
29
+ end
30
+
27
31
  def node(attribute, opts={})
28
32
  self.receiver.send("#{attribute}=", opts[:as].from_node(from_node.get("./#{attribute}")))
29
33
  end
@@ -1,5 +1,5 @@
1
1
  module Dozuki
2
2
  module Mapper
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -48,8 +48,8 @@ module Dozuki
48
48
  receiver.field.should == int
49
49
  end
50
50
  end
51
-
52
- describe "float" do
51
+
52
+ describe "float" do
53
53
  let(:receiver){ TestClass.new }
54
54
  let(:node) { mock :node}
55
55
  let(:method_name){:field}
@@ -71,6 +71,26 @@ module Dozuki
71
71
  end
72
72
  end
73
73
 
74
+ describe "boolean" do
75
+ let(:receiver){ TestClass.new }
76
+ let(:node) { mock :node}
77
+ let(:method_name){:field}
78
+
79
+ before do
80
+ node.stub(:boolean).and_return(true)
81
+ end
82
+
83
+ subject { Proxy.new(receiver, node).boolean(method_name) }
84
+ it "should get the field from the node using the xpath ./field as a boolean" do
85
+ node.should_receive(:boolean).with('./field').and_return(boolean)
86
+ subject
87
+ end
88
+
89
+ it "should set the field on the receiver with the boolean" do
90
+ subject
91
+ receiver.field.should == true
92
+ end
93
+ end
74
94
 
75
95
  describe "node" do
76
96
  let(:node) { mock :node }
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dozuki-mapper
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Almond
@@ -85,11 +85,13 @@ files:
85
85
  - README.markdown
86
86
  - Rakefile
87
87
  - dozuki-mapper.gemspec
88
+ - features/boolean_mapping.feature
88
89
  - features/date_mapping.feature
89
90
  - features/each_mapping.feature
90
91
  - features/float_mapping.feature
91
92
  - features/int_mapping.feature
92
93
  - features/node_mapping.feature
94
+ - features/step_definitions/boolean_steps.rb
93
95
  - features/step_definitions/date_steps.rb
94
96
  - features/step_definitions/each_steps.rb
95
97
  - features/step_definitions/float_steps.rb
@@ -134,11 +136,13 @@ specification_version: 3
134
136
  summary: A DSL for mapping API output to objects
135
137
  test_files:
136
138
  - .autotest
139
+ - features/boolean_mapping.feature
137
140
  - features/date_mapping.feature
138
141
  - features/each_mapping.feature
139
142
  - features/float_mapping.feature
140
143
  - features/int_mapping.feature
141
144
  - features/node_mapping.feature
145
+ - features/step_definitions/boolean_steps.rb
142
146
  - features/step_definitions/date_steps.rb
143
147
  - features/step_definitions/each_steps.rb
144
148
  - features/step_definitions/float_steps.rb