skates 0.2.11 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -31,7 +31,6 @@ begin
31
31
  "lib/skates/generator.rb",
32
32
  "lib/skates/xmpp_connection.rb",
33
33
  "lib/skates/xmpp_parser.rb",
34
- "lib/skates/xpath_helper.rb",
35
34
  "LICENSE",
36
35
  "Rakefile",
37
36
  "README.rdoc",
@@ -13,8 +13,8 @@ module Skates
13
13
  end
14
14
 
15
15
  # Match an xpath.
16
- def xpath(path)
17
- @routes << {"xpath" => path}
16
+ def xpath(path, namespaces = {})
17
+ @routes << {"xpath" => [path, namespaces]}
18
18
  self
19
19
  end
20
20
 
@@ -26,16 +26,6 @@ module Skates
26
26
  self
27
27
  end
28
28
 
29
- # Match a disco_info query.
30
- def disco_info(node = nil)
31
- disco_for(:info, node)
32
- end
33
-
34
- # Match a disco_items query.
35
- def disco_items(node = nil)
36
- disco_for(:items, node)
37
- end
38
-
39
29
  # Map a route to a specific controller and action.
40
30
  def to(params)
41
31
  last = @routes.pop
data/lib/skates/router.rb CHANGED
@@ -93,7 +93,7 @@ module Skates
93
93
  ##
94
94
  # Checks that the route matches the stanzas and calls the the action on the controller.
95
95
  def accepts?(stanza)
96
- stanza.xpath(@xpath, XpathHelper.new).empty? ? false : self
96
+ stanza.xpath(*@xpath).empty? ? false : self
97
97
  end
98
98
 
99
99
  end
@@ -90,8 +90,8 @@ module Skates
90
90
  def add_namespaces_and_attributes_to_current_node(attrs)
91
91
  # Namespaces
92
92
  attrs.select {|k| k.is_a? Array}.each do |pair|
93
- # set_namespace(pair[0], pair[1])
94
- set_normal_attribute(pair[0], pair[1])
93
+ set_namespace(pair[0], pair[1])
94
+ # set_normal_attribute(pair[0], pair[1])
95
95
  end
96
96
  # Attributes
97
97
  attrs.select {|k| k.is_a? String}.in_groups_of(2) do |pair|
data/lib/skates.rb CHANGED
@@ -21,7 +21,6 @@ require 'skates/client_connection'
21
21
  require 'skates/router'
22
22
  require 'skates/runner'
23
23
  require 'skates/generator'
24
- require 'skates/xpath_helper'
25
24
  require 'skates/base/controller'
26
25
  require 'skates/base/view'
27
26
  require 'skates/base/stanza'
@@ -34,39 +34,13 @@ describe Skates::Router::DSL do
34
34
  routes.length.should == 1
35
35
  end
36
36
 
37
- describe :disco_info do
38
- it "matches the root disco#info namespace" do
39
- Skates.router.draw do
40
- disco_info.to(:controller => "controller", :action => "action")
41
- end
42
- route = Skates.router.instance_variable_get("@routes").last
43
- route.xpath.should == "//iq[@type='get']/*[namespace(., 'query', 'http://jabber.org/protocol/disco#info')]"
44
- end
45
-
46
- it "matches the disco#info namespace for the specified node" do
47
- Skates.router.draw do
48
- disco_info("test").to(:controller => "controller", :action => "action")
49
- end
50
- route = Skates.router.instance_variable_get("@routes").last
51
- route.xpath.should == "//iq[@type='get']/*[namespace(., 'query', 'http://jabber.org/protocol/disco#info') and @node = 'test']"
52
- end
53
- end
54
-
55
- describe :disco_items do
56
- it "matches the root disco#items namespace" do
57
- Skates.router.draw do
58
- disco_items.to(:controller => "controller", :action => "action")
59
- end
60
- route = Skates.router.instance_variable_get("@routes").last
61
- route.xpath.should == "//iq[@type='get']/*[namespace(., 'query', 'http://jabber.org/protocol/disco#items')]"
62
- end
63
-
64
- it "matches the disco#items namespace for the specified node" do
65
- Skates.router.draw do
66
- disco_items("test").to(:controller => "controller", :action => "action")
67
- end
68
- route = Skates.router.instance_variable_get("@routes").last
69
- route.xpath.should == "//iq[@type='get']/*[namespace(., 'query', 'http://jabber.org/protocol/disco#items') and @node = 'test']"
37
+ it "should create routes with the right namespace" do
38
+ Skates.router.draw do
39
+ xpath("//ns:test", {"ns" => "http://my.namespace.uri"}
40
+ ).to(:controller => "controller", :action => "action").priority(5)
70
41
  end
42
+ route = Skates.router.instance_variable_get("@routes").first
43
+ route.xpath.should == ["//ns:test", {"ns"=>"http://my.namespace.uri"}]
71
44
  end
45
+
72
46
  end
@@ -23,8 +23,8 @@ describe Skates::Route do
23
23
  describe ".accepts?" do
24
24
  it "should check the stanza with Xpath" do
25
25
  mock_stanza = mock(Object)
26
- route = Skates::Route.new("controller" => "bar", "action" => "bar", "xpath" => "//message")
27
- mock_stanza.should_receive(:xpath).with(route.xpath, instance_of(Skates::XpathHelper)).and_return([])
26
+ route = Skates::Route.new("controller" => "bar", "action" => "bar", "xpath" => ["//message", {}])
27
+ mock_stanza.should_receive(:xpath).with("//message", {}).and_return([])
28
28
  route.accepts?(mock_stanza)
29
29
  end
30
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - julien Genestoux
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-27 00:00:00 +01:00
12
+ date: 2010-02-05 00:00:00 +01:00
13
13
  default_executable: skates
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -89,7 +89,6 @@ files:
89
89
  - lib/skates/runner.rb
90
90
  - lib/skates/xmpp_connection.rb
91
91
  - lib/skates/xmpp_parser.rb
92
- - lib/skates/xpath_helper.rb
93
92
  - templates/skates/app/controllers/controller.rb
94
93
  - templates/skates/app/stanzas/stanza.rb
95
94
  - templates/skates/app/views/view.rb
@@ -154,7 +153,6 @@ test_files:
154
153
  - spec/lib/skates/runner_spec.rb
155
154
  - spec/lib/skates/xmpp_connection_spec.rb
156
155
  - spec/lib/skates/xmpp_parser_spec.rb
157
- - spec/lib/skates/xpath_helper_spec.rb
158
156
  - spec/spec_helper.rb
159
157
  - test/skates_test.rb
160
158
  - test/test_helper.rb
@@ -1,13 +0,0 @@
1
- module Skates
2
-
3
- # Custom XPath functions for stanza-routing.
4
- class XpathHelper
5
-
6
- # Match nodes of the given name with the given namespace URI.
7
- def namespace(set, name, nsuri)
8
- set.find_all do |n|
9
- n.name == name && n.namespaces.values.include?(nsuri)
10
- end
11
- end
12
- end
13
- end
@@ -1,25 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe Skates::XpathHelper do
4
- describe "namespace method" do
5
- before do
6
- @doc = Nokogiri::XML(<<-eoxml)
7
- <iq from='me@my.jid/Eee' to='component.my.jid'
8
- xml:lang='en' type='get' id='43'><query
9
- xmlns='http://jabber.org/protocol/disco#info'/></iq>
10
- eoxml
11
- end
12
-
13
- it "matches nodes of the given name with the given namespace URI" do
14
- @doc.xpath("//iq/*[namespace(., 'query', 'http://jabber.org/protocol/disco#info')]", Skates::XpathHelper.new).length.should == 1
15
- end
16
-
17
- it "does not match a namespace URI if the node names differ" do
18
- @doc.xpath("//iq/*[namespace(., 'que', 'http://jabber.org/protocol/disco#info')]", Skates::XpathHelper.new).length.should == 0
19
- end
20
-
21
- it "does not match a node if the namespace URIs differ" do
22
- @doc.xpath("//iq/*[namespace(., 'query', 'http://jabber.org/protocol/disco#inf')]", Skates::XpathHelper.new).length.should == 0
23
- end
24
- end
25
- end