geoff 0.0.3.beta → 0.0.4

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.
@@ -3,70 +3,167 @@ require 'neo4j'
3
3
  require 'geoff'
4
4
 
5
5
  describe Geoff do
6
- class CoverageArea
7
- include Neo4j::NodeMixin
8
- end
9
- class Cafe
10
- include Neo4j::NodeMixin
11
- end
6
+ before { stub_node_dsl_object_id }
12
7
 
13
- class Carrier
14
- include Neo4j::NodeMixin
15
- end
8
+ context do
16
9
 
17
- class Branch
18
- include Neo4j::NodeMixin
19
- end
20
- describe 'base nodes' do
10
+ class Branch
11
+ include Neo4j::NodeMixin
12
+ end
21
13
 
22
- let(:builder) do
23
- Geoff(Cafe, Carrier, Branch, CoverageArea)
14
+ class Cafe
15
+ include Neo4j::NodeMixin
24
16
  end
25
17
 
26
- let(:expected_geoff) do
27
- strip_whitespace <<-EOS
18
+ describe 'base nodes' do
19
+
20
+ let(:builder) do
21
+ Geoff(Cafe, Branch)
22
+ end
23
+
24
+ let(:expected_geoff) do
25
+ strip_whitespace <<-EOS
28
26
  (ROOT)-[:Cafe]->(Cafe)
29
- (ROOT)-[:Carrier]->(Carrier)
30
27
  (ROOT)-[:Branch]->(Branch)
31
- (ROOT)-[:CoverageArea]->(CoverageArea)
32
- EOS
33
- end
28
+ EOS
29
+ end
34
30
 
35
- specify do
36
- builder.to_s.should == expected_geoff
31
+ specify do
32
+ builder.to_s.should == expected_geoff
33
+ end
37
34
  end
38
- end
39
35
 
40
- describe 'Geoff sugar' do
41
- let(:node) do
42
- Geoff(Branch) do
43
- branch 'starbucks_branch' do
44
- delay_time 15
36
+ describe 'Geoff sugar' do
37
+ let(:node) do
38
+ Geoff(Branch) do
39
+ branch 'starbucks_branch' do
40
+ delay_time 15
41
+ end
45
42
  end
46
43
  end
47
- end
48
44
 
49
- let(:expected_geoff) do
50
- strip_whitespace <<-EOS
45
+ let(:expected_geoff) do
46
+ strip_whitespace <<-EOS
51
47
  (ROOT)-[:Branch]->(Branch)
52
48
  (starbucks_branch) {"_classname":"Branch","delay_time":15}
53
49
  (Branch)-[:all]->(starbucks_branch)
50
+ EOS
51
+ end
52
+
53
+ specify do
54
+ node.to_geoff.should == expected_geoff
55
+ end
56
+
57
+ specify do
58
+ pending 'not implemented'
59
+ ->{
60
+ Geoff do
61
+ branch 'starbucks_branch' do
62
+ delay_time 15
63
+ end
64
+ end
65
+ }.should raise_error Geoff::MissingClassDefinition, "branch"
66
+ end
67
+ end
68
+ end
69
+
70
+ context do
71
+ let(:expected_geoff) do
72
+ strip_whitespace <<-EOS
73
+ (ROOT)-[:Sandwich]->(Sandwich)
74
+ (ROOT)-[:Cheese]->(Cheese)
75
+ (ROOT)-[:Egg]->(Egg)
54
76
  EOS
55
77
  end
56
78
 
57
- specify do
58
- node.to_geoff.should == expected_geoff
79
+ class Sandwich
80
+ include Neo4j::NodeMixin
59
81
  end
60
82
 
61
- specify do
62
- pending 'not implemented'
63
- ->{
64
- Geoff do
65
- branch 'starbucks_branch' do
66
- delay_time 15
83
+ class Cafe
84
+ include Neo4j::NodeMixin
85
+ end
86
+
87
+ class Branch
88
+ include Neo4j::NodeMixin
89
+ end
90
+
91
+
92
+ class Cheese
93
+ include Neo4j::NodeMixin
94
+ end
95
+
96
+ class Egg
97
+ include Neo4j::NodeMixin
98
+ end
99
+
100
+
101
+ describe "#to_s" do
102
+ specify do
103
+ dsl = Geoff.new Sandwich, Cheese, Egg
104
+ dsl.to_s.should == dsl.to_geoff
105
+ end
106
+ end
107
+
108
+ describe "#to_geoff" do
109
+ it "outputs root node geoff syntax" do
110
+ dsl = Geoff.new(Sandwich, Cheese, Egg)
111
+ dsl.to_geoff.should == expected_geoff
112
+ end
113
+
114
+ specify do
115
+ ->{Geoff.new 2 } .should raise_error ArgumentError
116
+ ->{Geoff.new '' } .should raise_error ArgumentError
117
+ ->{Geoff.new ['']}.should raise_error ArgumentError
118
+ ->{Geoff.new [1]} .should raise_error ArgumentError
119
+
120
+ ->{Geoff.new(Egg)}.should_not raise_error ArgumentError
121
+ end
122
+
123
+
124
+ context "with a block" do
125
+ let(:expected) {
126
+ strip_whitespace <<-EOS
127
+ (ROOT)-[:Cafe]->(Cafe)
128
+ (ROOT)-[:Branch]->(Branch)
129
+ (Starbucks) {"_classname":"Cafe"}
130
+ (Cafe)-[:all]->(Starbucks)
131
+ (starbucks_branch) {"_classname":"Branch"}
132
+ (Branch)-[:all]->(starbucks_branch)
133
+ (Starbucks)-[:owns]->(starbucks_branch)
134
+ EOS
135
+ }
136
+
137
+ specify "with parent node is root node, but no relationship,
138
+ don't create relationship to root node" do
139
+ Geoff.new(Cafe, Branch) do
140
+ cafe 'Starbucks' do
141
+ children 'owns' do
142
+ #create relationship to parent node of type owns (comes from children DSL)
143
+ branch 'starbucks_branch'
144
+ end
145
+ end
146
+
147
+ end.to_geoff.should == expected
148
+ end
149
+ end
150
+
151
+ describe 'called second time' do
152
+ let(:node) do
153
+ Geoff.new(Cafe) do
154
+ cafe 'Starbucks'
67
155
  end
68
156
  end
69
- }.should raise_error Geoff::MissingClassDefinition, "branch"
157
+
158
+ let(:expected_geoff) do
159
+ node.to_geoff
160
+ end
161
+
162
+ it 'returns same geoff as on first call' do
163
+ pending 'Not implemented yet'
164
+ node.to_geoff.should == expected_geoff
165
+ end
166
+ end
70
167
  end
71
168
  end
72
169
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'geoff/node_dsl'
3
+
4
+ describe NodeDsl do
5
+ subject { NodeDsl.new(node_name: 'starbucks') }
6
+
7
+ describe '#node_name' do
8
+ context 'in normal (non-test) use of builder' do
9
+ before do
10
+ subject.stub(:object_id).and_return 'egg'
11
+ end
12
+
13
+ its(:node_name) { should == 'starbucks_egg' }
14
+ end
15
+
16
+ context 'with object_id returning nil to make integration testing easier' do
17
+ before do
18
+ subject.stub(:object_id).and_return nil
19
+ end
20
+
21
+ its(:node_name) { should == 'starbucks' }
22
+ end
23
+ end
24
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,8 @@
1
-
2
1
  Dir["spec/support/**/*.rb"].each {|f| require_relative File.join('..', f)}
3
2
 
4
3
  RSpec.configure do |config|
5
4
  end
5
+
6
+ def stub_node_dsl_object_id
7
+ NodeDsl.any_instance.stub(:object_id).and_return nil
8
+ end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoff
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 6
5
- version: 0.0.3.beta
4
+ prerelease:
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Rouchy
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2012-08-15 00:00:00.000000000 Z
16
+ date: 2012-08-22 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: neo4j
@@ -123,27 +123,45 @@ extensions: []
123
123
  extra_rdoc_files: []
124
124
  files:
125
125
  - .gitignore
126
+ - .rbenv-version
126
127
  - .rvmrc
127
128
  - Gemfile
128
129
  - Gemfile.lock
129
130
  - LICENSE
130
131
  - README.md
131
132
  - Rakefile
133
+ - bin/autospec
134
+ - bin/coderay
135
+ - bin/erubis
136
+ - bin/htmldiff
137
+ - bin/ldiff
138
+ - bin/neo4j-jars
139
+ - bin/neo4j-shell
140
+ - bin/neo4j-upgrade
141
+ - bin/pry
142
+ - bin/rackup
143
+ - bin/rails
144
+ - bin/rake
145
+ - bin/rake2thor
146
+ - bin/rdebug
147
+ - bin/ri
148
+ - bin/rspec
149
+ - bin/thor
150
+ - bin/tilt
132
151
  - geoff.gemspec
133
152
  - lib/geoff.rb
134
153
  - lib/geoff/children_dsl.rb
135
154
  - lib/geoff/container.rb
136
155
  - lib/geoff/dsl_exception_handling.rb
137
156
  - lib/geoff/importer.rb
138
- - lib/geoff/neo4j_wrapper_dsl.rb
139
- - lib/geoff/neo4j_wrapper_validator.rb
140
157
  - lib/geoff/node_dsl.rb
141
158
  - lib/geoff/version.rb
142
159
  - spec/integration/children_dsl_spec.rb
160
+ - spec/integration/geoff_spec.rb
143
161
  - spec/integration/node_dsl_spec.rb
162
+ - spec/models/container_spec.rb
144
163
  - spec/models/geoff_spec.rb
145
- - spec/models/neo4j_wrapper_dsl_spec.rb
146
- - spec/models/neo4j_wrapper_validator_spec.rb
164
+ - spec/node_dsl_spec.rb
147
165
  - spec/spec_helper.rb
148
166
  - spec/support/geof_matchers.rb
149
167
  homepage: ''
@@ -160,9 +178,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
178
  none: false
161
179
  required_rubygems_version: !ruby/object:Gem::Requirement
162
180
  requirements:
163
- - - ! '>'
181
+ - - ! '>='
164
182
  - !ruby/object:Gem::Version
165
- version: 1.3.1
183
+ version: '0'
166
184
  none: false
167
185
  requirements: []
168
186
  rubyforge_project:
@@ -172,10 +190,11 @@ specification_version: 3
172
190
  summary: DSL to allow easy generating of data for Neo4j
173
191
  test_files:
174
192
  - spec/integration/children_dsl_spec.rb
193
+ - spec/integration/geoff_spec.rb
175
194
  - spec/integration/node_dsl_spec.rb
195
+ - spec/models/container_spec.rb
176
196
  - spec/models/geoff_spec.rb
177
- - spec/models/neo4j_wrapper_dsl_spec.rb
178
- - spec/models/neo4j_wrapper_validator_spec.rb
197
+ - spec/node_dsl_spec.rb
179
198
  - spec/spec_helper.rb
180
199
  - spec/support/geof_matchers.rb
181
200
  has_rdoc:
@@ -1,50 +0,0 @@
1
- require 'geoff/children_dsl'
2
-
3
- class Neo4jWrapperDsl
4
- def initialize *classes, &block
5
- options = classes.last.is_a?(Hash) ? classes.pop : {}
6
-
7
- validate classes
8
-
9
- options.merge!({
10
- parent_node_name: 'ROOT',
11
- type: nil,
12
- container: Container.new
13
- })
14
-
15
- @children_dsl = ChildrenDsl.new(options, &block) if block_given?
16
- end
17
-
18
- def to_geoff
19
- geoff = "#{add_classes}\n"
20
- geoff += @children_dsl.to_geoff if @children_dsl
21
- geoff.chomp
22
- end
23
-
24
- def <=> other
25
- to_geoff == other.to_geoff ? 0 : -1
26
- end
27
-
28
- def to_s
29
- to_geoff
30
- end
31
-
32
- private
33
-
34
- def add_classes
35
- @classes.map{|c| root_to_class_as_geoff c }.join("\n")
36
- end
37
-
38
- def root_to_class_as_geoff c
39
- "(ROOT)-[:#{c}]->(#{c})"
40
- end
41
-
42
- def validate classes
43
- @classes = classes || []
44
-
45
- @classes.each do |c|
46
- m = "Class #{c} should include Neo4j::NodeMixin"
47
- raise ArgumentError, m unless c.is_a?(Class) and c.included_modules.include? Neo4j::NodeMixin
48
- end
49
- end
50
- end
@@ -1,17 +0,0 @@
1
- class Neo4jWrapperValidator
2
- NODE_NAME_REGEX = /^\(([^\)]+)\)/
3
-
4
- def call container, node
5
- node_name = node.match(NODE_NAME_REGEX)[1]
6
-
7
- unless class_present? container, node_name
8
- raise Geoff::MissingNodeDefinition, node_name
9
- end
10
-
11
- true
12
- end
13
-
14
- def class_present? container, node_name
15
- container.node_list.include? node_name
16
- end
17
- end
@@ -1,86 +0,0 @@
1
- require File.expand_path('spec/spec_helper')
2
- require 'neo4j'
3
- require './lib/geoff/neo4j_wrapper_dsl'
4
-
5
- describe Neo4jWrapperDsl do
6
- let(:expected_geoff) do
7
- strip_whitespace <<-EOS
8
- (ROOT)-[:Sandwich]->(Sandwich)
9
- (ROOT)-[:Cheese]->(Cheese)
10
- (ROOT)-[:Egg]->(Egg)
11
- EOS
12
- end
13
-
14
- class Sandwich
15
- include Neo4j::NodeMixin
16
- end
17
-
18
- class Cafe
19
- include Neo4j::NodeMixin
20
- end
21
-
22
- class Branch
23
- include Neo4j::NodeMixin
24
- end
25
-
26
-
27
- class Cheese
28
- include Neo4j::NodeMixin
29
- end
30
-
31
- class Egg
32
- include Neo4j::NodeMixin
33
- end
34
-
35
-
36
- describe "#to_s" do
37
- specify do
38
- dsl = Neo4jWrapperDsl.new Sandwich, Cheese, Egg
39
- dsl.to_s.should == dsl.to_geoff
40
- end
41
- end
42
-
43
- describe "#to_geoff" do
44
- it "outputs root node geoff syntax" do
45
- dsl = Neo4jWrapperDsl.new(Sandwich, Cheese, Egg)
46
- dsl.to_geoff.should == expected_geoff
47
- end
48
-
49
- specify do
50
- ->{Neo4jWrapperDsl.new 2 } .should raise_error ArgumentError
51
- ->{Neo4jWrapperDsl.new '' } .should raise_error ArgumentError
52
- ->{Neo4jWrapperDsl.new ['']}.should raise_error ArgumentError
53
- ->{Neo4jWrapperDsl.new [1]} .should raise_error ArgumentError
54
-
55
- ->{Neo4jWrapperDsl.new(Egg)}.should_not raise_error ArgumentError
56
- end
57
-
58
-
59
- context "with a block" do
60
- let(:expected) {
61
- strip_whitespace <<-EOS
62
- (ROOT)-[:Cafe]->(Cafe)
63
- (ROOT)-[:Branch]->(Branch)
64
- (Starbucks) {"_classname":"Cafe"}
65
- (Cafe)-[:all]->(Starbucks)
66
- (starbucks_branch) {"_classname":"Branch"}
67
- (Branch)-[:all]->(starbucks_branch)
68
- (Starbucks)-[:owns]->(starbucks_branch)
69
- EOS
70
- }
71
-
72
- specify "with parent node is root node, but no relationship,
73
- don't create relationship to root node" do
74
- Neo4jWrapperDsl.new(Cafe, Branch) do
75
- cafe 'Starbucks' do
76
- children 'owns' do
77
- #create relationship to parent node of type owns (comes from children DSL)
78
- branch 'starbucks_branch'
79
- end
80
- end
81
-
82
- end.to_geoff.should == expected
83
- end
84
- end
85
- end
86
- end
@@ -1,28 +0,0 @@
1
- require './lib/geoff'
2
- require './lib/geoff/neo4j_wrapper_validator'
3
-
4
- describe Neo4jWrapperValidator do
5
- let(:validator) { Neo4jWrapperValidator.new }
6
-
7
- {
8
- "(Egg)-[:relates]->(1)" => {existing_nodes: %w(Branch Starbucks Cafe), node_name: "Egg", valid: false},
9
- "((Branch)-[:relates]->(1)" => {existing_nodes: %w(Branch Cafe Starbucks), node_name: "Branch", valid: false},
10
- "(Starbucks)-[:relates]->(1)" => {existing_nodes: %w(Branch Cafe Starbucks), node_name: "Starbucks", valid: true},
11
- "((_Branch)-[:relates]->(1)" => {existing_nodes: %w(Branch), node_name: "(_Branch", valid: false},
12
- "((Bra nch)-[:relates]->(1)" => {existing_nodes: %w(Branch Cafe), node_name: "(Bra nch", valid: false},
13
- "((Branch)-[:relates]->(1)" => {existing_nodes: %w(Branch Cafe), node_name: "(Branch", valid: false},
14
- "(Branch)-[:relates]->(1)" => {existing_nodes: [], node_name: "Branch", valid: false}}.each do |input, details|
15
- specify do
16
- valid = details[:valid]
17
- existing_nodes = details[:existing_nodes]
18
- node_name = details[:node_name]
19
- container = mock 'container', node_list: existing_nodes
20
-
21
- if valid
22
- validator.call(container, input).should == true
23
- else
24
- ->{validator.call(container, input)}.should raise_error Geoff::MissingNodeDefinition, node_name
25
- end
26
- end
27
- end
28
- end