js-routes 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/Readme.md CHANGED
@@ -7,7 +7,7 @@ Generates javascript file that defines all Rails named routes as javascript help
7
7
  Your Rails Gemfile:
8
8
 
9
9
  ``` ruby
10
- gem "js-routes"
10
+ gem "js-routes", :require => 'js_routes'
11
11
  ```
12
12
 
13
13
  Your application initializer, like `config/initializers/jsroutes.rb`:
@@ -72,9 +72,17 @@ In order to make routes helpers available globally:
72
72
  jQuery.extend(window, Routes)
73
73
  ```
74
74
 
75
- ### Alternative
75
+ ### What about security?
76
76
 
77
- There are some alternatives available. Advantages of this one are:
77
+ js-routes itself do not have security holes. It makes URLs
78
+ without access protection more reachable by potential attacker.
79
+ In order to prevent this use `:exclude` option for sensitive urls like `/admin_/`
80
+
81
+
82
+ ### Advantages over alternatives
83
+
84
+ There are some alternatives available. Most of them has only basic feature and don't reach the level of quality I accept.
85
+ Advantages of this one are:
78
86
 
79
87
  * Rails3 support
80
88
  * Rich options set
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{js-routes}
8
- s.version = "0.6.0"
8
+ s.version = "0.6.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bogdan Gusiev"]
12
- s.date = %q{2011-08-22}
12
+ s.date = %q{2011-09-12}
13
13
  s.description = %q{Generates javascript file that defines all Rails named routes as javascript helpers}
14
14
  s.email = %q{agresso@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -17,7 +17,7 @@
17
17
  },
18
18
 
19
19
  clean_path: function(path) {
20
- return path.replace(/\.$/m, '').replace(/\/$/m, '');
20
+ return path.replace(/\/+/g, "/").replace(/[\)\(]/g, "").replace(/\.$/m, '').replace(/\/$/m, '');
21
21
  },
22
22
 
23
23
  extract_format: function(options) {
@@ -50,13 +50,29 @@
50
50
  result = "";
51
51
  var opts = Utils.extract_options(number_of_params, args);
52
52
  for (var i=0; i < parts.length; i++) {
53
+ value = args.shift();
53
54
  part = parts[i];
54
- result += part;
55
- result += Utils.path_identifier(args.shift());
55
+ if (Utils.specified(value)) {
56
+ result += part;
57
+ result += Utils.path_identifier(value);
58
+ } else if (!Utils.optional_part(part)) {
59
+ //TODO: make it strict
60
+ //throw new Error("Can not build path: required parameter is null or undefined.");
61
+ result += part;
62
+ }
56
63
  }
57
64
  var format = Utils.extract_format(opts);
58
65
  return Utils.clean_path(result + format) + Utils.serialize(opts);
66
+ },
67
+
68
+ specified: function(value) {
69
+ return !(value === undefined || value === null);
70
+ },
71
+
72
+ optional_part: function(part) {
73
+ return part.match(/\(/);
59
74
  }
75
+
60
76
  };
61
77
 
62
78
  window.NAMESPACE = ROUTES;
@@ -38,10 +38,7 @@ describe JsRoutes do
38
38
  end
39
39
 
40
40
  it "should support routes with reserved javascript words as parameters" do
41
- #TODO: this doesn't actually test what it should test
42
- #because the parameter name is return_id
43
- #need to find the real way to test
44
- evaljs("Routes.return_path(1)").should == "/returns/1"
41
+ evaljs("Routes.object_path(1, 2)").should == "/returns/1/objects/2"
45
42
  end
46
43
 
47
44
  context "when exclude is specified" do
@@ -100,23 +97,44 @@ describe JsRoutes do
100
97
  it "should use this name space for routing" do
101
98
  evaljs("PHM.Routes.inbox_path").should_not be_nil
102
99
  end
103
-
104
100
  end
105
101
 
106
102
  context "when arguments are objects" do
107
- it "should use id property of the object" do
103
+ it "should use id property of the object in path" do
108
104
  evaljs("Routes.inbox_path({id: 1})").should == "/inboxes/1"
109
105
  end
110
106
 
111
- it "should use prefer to_param property over id property" do
107
+ it "should prefer to_param property over id property" do
112
108
  evaljs("Routes.inbox_path({id: 1, to_param: 'my'})").should == "/inboxes/my"
113
109
  end
114
110
 
115
- it "should support still support options argument" do
111
+ it "should support options argument" do
116
112
  evaljs("Routes.inbox_message_path({id:1, to_param: 'my'}, {id:2}, {custom: true, format: 'json'})").should == "/inboxes/my/messages/2.json?custom=true"
117
113
  end
118
114
  end
119
115
 
116
+ context "using optional path fragments" do
117
+ context "but not including them" do
118
+ it "should not include the optional parts" do
119
+ evaljs("Routes.things_path()").should == "/things"
120
+ end
121
+
122
+ it "should treat undefined as non-given optional part" do
123
+ evaljs("Routes.thing_path(undefined, 5)").should == "/things/5"
124
+ end
125
+
126
+ it "should treat null as non-given optional part" do
127
+ evaljs("Routes.thing_path(null, 5)").should == "/things/5"
128
+ end
129
+ end
130
+
131
+ context "and including them" do
132
+ it "should include the optional parts" do
133
+ evaljs("Routes.things_path(5)").should == "/optional/5/things"
134
+ end
135
+ end
136
+ end
137
+
120
138
  describe "generated js" do
121
139
  subject { JsRoutes.generate }
122
140
  it "should have correct function without arguments signature" do
@@ -24,7 +24,14 @@ class App < Rails::Application
24
24
  resources :users
25
25
  end
26
26
 
27
+ scope "/returns/:return" do
28
+ resources :objects
29
+ end
27
30
  resources :returns
31
+
32
+ scope "(/optional/:optional_id)" do
33
+ resources :things
34
+ end
28
35
  end
29
36
  end
30
37
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js-routes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 0
10
- version: 0.6.0
9
+ - 1
10
+ version: 0.6.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bogdan Gusiev
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-22 00:00:00 +03:00
18
+ date: 2011-09-12 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency