skates 0.5.0 → 0.5.3

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.
@@ -40,7 +40,7 @@ module Skates
40
40
  def evaluate
41
41
  return if @view_template == ""
42
42
  raise ViewFileNotFound, "No such file #{@view_template}" unless Skates.views[@view_template]
43
- builder = Nokogiri::XML::Builder.new
43
+ builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8')
44
44
  builder.stream do |xml|
45
45
  eval(Skates.views[@view_template], binding, @view_template, 1)
46
46
  end
@@ -98,7 +98,7 @@ module Skates
98
98
  stream["version"] = "1.0"
99
99
  paste_content_here = Nokogiri::XML::Node.new("paste_content_here", doc)
100
100
  stream.add_child(paste_content_here)
101
- doc.to_xml.split('<paste_content_here/>').first
101
+ doc.to_xml(:encoding => "UTF-8").split('<paste_content_here/>').first
102
102
  end
103
103
 
104
104
  ##
@@ -30,7 +30,7 @@ module Skates
30
30
  doc.add_child(stream)
31
31
  paste_content_here= Nokogiri::XML::Node.new("paste_content_here", doc)
32
32
  stream.add_child(paste_content_here)
33
- start, stop = doc.to_xml.split('<paste_content_here/>')
33
+ start, stop = doc.to_xml(:encoding => "UTF-8").split('<paste_content_here/>')
34
34
  send_xml(start)
35
35
  end
36
36
 
@@ -122,7 +122,7 @@ module Skates
122
122
  # Called when a full stanza has been received and returns it to the central router to be sent to the corresponding controller.
123
123
  def receive_stanza(stanza)
124
124
  Skates.logger.debug {
125
- "PARSED : #{stanza.to_xml}"
125
+ "PARSED : #{stanza.to_xml(:encoding => "UTF-8")}"
126
126
  }
127
127
  # If not handled by subclass (for authentication)
128
128
  case stanza.name
@@ -152,8 +152,10 @@ module Skates
152
152
  begin
153
153
  if xml.is_a? Nokogiri::XML::NodeSet
154
154
  xml.each do |element|
155
- send_chunk(element.to_s)
155
+ send_chunk(element.to_xml(:encoding => "UTF-8"))
156
156
  end
157
+ elsif xml.is_a? Nokogiri::XML::Node
158
+ send_chunk(xml.to_xml(:encoding => "UTF-8"))
157
159
  else
158
160
  send_chunk(xml.to_s)
159
161
  end
@@ -41,7 +41,7 @@ module Skates
41
41
  # If no element is being parsed, then, we create a new document, to which we add this new element as root. (we create one document per stanza to avoid memory problems)
42
42
  def start_element(qname, attributes = [])
43
43
  clear_characters_buffer
44
- @doc ||= Nokogiri::XML::Document.new
44
+ @doc ||= Nokogiri::XML::Document.new
45
45
  @elem ||= @doc # If we have no current element, then, we take the doc
46
46
  @parent = @elem
47
47
 
@@ -129,7 +129,7 @@ module Skates
129
129
  end
130
130
 
131
131
  def set_attribute(key, value)
132
- @elem.set_attribute key, Skates.decode_xml(value)
132
+ @elem.set_attribute(key, Skates.decode_xml(value))
133
133
  end
134
134
 
135
135
  def set_namespace(key, value)
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skates
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 13
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 5
8
- - 0
9
- version: 0.5.0
9
+ - 3
10
+ version: 0.5.3
10
11
  platform: ruby
11
12
  authors:
12
13
  - julien Genestoux
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-02-21 00:00:00 -05:00
18
+ date: 2011-06-23 00:00:00 +02:00
18
19
  default_executable: skates
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 59
28
30
  segments:
29
31
  - 0
30
32
  - 12
@@ -40,6 +42,7 @@ dependencies:
40
42
  requirements:
41
43
  - - ">="
42
44
  - !ruby/object:Gem::Version
45
+ hash: 3
43
46
  segments:
44
47
  - 0
45
48
  version: "0"
@@ -53,6 +56,7 @@ dependencies:
53
56
  requirements:
54
57
  - - "="
55
58
  - !ruby/object:Gem::Version
59
+ hash: 15
56
60
  segments:
57
61
  - 1
58
62
  - 4
@@ -68,6 +72,7 @@ dependencies:
68
72
  requirements:
69
73
  - - ">="
70
74
  - !ruby/object:Gem::Version
75
+ hash: 3
71
76
  segments:
72
77
  - 0
73
78
  version: "0"
@@ -113,22 +118,6 @@ files:
113
118
  - templates/skates/log/test.log
114
119
  - templates/skates/script/component
115
120
  - templates/skates/tmp/pids/README
116
- - spec/bin/skates_spec.rb
117
- - spec/em_mock.rb
118
- - spec/lib/skates/base/controller_spec.rb
119
- - spec/lib/skates/base/stanza_spec.rb
120
- - spec/lib/skates/base/view_spec.rb
121
- - spec/lib/skates/client_connection_spec.rb
122
- - spec/lib/skates/component_connection_spec.rb
123
- - spec/lib/skates/generator_spec.rb
124
- - spec/lib/skates/router/dsl_spec.rb
125
- - spec/lib/skates/router_spec.rb
126
- - spec/lib/skates/runner_spec.rb
127
- - spec/lib/skates/xmpp_connection_spec.rb
128
- - spec/lib/skates/xmpp_parser_spec.rb
129
- - spec/spec_helper.rb
130
- - test/skates_test.rb
131
- - test/test_helper.rb
132
121
  has_rdoc: true
133
122
  homepage: http://github.com/julien51/skates
134
123
  licenses: []
@@ -143,6 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
132
  requirements:
144
133
  - - ">="
145
134
  - !ruby/object:Gem::Version
135
+ hash: 3
146
136
  segments:
147
137
  - 0
148
138
  version: "0"
@@ -151,6 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
141
  requirements:
152
142
  - - ">="
153
143
  - !ruby/object:Gem::Version
144
+ hash: 3
154
145
  segments:
155
146
  - 0
156
147
  version: "0"
@@ -167,24 +158,9 @@ requirements:
167
158
  - resolv
168
159
  - utf8cleaner
169
160
  rubyforge_project: skates
170
- rubygems_version: 1.3.7
161
+ rubygems_version: 1.4.2
171
162
  signing_key:
172
163
  specification_version: 3
173
164
  summary: Skates is a framework to create EventMachine based XMPP External Components in Ruby.
174
- test_files:
175
- - spec/bin/skates_spec.rb
176
- - spec/em_mock.rb
177
- - spec/lib/skates/base/controller_spec.rb
178
- - spec/lib/skates/base/stanza_spec.rb
179
- - spec/lib/skates/base/view_spec.rb
180
- - spec/lib/skates/client_connection_spec.rb
181
- - spec/lib/skates/component_connection_spec.rb
182
- - spec/lib/skates/generator_spec.rb
183
- - spec/lib/skates/router/dsl_spec.rb
184
- - spec/lib/skates/router_spec.rb
185
- - spec/lib/skates/runner_spec.rb
186
- - spec/lib/skates/xmpp_connection_spec.rb
187
- - spec/lib/skates/xmpp_parser_spec.rb
188
- - spec/spec_helper.rb
189
- - test/skates_test.rb
190
- - test/test_helper.rb
165
+ test_files: []
166
+
File without changes
data/spec/em_mock.rb DELETED
@@ -1,42 +0,0 @@
1
- ##
2
- # Mock for EventMachine
3
- module EventMachine
4
-
5
- def self.mock?
6
- true
7
- end
8
-
9
- ##
10
- # Mock for the Connection Class
11
- class Connection
12
- def self.new(*args)
13
- allocate.instance_eval do
14
- # Call a superclass's #initialize if it has one
15
- initialize(*args)
16
- # Store signature and run #post_init
17
- post_init
18
- self
19
- end
20
- end
21
- end
22
-
23
- ##
24
- # Stub for run
25
- def self.run(proc)
26
- proc.call
27
- end
28
-
29
- ##
30
- # Stub for epoll
31
- def self.epoll; end
32
-
33
- ##
34
- # Stub! to stop the event loop.
35
- def self.stop_event_loop; end
36
-
37
- ##
38
- # Stub for connect (should return a connection object)
39
- def self.connect(host, port, handler, params)
40
- handler.new(params)
41
- end
42
- end
@@ -1,205 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../../spec_helper'
2
-
3
- describe Skates::Base::Controller do
4
-
5
- before(:each) do
6
- Skates.views.stub!(:[]).and_return("") # Stubbing read for view
7
- end
8
-
9
- describe ".initialize" do
10
- before(:each) do
11
- @params = {:a => "a", :b => 1, :c => {:key => "value"}, :stanza => "<hello>world</hello>"}
12
- end
13
-
14
- it "should have a stanza instance" do
15
- stanza = mock(Object)
16
- c = Skates::Base::Controller.new(stanza)
17
-
18
- c.instance_variables.should be_include :"@stanza"
19
- c.instance_variable_get(:"@stanza").should == stanza
20
- end
21
-
22
- it "should not be rendered yet" do
23
- c = Skates::Base::Controller.new(@params)
24
- c.rendered.should_not be_true
25
- end
26
- end
27
-
28
- describe ".perform" do
29
- before(:each) do
30
- @action = :subscribe
31
- params = {:stanza => "<hello>world</hello>"}
32
- @controller = Skates::Base::Controller.new(params)
33
- @controller.class.send(:define_method, @action) do # Defining the action method
34
- # Do something
35
- end
36
- end
37
-
38
- it "should setup the action to the param" do
39
- @controller.perform(@action) do
40
- # Do something
41
- end
42
- @controller.instance_variable_get("@action_name").should == @action
43
- end
44
-
45
- it "should call the action" do
46
- @controller.should_receive(:send).with(@action).and_return()
47
- @controller.perform(@action) do
48
- # Do something
49
- end
50
- end
51
-
52
- it "should write an error to the log in case of failure of the action" do
53
- @controller.stub!(:send).with(@action).and_raise(StandardError)
54
- Skates.logger.should_receive(:error)
55
- @controller.perform(@action) do
56
- # Do something
57
- end
58
- end
59
-
60
- it "should call render" do
61
- @controller.should_receive(:render)
62
- @controller.perform(@action) do
63
- # Do something
64
- end
65
- end
66
- end
67
-
68
- describe ".render" do
69
- before(:each) do
70
- @controller = Skates::Base::Controller.new({})
71
- @controller.action_name = :subscribe
72
- end
73
-
74
- it "should assign a value to view" do
75
- @controller.render
76
- @controller.instance_variable_get("@view").should_not be_nil
77
- end
78
-
79
- describe "with :nothing option" do
80
- it "should not render any file" do
81
- @controller.should_not_receive(:render_for_file)
82
- @controller.render :nothing => true
83
- end
84
- end
85
-
86
- describe "with no option" do
87
- it "should call render with default_file_name if no option is provided" do
88
- @controller.should_receive(:default_template_name)
89
- @controller.render
90
- end
91
- end
92
-
93
- describe "with an :action option" do
94
- it "should call render with the file name corresponding to the action given as option" do
95
- action = :unsubscribe
96
- @controller.should_receive(:default_template_name).with("#{action}")
97
- @controller.render(:action => action)
98
- end
99
- end
100
-
101
- describe "with a file option" do
102
- it "should call render_for_file with the correct path if an option file is provided" do
103
- file = "myfile"
104
- @controller.should_receive(:render_for_file)
105
- @controller.render(:file => file)
106
- end
107
- end
108
-
109
- it "should not render twice when called twice" do
110
- @controller.render
111
- @controller.should_not_receive(:render_for_file)
112
- @controller.render
113
- end
114
- end
115
-
116
- describe ".assigns" do
117
-
118
- before(:each) do
119
- @stanza = mock(Skates::Base::Stanza)
120
- @controller = Skates::Base::Controller.new(@stanza)
121
- end
122
-
123
- it "should be a hash" do
124
- @controller.assigns.should be_an_instance_of(Hash)
125
- end
126
-
127
- it "should only contain the @stanza if the action hasn't been called yet" do
128
- @controller.assigns.should_not be_empty
129
- @controller.assigns["stanza"].should == @stanza
130
- end
131
-
132
- it "should return an hash containing all instance variables defined in the action" do
133
- vars = {"a" => 1, "b" => "b", "c" => { "d" => 4}}
134
- class MyController < Skates::Base::Controller
135
- def do_something
136
- @a = 1
137
- @b = "b"
138
- @c = { "d" => 4 }
139
- end
140
- end
141
- @controller = MyController.new(@stanza)
142
- @controller.do_something
143
- @controller.assigns.should == vars.merge("stanza" => @stanza, "view" => nil)
144
- end
145
- end
146
-
147
- describe ".evaluate" do
148
- before(:each) do
149
- @controller = Skates::Base::Controller.new()
150
- end
151
-
152
- it "should evaluate the view" do
153
- view = mock(Skates::Base::View)
154
- response = "hello"
155
- @controller.instance_variable_set("@view", view)
156
- view.should_receive(:evaluate).and_return(response)
157
- @controller.evaluate.should == response
158
- end
159
- end
160
-
161
- describe ".view_path" do
162
- it "should return complete file path to the file given in param" do
163
- @controller = Skates::Base::Controller.new()
164
- file_name = "myfile"
165
- @controller.__send__(:view_path, file_name).should == File.join("app/views", "#{"Skates::Base::Controller".gsub("Controller","").downcase}", file_name)
166
- end
167
- end
168
-
169
- describe ".default_template_name" do
170
- before(:each) do
171
- @controller = Skates::Base::Controller.new()
172
- end
173
-
174
- it "should return the view file name if a file is given in param" do
175
- @controller.__send__(:default_template_name, "myaction").should == "myaction.xml.builder"
176
- end
177
-
178
- it "should return the view file name based on the action_name if no file has been given" do
179
- @controller.action_name = "a_great_action"
180
- @controller.__send__(:default_template_name).should == "a_great_action.xml.builder"
181
- end
182
- end
183
-
184
- describe ".render_for_file" do
185
-
186
- before(:each) do
187
- @controller = Skates::Base::Controller.new()
188
- @block = Proc.new {
189
- # Do something
190
- }
191
- @controller.class.send(:define_method, "action") do # Defining the action method
192
- # Do something
193
- end
194
- @controller.perform(:action, &@block)
195
- @view = Skates::Base::View.new("path_to_a_file", {})
196
- end
197
-
198
- it "should instantiate a new view, with the file provided and the hashed_variables" do
199
- Skates::Base::View.should_receive(:new).with("path_to_a_file",an_instance_of(Hash)).and_return(@view)
200
- @controller.__send__(:render_for_file, "path_to_a_file")
201
- end
202
-
203
- end
204
-
205
- end
@@ -1,120 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../../spec_helper'
2
-
3
- describe Skates::Base::Stanza do
4
-
5
- describe "initialize" do
6
-
7
- context "when the stanza is an IQ" do
8
-
9
- before(:each) do
10
- xml = <<-EOXML
11
- <iq type='get'
12
- from='romeo@montague.net/orchard'
13
- to='plays.shakespeare.lit'
14
- id='info1'>
15
- <query xmlns='http://jabber.org/protocol/disco#configuration'/>
16
- </iq>
17
- EOXML
18
- xml = Nokogiri::XML(xml)
19
- @stanza = Skates::Base::Stanza.new(xml.root)
20
- end
21
-
22
- it "should have the right from" do
23
- @stanza.from.should == "romeo@montague.net/orchard"
24
- end
25
-
26
- it "should have the right id" do
27
- @stanza.id.should == "info1"
28
- end
29
-
30
- it "should have the right to" do
31
- @stanza.to.should == "plays.shakespeare.lit"
32
- end
33
-
34
- it "should have the right type" do
35
- @stanza.type.should == "get"
36
- end
37
-
38
- it "should have the right name" do
39
- @stanza.name.should == "iq"
40
- end
41
-
42
- end
43
-
44
-
45
-
46
- context "when the stanza is a presence" do
47
-
48
- before(:each) do
49
- xml = <<-EOXML
50
- <presence from='firehoser-test.superfeedr.com' to='testparsr@superfeedr.com/skates_client_7008465' type='error' />
51
- EOXML
52
- xml = Nokogiri::XML(xml)
53
- @stanza = Skates::Base::Stanza.new(xml.root)
54
- end
55
-
56
- it "should have the right from" do
57
- @stanza.from.should == "firehoser-test.superfeedr.com"
58
- end
59
-
60
- it "should have the right id" do
61
- @stanza.id.should be_nil
62
- end
63
-
64
- it "should have the right to" do
65
- @stanza.to.should == "testparsr@superfeedr.com/skates_client_7008465"
66
- end
67
-
68
- it "should have the right type" do
69
- @stanza.type.should == "error"
70
- end
71
-
72
- it "should have the right name" do
73
- @stanza.name.should == "presence"
74
- end
75
-
76
- end
77
-
78
- context "when the stanza is a message" do
79
-
80
- before(:each) do
81
- xml = <<-EOXML
82
- <message to="monitor@superfeedr.com" from="test-firehoser.superfeedr.com">
83
- <event xmlns="http://jabber.org/protocol/pubsub#event">
84
- <status xmlns="http://superfeedr.com/xmpp-pubsub-ext" feed="http://domain.tld/feed.xml">
85
- <http code="200">All went very fine. Thanks for asking!</http>
86
- <next_fetch>2010-02-03T01:32:58+01:00</next_fetch>
87
- <title></title>
88
- </status>
89
- </event>
90
- </message>
91
- EOXML
92
- xml = Nokogiri::XML(xml)
93
- @stanza = Skates::Base::Stanza.new(xml.root)
94
- end
95
-
96
- it "should have the right from" do
97
- @stanza.from.should == "test-firehoser.superfeedr.com"
98
- end
99
-
100
- it "should have the right id" do
101
- @stanza.id.should be_nil
102
- end
103
-
104
- it "should have the right to" do
105
- @stanza.to.should == "monitor@superfeedr.com"
106
- end
107
-
108
- it "should have the right type" do
109
- @stanza.type.should be_nil
110
- end
111
-
112
- it "should have the right name" do
113
- @stanza.name.should == "message"
114
- end
115
-
116
- end
117
-
118
- end
119
-
120
- end