Skip to content

Commit ea679a5

Browse files
committed
Specs and version
1 parent 4d626da commit ea679a5

File tree

3 files changed

+69
-7
lines changed

3 files changed

+69
-7
lines changed

lib/gon/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class Gon
2-
VERSION = '4.0.0beta'
2+
VERSION = '4.0.0'
33
end

lib/gon/watch.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ def clear
4949
@watch_variables = {}
5050
end
5151

52-
def return_variable(value)
53-
controller = Gon::Base.get_controller
54-
55-
controller.render :text => value.to_json
56-
end
57-
5852
private
5953

6054
def set_variable(name, value)
@@ -83,6 +77,12 @@ def return_variable?(variable)
8377
params[:gon_watched_variable] == variable
8478
end
8579

80+
def return_variable(value)
81+
controller = Gon::Base.get_controller
82+
83+
controller.render :text => value.to_json
84+
end
85+
8686
end
8787
end
8888
end

spec/gon/watch_spec.rb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
require 'gon'
2+
3+
describe Gon::Watch do
4+
5+
let(:controller) { ActionController::Base.new }
6+
let(:request) { ActionDispatch::Request.new({}) }
7+
8+
before :each do
9+
controller.request = request
10+
controller.params = {}
11+
env = {}
12+
env['ORIGINAL_FULLPATH'] = '/foo'
13+
env['REQUEST_METHOD'] = 'GET'
14+
15+
Gon::Watch.clear
16+
Gon::Request.instance_variable_set(:@request_env, env)
17+
Gon::Request.env['action_controller.instance'] = controller
18+
Gon.clear
19+
end
20+
21+
it 'should add variables to Gon#all_variables hash' do
22+
Gon.a = 1
23+
Gon.watch.b = 2
24+
Gon.all_variables.should == { 'a' => 1, 'b' => 2 }
25+
end
26+
27+
describe '#all_variables' do
28+
29+
it 'should generate array with current request url, method type and variable names' do
30+
Gon.watch.a = 1
31+
Gon.watch.all_variables.should == { 'a' => { 'url' => '/foo', 'method' => 'GET', 'name' => 'a' } }
32+
end
33+
34+
end
35+
36+
describe '#render' do
37+
38+
it 'should render function with variables in gon namespace' do
39+
Gon.watch.a = 1
40+
Gon.watch.render.should =~ /gon\.watch\s=/
41+
Gon.watch.render.should =~ /gon\.watchedVariables/
42+
end
43+
44+
end
45+
46+
it 'should return value of variable if called right request' do
47+
env = Gon::Request.instance_variable_get :@request_env
48+
env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest"
49+
request = ActionDispatch::Request.new env
50+
controller.request = request
51+
params = {}
52+
params[:gon_return_variable] = true
53+
params[:gon_watched_variable] = 'a'
54+
controller.params = params
55+
Gon::Request.env['action_controller.instance'] = controller
56+
57+
controller.should_receive('render').with(:text => '1')
58+
59+
Gon.watch.a = 1
60+
end
61+
62+
end

0 commit comments

Comments
 (0)