cancan-rest-links 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,17 @@
1
- = cancan-rest-links
1
+ # CanCan REST links
2
2
 
3
- Description goes here.
3
+ REST link helpers for the [CanCan](http://github.com/ryanb/cancan) permission system.
4
4
 
5
- == Note on Patches/Pull Requests
5
+ Note: The link helpers require a hash called #auth_labels, which is used to look-up a label to display for the link
6
+
7
+ <pre>
8
+ label = auth_labels[:new]
9
+ ...
10
+ </pre>
11
+
12
+ An example of this functionality can be found in the [Cream](http://github.com/kristianmandrup/cream) framework where this gem is used.
13
+
14
+ ## Note on Patches/Pull Requests
6
15
 
7
16
  * Fork the project.
8
17
  * Make your feature addition or bug fix.
@@ -12,6 +21,6 @@ Description goes here.
12
21
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
22
  * Send me a pull request. Bonus points for topic branches.
14
23
 
15
- == Copyright
24
+ ## Copyright
16
25
 
17
26
  Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
data/Rakefile CHANGED
@@ -7,10 +7,10 @@ begin
7
7
  gem.email = "kmandrup@gmail.com"
8
8
  gem.homepage = "http://github.com/kristianmandrup/cancan-rest-links"
9
9
  gem.authors = ["Kristian Mandrup"]
10
- gem.add_development_dependency "rspec", "~> 2.0.0.beta.22"
10
+ gem.add_development_dependency "rspec", ">= 2.0.0"
11
11
  gem.add_development_dependency "rspec-action_view", "~> 0.3.1"
12
12
 
13
- gem.add_dependency 'cancan', "~> 1.3.4"
13
+ gem.add_dependency 'cancan', "~> 1.4.0"
14
14
  gem.add_dependency 'require_all', "~> 1.2.0"
15
15
  gem.add_dependency 'sugar-high', "~> 0.2.10"
16
16
  gem.add_dependency 'r3_plugin_toolbox', "~> 0.3.6"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -5,23 +5,23 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cancan-rest-links}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = %q{2010-09-26}
12
+ s.date = %q{2010-10-18}
13
13
  s.description = %q{Guard your links with permissions}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.markdown"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
22
  ".rspec",
23
23
  "LICENSE",
24
- "README.rdoc",
24
+ "README.markdown",
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "cancan-rest-links.gemspec",
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "lib/cancan-rest-links/rails/configure.rb",
32
32
  "log/development.log",
33
33
  "spec/cancan-rest-links/link_helpers_spec.rb",
34
+ "spec/cancan-rest-links/link_with_cream_spec.rb",
34
35
  "spec/cancan-rest-links/rails/configure_spec.rb",
35
36
  "spec/spec_helper.rb"
36
37
  ]
@@ -41,6 +42,7 @@ Gem::Specification.new do |s|
41
42
  s.summary = %q{Rest link helpers for CanCan}
42
43
  s.test_files = [
43
44
  "spec/cancan-rest-links/link_helpers_spec.rb",
45
+ "spec/cancan-rest-links/link_with_cream_spec.rb",
44
46
  "spec/cancan-rest-links/rails/configure_spec.rb",
45
47
  "spec/spec_helper.rb"
46
48
  ]
@@ -50,24 +52,24 @@ Gem::Specification.new do |s|
50
52
  s.specification_version = 3
51
53
 
52
54
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
- s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
55
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
54
56
  s.add_development_dependency(%q<rspec-action_view>, ["~> 0.3.1"])
55
- s.add_runtime_dependency(%q<cancan>, ["~> 1.3.4"])
57
+ s.add_runtime_dependency(%q<cancan>, ["~> 1.4.0"])
56
58
  s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
57
59
  s.add_runtime_dependency(%q<sugar-high>, ["~> 0.2.10"])
58
60
  s.add_runtime_dependency(%q<r3_plugin_toolbox>, ["~> 0.3.6"])
59
61
  else
60
- s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
62
+ s.add_dependency(%q<rspec>, [">= 2.0.0"])
61
63
  s.add_dependency(%q<rspec-action_view>, ["~> 0.3.1"])
62
- s.add_dependency(%q<cancan>, ["~> 1.3.4"])
64
+ s.add_dependency(%q<cancan>, ["~> 1.4.0"])
63
65
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
64
66
  s.add_dependency(%q<sugar-high>, ["~> 0.2.10"])
65
67
  s.add_dependency(%q<r3_plugin_toolbox>, ["~> 0.3.6"])
66
68
  end
67
69
  else
68
- s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
70
+ s.add_dependency(%q<rspec>, [">= 2.0.0"])
69
71
  s.add_dependency(%q<rspec-action_view>, ["~> 0.3.1"])
70
- s.add_dependency(%q<cancan>, ["~> 1.3.4"])
72
+ s.add_dependency(%q<cancan>, ["~> 1.4.0"])
71
73
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
72
74
  s.add_dependency(%q<sugar-high>, ["~> 0.2.10"])
73
75
  s.add_dependency(%q<r3_plugin_toolbox>, ["~> 0.3.6"])
@@ -9,7 +9,7 @@ end
9
9
  describe CanCan::Link::Rest do
10
10
  describe '#index_link' do
11
11
  it "should create an index link" do
12
- with_engine do |e, view|
12
+ view_engine do |e, view|
13
13
  label = 'index'
14
14
  path = 'post/index'
15
15
  post = Post.new
@@ -30,7 +30,7 @@ describe CanCan::Link::Rest do
30
30
 
31
31
  describe '#create_link' do
32
32
  it "should create a create link" do
33
- with_engine do |e, view|
33
+ view_engine do |e, view|
34
34
  label = 'create'
35
35
  path = 'post/create'
36
36
  post = Post.new
@@ -51,7 +51,7 @@ describe CanCan::Link::Rest do
51
51
 
52
52
  describe '#edit_link' do
53
53
  it "should create a create link" do
54
- with_engine do |e, view|
54
+ view_engine do |e, view|
55
55
  label = 'create'
56
56
  path = 'post/create'
57
57
  post = Post.new
@@ -71,7 +71,7 @@ describe CanCan::Link::Rest do
71
71
 
72
72
  describe '#delete_link' do
73
73
  it "should create a delete link" do
74
- with_engine do |e, view|
74
+ view_engine do |e, view|
75
75
  label = 'delete'
76
76
  path = 'post/delete'
77
77
  post = Post.new
@@ -92,7 +92,7 @@ describe CanCan::Link::Rest do
92
92
 
93
93
  describe '#show_link' do
94
94
  it "should create a show link" do
95
- with_engine do |e, view|
95
+ view_engine do |e, view|
96
96
  label = 'show'
97
97
  path = 'post/show'
98
98
  post = Post.new
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ # extend_view_with CanCan::Link::Rest
4
+ require 'cancan-rest-links/rails/configure'
5
+ require 'cream'
6
+
7
+ class Post
8
+ end
9
+
10
+ # From cream: The following module should be added to Rails view
11
+ # translate_labels has been stubbed out to just return the action as the translation for each "action"
12
+ module Cream::Helper
13
+ module AuthLabel
14
+ def translate_labels
15
+ labels = {}
16
+ %w{new edit delete show sign_in sign_out sign_up edit_registration}.each do |action|
17
+ labels[action.to_sym] = action
18
+ end
19
+ labels[:confirm] = 'confirm'
20
+ labels
21
+ end
22
+ end
23
+ end
24
+
25
+ describe CanCan::Link::Rest do
26
+ describe '#index_link' do
27
+ it "should create an index link" do
28
+
29
+ # TODO: Should be renamed to:- view_engine do ...
30
+ # view engine
31
+ view_engine do |e, view|
32
+ label = 'index'
33
+ path = 'post/index'
34
+ post = Post.new
35
+
36
+ puts view.auth_labels.inspect
37
+
38
+ view.stubs(:posts_path).returns path
39
+ view.stubs(:can?).returns true
40
+ view.stubs(:link_to).with(label, path).returns 'it works'
41
+
42
+ res = e.run_template_locals :post => post, :name => label do
43
+ %{<%= index_link(post, name) %> }
44
+ end
45
+ res.should match /it works/
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#create_link' do
51
+ it "should create a create link" do
52
+ view_engine do |e, view|
53
+ label = 'create'
54
+ path = 'post/create'
55
+ post = Post.new
56
+
57
+ view.stubs(:new_post_path).returns path
58
+ view.stubs(:can?).returns true
59
+ view.stubs(:link_to).with(label, path).returns 'it works'
60
+
61
+ res = e.run_template_locals :post => post, :name => label do
62
+ %{<%= create_link(post, name) %> }
63
+ end
64
+ res.should match /it works/
65
+ end
66
+ end
67
+ end
68
+
69
+ describe '#edit_link' do
70
+ it "should create a create link" do
71
+ view_engine do |e, view|
72
+ label = 'create'
73
+ path = 'post/create'
74
+ post = Post.new
75
+
76
+ view.stubs(:can?).returns true
77
+ view.stubs(:link_to).with(label, [:edit, post]).returns 'it works'
78
+
79
+ res = e.run_template_locals :post => post, :name => label do
80
+ %{<%= edit_link(post, name) %> }
81
+ end
82
+ res.should match /it works/
83
+ end
84
+ end
85
+ end
86
+
87
+ describe '#delete_link' do
88
+ it "should create a delete link" do
89
+ view_engine do |e, view|
90
+ label = 'delete'
91
+ path = 'post/delete'
92
+ post = Post.new
93
+
94
+ view.stubs(:can?).returns true
95
+ view.stubs(:link_to).returns 'it works'
96
+
97
+ res = e.run_template_locals :post => post, :name => label do
98
+ %{<%= delete_link(post, name) %> }
99
+ end
100
+ res.should match /it works/
101
+ end
102
+ end
103
+ end
104
+
105
+
106
+ describe '#show_link' do
107
+ it "should create a show link" do
108
+ view_engine do |e, view|
109
+ label = 'show'
110
+ path = 'post/show'
111
+ post = Post.new
112
+
113
+ view.stubs(:can?).returns true
114
+ view.stubs(:link_to).with(label, post).returns 'it works'
115
+
116
+ res = e.run_template_locals :post => post, :name => label do
117
+ %{<%= show_link(post, name) %> }
118
+ end
119
+ res.should match /it works/
120
+ end
121
+ end
122
+ end
123
+ end
124
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-26 00:00:00 +02:00
17
+ date: 2010-10-18 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -23,15 +23,13 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ~>
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 2
30
30
  - 0
31
31
  - 0
32
- - beta
33
- - 22
34
- version: 2.0.0.beta.22
32
+ version: 2.0.0
35
33
  type: :development
36
34
  version_requirements: *id001
37
35
  - !ruby/object:Gem::Dependency
@@ -59,9 +57,9 @@ dependencies:
59
57
  - !ruby/object:Gem::Version
60
58
  segments:
61
59
  - 1
62
- - 3
63
60
  - 4
64
- version: 1.3.4
61
+ - 0
62
+ version: 1.4.0
65
63
  type: :runtime
66
64
  version_requirements: *id003
67
65
  - !ruby/object:Gem::Dependency
@@ -117,13 +115,13 @@ extensions: []
117
115
 
118
116
  extra_rdoc_files:
119
117
  - LICENSE
120
- - README.rdoc
118
+ - README.markdown
121
119
  files:
122
120
  - .document
123
121
  - .gitignore
124
122
  - .rspec
125
123
  - LICENSE
126
- - README.rdoc
124
+ - README.markdown
127
125
  - Rakefile
128
126
  - VERSION
129
127
  - cancan-rest-links.gemspec
@@ -133,6 +131,7 @@ files:
133
131
  - lib/cancan-rest-links/rails/configure.rb
134
132
  - log/development.log
135
133
  - spec/cancan-rest-links/link_helpers_spec.rb
134
+ - spec/cancan-rest-links/link_with_cream_spec.rb
136
135
  - spec/cancan-rest-links/rails/configure_spec.rb
137
136
  - spec/spec_helper.rb
138
137
  has_rdoc: true
@@ -169,5 +168,6 @@ specification_version: 3
169
168
  summary: Rest link helpers for CanCan
170
169
  test_files:
171
170
  - spec/cancan-rest-links/link_helpers_spec.rb
171
+ - spec/cancan-rest-links/link_with_cream_spec.rb
172
172
  - spec/cancan-rest-links/rails/configure_spec.rb
173
173
  - spec/spec_helper.rb