safety-pin 0.0.9
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/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +21 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/safety-pin +45 -0
- data/console_loader.rb +7 -0
- data/lib/safety-pin.rb +2 -0
- data/lib/safety_pin/jcr.rb +42 -0
- data/lib/safety_pin/node.rb +389 -0
- data/lib/safety_pin/node_blueprint.rb +18 -0
- data/lib/safety_pin/query/where_condition.rb +25 -0
- data/lib/safety_pin/query.rb +70 -0
- data/lib/safety_pin/version.rb +3 -0
- data/lib/safety_pin.rb +11 -0
- data/safety-pin.gemspec +17 -0
- data/spec/jcr_spec.rb +31 -0
- data/spec/jcr_sql2_spec.rb +81 -0
- data/spec/node_blueprint_spec.rb +35 -0
- data/spec/node_spec.rb +712 -0
- data/spec/query_spec.rb +114 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/where_condition_spec.rb +20 -0
- metadata +79 -0
data/lib/safety_pin.rb
ADDED
data/safety-pin.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/safety_pin/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jordan Raine"]
|
6
|
+
gem.email = ["jnraine@gmail.com"]
|
7
|
+
gem.description = %q{An easy-to-use JCR connector for JRuby}
|
8
|
+
gem.summary = %q{JCR connector for JRuby}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "safety-pin"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = SafetyPin::VERSION
|
17
|
+
end
|
data/spec/jcr_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe SafetyPin::JCR do
|
4
|
+
before(:all) do
|
5
|
+
SafetyPin::JCR.logout
|
6
|
+
end
|
7
|
+
|
8
|
+
after(:all) do
|
9
|
+
SafetyPin::JCR.dev_login
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should login to a remote JCR" do
|
13
|
+
SafetyPin::JCR.login(:hostname => "http://localhost:4502", :username => "admin", :password => "admin")
|
14
|
+
SafetyPin::JCR.session.should be_a(Java::JavaxJcr::Session)
|
15
|
+
SafetyPin::JCR.should be_logged_in
|
16
|
+
SafetyPin::JCR.logout
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should logout of a remote SafetyPin::JCR" do
|
20
|
+
SafetyPin::JCR.login(:hostname => "http://localhost:4502", :username => "admin", :password => "admin")
|
21
|
+
SafetyPin::JCR.logout
|
22
|
+
SafetyPin::JCR.should be_logged_out
|
23
|
+
end
|
24
|
+
|
25
|
+
context ".parse_hostname" do
|
26
|
+
it "ensures the hostname ends with /crx/server" do
|
27
|
+
hostname = SafetyPin::JCR.parse_hostname("http://localhost:4502")
|
28
|
+
hostname.end_with?("/crx/server").should be_true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe "JCR-SQL2 example queries" do
|
4
|
+
before do
|
5
|
+
@node = SafetyPin::Node.create("/content/foo")
|
6
|
+
@node.properties = {"bar" => "baz", "qux" => "qax"}
|
7
|
+
@node.save
|
8
|
+
end
|
9
|
+
|
10
|
+
after { @node.destroy }
|
11
|
+
|
12
|
+
it "can lookup a node based on property presence" do
|
13
|
+
nodes = SafetyPin::Query.execute("SELECT * FROM [nt:base] WHERE [nt:base].bar IS NOT NULL")
|
14
|
+
nodes.first["bar"].should_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "can lookup a node based on a property's value" do
|
18
|
+
nodes = SafetyPin::Query.execute("SELECT * FROM [nt:base] WHERE bar = 'baz'")
|
19
|
+
values = nodes.map {|e| e["bar"] }.uniq
|
20
|
+
values.length.should eql(1)
|
21
|
+
values.first.should eql("baz")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can lookup a node based on multiple property values" do
|
25
|
+
nodes = SafetyPin::Query.execute("SELECT * FROM [nt:base] WHERE bar = 'baz' AND qux = 'qax'")
|
26
|
+
bar_values = nodes.map {|e| e["bar"] }.uniq
|
27
|
+
qux_values = nodes.map {|e| e["qux"] }.uniq
|
28
|
+
bar_values.length.should eql(1)
|
29
|
+
qux_values.length.should eql(1)
|
30
|
+
bar_values.first.should eql("baz")
|
31
|
+
qux_values.first.should eql("qax")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can lookup a node based on node name" do
|
35
|
+
nodes = SafetyPin::Query.execute("SELECT * FROM [nt:base] WHERE NAME([nt:base]) = 'foo'")
|
36
|
+
names = nodes.map(&:name).uniq
|
37
|
+
names.length.should eql(1)
|
38
|
+
names.first.should eql("foo")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "can lookup a node based on a path" do
|
42
|
+
pending "can't do this yet"
|
43
|
+
nodes = SafetyPin::Query.execute("SELECT * FROM [nt:base] AS base WHERE base.[jcr:path] LIKE '/content/%'")
|
44
|
+
nodes.length.should be > 0
|
45
|
+
nodes.map(&:path).each {|name| name.starts_with?("/content").should be_true }
|
46
|
+
end
|
47
|
+
|
48
|
+
it "can lookup a node based on node type" do
|
49
|
+
nodes = SafetyPin::Query.execute("SELECT * FROM [cq:Page]")
|
50
|
+
nodes.first.primary_type.should eql("cq:Page")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "can lookup a node based on its node super type" do
|
54
|
+
nodes = SafetyPin::Query.execute("SELECT * FROM [rep:Authorizable]")
|
55
|
+
primary_types = nodes.map(&:primary_type)
|
56
|
+
primary_types.should include("rep:User")
|
57
|
+
end
|
58
|
+
|
59
|
+
# context "given some nodes and child nodes" do
|
60
|
+
# before do
|
61
|
+
# @parent2 = SafetyPin::Node.create("/content/foo2")
|
62
|
+
# @child1 = SafetyPin::Node.create("/content/foo2/child")
|
63
|
+
# @child1.properties = {"bar" => "baz", "qux" => "qax", "child" => "yes"}
|
64
|
+
# @child1.save
|
65
|
+
# @child2 = SafetyPin::Node.create("/content/foo/child")
|
66
|
+
# @child2.properties = {"bar" => "baz", "qux" => "qax", "child" => "yes"}
|
67
|
+
# @child2.save
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# after do
|
71
|
+
# @parent2.destroy
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# it "can lookup a node based on nested WHERE conditions" do
|
75
|
+
# sql_statement = "SELECT * FROM [nt:base]
|
76
|
+
# WHERE [jcr:path] LIKE '/content/foo%'"
|
77
|
+
# nodes = SafetyPin::Query.execute(sql_statement)
|
78
|
+
# nodes.map(&:path).sort.should eql(["/content/foo/child", "/content/foo2/child"])
|
79
|
+
# end
|
80
|
+
# end
|
81
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SafetyPin::NodeBlueprint do
|
4
|
+
let(:node_blueprint) { SafetyPin::NodeBlueprint.new(:path => "/content/foo/bar", :primary_type => "nt:folder", :properties => {"foo" => "bar"}) }
|
5
|
+
|
6
|
+
describe "#primary_type" do
|
7
|
+
it "has a primary type" do
|
8
|
+
node_blueprint.primary_type.should == "nt:folder"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a default primary type" do
|
12
|
+
SafetyPin::NodeBlueprint.new(:path => "/something").primary_type.should == "nt:unstructured"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#properties" do
|
17
|
+
it "has properties" do
|
18
|
+
node_blueprint.properties.should == {"foo" => "bar"}
|
19
|
+
end
|
20
|
+
|
21
|
+
it "defaults to an empty hash" do
|
22
|
+
SafetyPin::NodeBlueprint.new(:path => "/something").properties.should == {}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#path" do
|
27
|
+
it "requires a path" do
|
28
|
+
expect { SafetyPin::NodeBlueprint.new({}).path }.to raise_error(SafetyPin::NodeBlueprintError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has a path" do
|
32
|
+
node_blueprint.path.should == "/content/foo/bar"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|