safety-pin 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,114 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe SafetyPin::Query do
4
+ let(:query) { SafetyPin::Query.new }
5
+
6
+ describe ".execute" do
7
+ before do
8
+ @node = SafetyPin::Node.create("/content/foo")
9
+ @node["bar"] = "baz"
10
+ @node.save
11
+ end
12
+
13
+ after { @node.destroy }
14
+
15
+ it "should lookup nodes given a valid JCR-SQL2 query string" do
16
+ nodes = SafetyPin::Query.execute("SELECT * FROM [nt:base] WHERE [nt:base].bar IS NOT NULL")
17
+ nodes.first["bar"].should_not be_nil
18
+ end
19
+ end
20
+
21
+ describe "#sql" do
22
+ it "should compile a default query string to return all nodes" do
23
+ query.sql.should eql("SELECT * FROM [nt:base]")
24
+ end
25
+
26
+ it "should compile a query string to search for nodes of a specific type" do
27
+ query.type("cq:Page")
28
+ query.sql.should eql("SELECT * FROM [cq:Page]")
29
+ end
30
+
31
+ it "should compile a query string to search for a node with a property and value" do
32
+ query.where("foo" => "bar")
33
+ query.sql.should eql("SELECT * FROM [nt:base] WHERE [foo] = 'bar'")
34
+ end
35
+
36
+ it "should compile a query string to search for a node with multiple properties and values" do
37
+ query.where("foo" => "bar", "baz" => "quux")
38
+ query.sql.should eql("SELECT * FROM [nt:base] WHERE [foo] = 'bar' AND [baz] = 'quux'")
39
+ end
40
+
41
+ it "should compile a query string to search for a node within a path" do
42
+ query.within("/content/")
43
+ query.sql.should eql("SELECT * FROM [nt:base] WHERE [jcr:path] LIKE '/content/%'")
44
+ end
45
+
46
+ it "should compile a query string to search a node within multiple nodes" do
47
+
48
+ end
49
+ end
50
+
51
+ describe "#within" do
52
+ context "given string paths" do
53
+ it "should append to @within instance variable" do
54
+ query.within("/foo")
55
+ query.within("/bar")
56
+ query.instance_eval { @within }.should eql(["/foo", "/bar"])
57
+ end
58
+ end
59
+
60
+ context "given an array of string paths" do
61
+ it "should append to @within instance variable" do
62
+ query.within("/foo")
63
+ query.within(["/bar", "/baz"])
64
+ query.instance_eval { @within }.should eql(["/foo", "/bar", "/baz"])
65
+ end
66
+ end
67
+
68
+ context "given an invalid argument" do
69
+ it "should ignore it" do
70
+ query.within("/foo")
71
+ query.within(nil)
72
+ query.instance_eval { @within }.should eql(["/foo"])
73
+ end
74
+ end
75
+ end
76
+
77
+ describe "#where" do
78
+ it "should append to where_conditions" do
79
+ query.where("foo" => "bar")
80
+ query.where("baz" => "quux")
81
+ query.where_conditions.should eql([SafetyPin::Query::WhereCondition.new("foo", "bar"), SafetyPin::Query::WhereCondition.new("baz", "quux")])
82
+ end
83
+ end
84
+
85
+ describe "#type" do
86
+ it "should set the node type" do
87
+ query = SafetyPin::Query.new
88
+ query.type("cq:Page")
89
+ query.instance_eval { @type }.should eql("cq:Page")
90
+ end
91
+ end
92
+
93
+ describe "#where_conditions" do
94
+ it "should return an empty array by default" do
95
+ query.where_conditions.should eql([])
96
+ end
97
+ end
98
+
99
+ #
100
+ # it "should query for nodes beneath a specific path" do
101
+ # pending
102
+ # nodes = SafetyPin::Query.path("/content/sfu")
103
+ # end
104
+ #
105
+ # it "should query for nodes with a specific property" do
106
+ # pending
107
+ # nodes = SafetyPin::Query.where("cq:Template" => "/apps/sfu/templates/basicpage")
108
+ # end
109
+ #
110
+ # it "should chain together query methods to build a query" do
111
+ # pending
112
+ # nodes = SafetyPin::Query.path("/content").type("nt:unstructured").where("jcr:title" => "Open House")
113
+ # end
114
+ end
@@ -0,0 +1,27 @@
1
+ $:<<File.join(File.dirname(__FILE__), '/../lib')
2
+
3
+ require 'safety_pin'
4
+
5
+ RSpec.configure do |config|
6
+ config.before(:all) do
7
+ SafetyPin::JCR.dev_login
8
+ end
9
+
10
+ config.before do
11
+ SafetyPin::JCR.session.refresh(false) if SafetyPin::JCR.logged_in?
12
+ end
13
+
14
+ config.after(:all) do
15
+ SafetyPin::JCR.logout
16
+ end
17
+
18
+ config.after do
19
+ if SafetyPin::JCR.logged_in?
20
+ node = SafetyPin::Node.find("/content/foo")
21
+ unless node.nil?
22
+ node.reload if node.changed?
23
+ node.destroy
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe SafetyPin::Query::WhereCondition do
4
+ it "should be instantiated with a name, value, and comparator" do
5
+ where_condition = SafetyPin::Query::WhereCondition.new("foo", "bar", "LIKE")
6
+ where_condition.should_not be_nil
7
+ end
8
+
9
+ it "should generate a SQL WHERE string fragment" do
10
+ where_condition = SafetyPin::Query::WhereCondition.new("foo", "bar", "LIKE")
11
+ where_condition.sql_fragment.should eql("[foo] LIKE 'bar'")
12
+ end
13
+
14
+ it "should be equal based on its main attributes" do
15
+ condition1 = SafetyPin::Query::WhereCondition.new("foo", "bar", "LIKE")
16
+ condition2 = SafetyPin::Query::WhereCondition.new("foo", "bar", "LIKE")
17
+ condition1.should == condition2
18
+ condition1.should eql(condition2)
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: safety-pin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jordan Raine
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-08 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: An easy-to-use JCR connector for JRuby
15
+ email:
16
+ - jnraine@gmail.com
17
+ executables:
18
+ - safety-pin
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .rspec
23
+ - .rvmrc
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE
27
+ - README.md
28
+ - Rakefile
29
+ - bin/safety-pin
30
+ - console_loader.rb
31
+ - lib/safety-pin.rb
32
+ - lib/safety_pin.rb
33
+ - lib/safety_pin/jcr.rb
34
+ - lib/safety_pin/node.rb
35
+ - lib/safety_pin/node_blueprint.rb
36
+ - lib/safety_pin/query.rb
37
+ - lib/safety_pin/query/where_condition.rb
38
+ - lib/safety_pin/version.rb
39
+ - safety-pin.gemspec
40
+ - spec/jcr_spec.rb
41
+ - spec/jcr_sql2_spec.rb
42
+ - spec/node_blueprint_spec.rb
43
+ - spec/node_spec.rb
44
+ - spec/query_spec.rb
45
+ - spec/spec_helper.rb
46
+ - spec/where_condition_spec.rb
47
+ homepage: ''
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 1.8.23
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: JCR connector for JRuby
71
+ test_files:
72
+ - spec/jcr_spec.rb
73
+ - spec/jcr_sql2_spec.rb
74
+ - spec/node_blueprint_spec.rb
75
+ - spec/node_spec.rb
76
+ - spec/query_spec.rb
77
+ - spec/spec_helper.rb
78
+ - spec/where_condition_spec.rb
79
+ has_rdoc: