cancan-rest-links 0.1.6 → 0.2.0
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.
- data/Changelog.txt +7 -0
- data/Ideas and Planning.txt +2 -0
- data/README.markdown +11 -10
- data/Rakefile +3 -2
- data/VERSION +1 -1
- data/cancan-rest-links.gemspec +23 -10
- data/lib/cancan-rest-links.rb +2 -2
- data/lib/cancan-rest-links/labels.rb +38 -0
- data/lib/cancan-rest-links/{helpers/rest_links.rb → rest_links.rb} +12 -25
- data/lib/generators/cancan/restlinks/restlinks_generator.rb +28 -0
- data/lib/generators/cancan/restlinks/templates/en.yml +9 -0
- data/{spec/cancan-rest-links → sandbox}/link_with_cream_spec.rb +0 -0
- data/spec/cancan-rest-links/generators/restlinks_generator.rb +34 -0
- data/spec/cancan-rest-links/rails/configure_spec.rb +1 -1
- data/spec/cancan-rest-links/{link_helpers_spec.rb → rest_links_default_spec.rb} +26 -24
- data/spec/cancan-rest-links/rest_links_translate_spec.rb +144 -0
- data/spec/cancan-rest-links/translate_spec.rb +46 -0
- metadata +37 -12
data/Changelog.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Nov 26, 2010
|
2
|
+
---
|
3
|
+
* Removed dependency to Cream for labels
|
4
|
+
* Created class methods on CanCan::Links::Rest for handling labels, including translations
|
5
|
+
* Created a Generator to create a locale file for labels
|
6
|
+
* Created a spec to test the generator
|
7
|
+
* Created specs to test the REST link generation with and without label translations
|
data/README.markdown
CHANGED
@@ -2,24 +2,25 @@
|
|
2
2
|
|
3
3
|
REST link helpers for the [CanCan](http://github.com/ryanb/cancan) permission system.
|
4
4
|
|
5
|
-
|
5
|
+
## Update:Nov 26, 2010
|
6
6
|
|
7
|
-
|
8
|
-
label = auth_labels[:new]
|
9
|
-
...
|
10
|
-
</pre>
|
7
|
+
From changelog:
|
11
8
|
|
12
|
-
|
9
|
+
* Removed dependency to Cream for labels
|
10
|
+
* Created class methods on CanCan::Links::Rest for handling labels, including translations
|
11
|
+
* Created a Generator to create a locale file for labels
|
12
|
+
* Created a spec to test the generator
|
13
|
+
* Created specs to test the REST link generation with and without label translations
|
13
14
|
|
14
15
|
## Rails 3 usage
|
15
16
|
|
16
|
-
See the
|
17
|
+
See the demo app at [CanCan permits demo app](https://github.com/kristianmandrup/cancan-permits-demo)
|
17
18
|
|
18
|
-
|
19
|
-
require 'cancan-rest-links/rails/configure'
|
20
|
-
</code>
|
19
|
+
Configure your Rails 3 app for use with CanCan and some Authentication solution like Authlogic or Devise.
|
21
20
|
|
21
|
+
## Use with CanCan permits
|
22
22
|
|
23
|
+
[CanCan permits](https://github.com/kristianmandrup/cancan-permits) is a gem that lets you use Permits with CanCan to configure permissions.
|
23
24
|
|
24
25
|
## Note on Patches/Pull Requests
|
25
26
|
|
data/Rakefile
CHANGED
@@ -8,12 +8,13 @@ begin
|
|
8
8
|
gem.homepage = "http://github.com/kristianmandrup/cancan-rest-links"
|
9
9
|
gem.authors = ["Kristian Mandrup"]
|
10
10
|
gem.add_development_dependency "rspec", ">= 2.0.0"
|
11
|
-
gem.add_development_dependency "rspec-action_view", "
|
11
|
+
gem.add_development_dependency "rspec-action_view", ">= 0.3.4"
|
12
12
|
|
13
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.3.0"
|
16
|
-
gem.add_dependency 'r3_plugin_toolbox', ">= 0.4.0"
|
16
|
+
gem.add_dependency 'r3_plugin_toolbox', ">= 0.4.0"
|
17
|
+
gem.add_dependency 'generator-spec', ">= 0.7.0"
|
17
18
|
end
|
18
19
|
Jeweler::GemcutterTasks.new
|
19
20
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/cancan-rest-links.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cancan-rest-links}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
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-11-
|
12
|
+
s.date = %q{2010-11-26}
|
13
13
|
s.description = %q{Guard your links with permissions}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -20,20 +20,28 @@ Gem::Specification.new do |s|
|
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
22
|
".rspec",
|
23
|
+
"Changelog.txt",
|
23
24
|
"Gemfile",
|
25
|
+
"Ideas and Planning.txt",
|
24
26
|
"LICENSE",
|
25
27
|
"README.markdown",
|
26
28
|
"Rakefile",
|
27
29
|
"VERSION",
|
28
30
|
"cancan-rest-links.gemspec",
|
29
31
|
"lib/cancan-rest-links.rb",
|
30
|
-
"lib/cancan-rest-links/
|
32
|
+
"lib/cancan-rest-links/labels.rb",
|
31
33
|
"lib/cancan-rest-links/namespaces.rb",
|
32
34
|
"lib/cancan-rest-links/rails/configure.rb",
|
35
|
+
"lib/cancan-rest-links/rest_links.rb",
|
36
|
+
"lib/generators/cancan/restlinks/restlinks_generator.rb",
|
37
|
+
"lib/generators/cancan/restlinks/templates/en.yml",
|
33
38
|
"log/development.log",
|
34
|
-
"
|
35
|
-
"spec/cancan-rest-links/
|
39
|
+
"sandbox/link_with_cream_spec.rb",
|
40
|
+
"spec/cancan-rest-links/generators/restlinks_generator.rb",
|
36
41
|
"spec/cancan-rest-links/rails/configure_spec.rb",
|
42
|
+
"spec/cancan-rest-links/rest_links_default_spec.rb",
|
43
|
+
"spec/cancan-rest-links/rest_links_translate_spec.rb",
|
44
|
+
"spec/cancan-rest-links/translate_spec.rb",
|
37
45
|
"spec/spec_helper.rb"
|
38
46
|
]
|
39
47
|
s.homepage = %q{http://github.com/kristianmandrup/cancan-rest-links}
|
@@ -42,9 +50,11 @@ Gem::Specification.new do |s|
|
|
42
50
|
s.rubygems_version = %q{1.3.7}
|
43
51
|
s.summary = %q{Rest link helpers for CanCan}
|
44
52
|
s.test_files = [
|
45
|
-
"spec/cancan-rest-links/
|
46
|
-
"spec/cancan-rest-links/link_with_cream_spec.rb",
|
53
|
+
"spec/cancan-rest-links/generators/restlinks_generator.rb",
|
47
54
|
"spec/cancan-rest-links/rails/configure_spec.rb",
|
55
|
+
"spec/cancan-rest-links/rest_links_default_spec.rb",
|
56
|
+
"spec/cancan-rest-links/rest_links_translate_spec.rb",
|
57
|
+
"spec/cancan-rest-links/translate_spec.rb",
|
48
58
|
"spec/spec_helper.rb"
|
49
59
|
]
|
50
60
|
|
@@ -54,26 +64,29 @@ Gem::Specification.new do |s|
|
|
54
64
|
|
55
65
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
66
|
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
57
|
-
s.add_development_dependency(%q<rspec-action_view>, ["
|
67
|
+
s.add_development_dependency(%q<rspec-action_view>, [">= 0.3.4"])
|
58
68
|
s.add_runtime_dependency(%q<cancan>, ["~> 1.4.0"])
|
59
69
|
s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
|
60
70
|
s.add_runtime_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
61
71
|
s.add_runtime_dependency(%q<r3_plugin_toolbox>, [">= 0.4.0"])
|
72
|
+
s.add_runtime_dependency(%q<generator-spec>, [">= 0.7.0"])
|
62
73
|
else
|
63
74
|
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
64
|
-
s.add_dependency(%q<rspec-action_view>, ["
|
75
|
+
s.add_dependency(%q<rspec-action_view>, [">= 0.3.4"])
|
65
76
|
s.add_dependency(%q<cancan>, ["~> 1.4.0"])
|
66
77
|
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
67
78
|
s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
68
79
|
s.add_dependency(%q<r3_plugin_toolbox>, [">= 0.4.0"])
|
80
|
+
s.add_dependency(%q<generator-spec>, [">= 0.7.0"])
|
69
81
|
end
|
70
82
|
else
|
71
83
|
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
72
|
-
s.add_dependency(%q<rspec-action_view>, ["
|
84
|
+
s.add_dependency(%q<rspec-action_view>, [">= 0.3.4"])
|
73
85
|
s.add_dependency(%q<cancan>, ["~> 1.4.0"])
|
74
86
|
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
75
87
|
s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
76
88
|
s.add_dependency(%q<r3_plugin_toolbox>, [">= 0.4.0"])
|
89
|
+
s.add_dependency(%q<generator-spec>, [">= 0.7.0"])
|
77
90
|
end
|
78
91
|
end
|
79
92
|
|
data/lib/cancan-rest-links.rb
CHANGED
@@ -2,5 +2,5 @@ require 'require_all'
|
|
2
2
|
require 'sugar-high/module'
|
3
3
|
require 'sugar-high/alias'
|
4
4
|
require 'cancan-rest-links/namespaces'
|
5
|
-
|
6
|
-
|
5
|
+
require 'cancan-rest-links/rest_links'
|
6
|
+
require 'cancan-rest-links/rails/configure'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module CanCan::Links
|
2
|
+
module Rest
|
3
|
+
class << self
|
4
|
+
def labels
|
5
|
+
@lbs ||= translate_labels? ? translate_labels : default_labels
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor :translate
|
9
|
+
|
10
|
+
def translate_labels?
|
11
|
+
translate
|
12
|
+
end
|
13
|
+
|
14
|
+
def rest_labels
|
15
|
+
%w{index new edit delete show confirm}
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def default_labels
|
21
|
+
rest_labels.inject({}) {|result, action|
|
22
|
+
result[action.to_sym] = action.to_s.humanize
|
23
|
+
result
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def translate_labels
|
28
|
+
ns_actions = 'cream.actions'
|
29
|
+
tlabels =rest_labels.inject({}) {|result, action|
|
30
|
+
result[action.to_sym] = t("#{ns_actions}.#{action}").humanize
|
31
|
+
result
|
32
|
+
}
|
33
|
+
tlabels[:confirm] = t 'cream.confirm'
|
34
|
+
tlabels
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
|
+
require 'cancan-rest-links/labels'
|
2
|
+
|
1
3
|
module CanCan::Link
|
2
|
-
module Rest
|
4
|
+
module Rest
|
3
5
|
def index_link(object, label = nil)
|
4
6
|
label ||= index_label
|
5
7
|
obj = index_obj(object)
|
@@ -52,33 +54,18 @@ module CanCan::Link
|
|
52
54
|
|
53
55
|
protected
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
def edit_label
|
64
|
-
get_label :edit
|
65
|
-
end
|
66
|
-
|
67
|
-
def show_label
|
68
|
-
get_label :show
|
69
|
-
end
|
70
|
-
|
71
|
-
def delete_label
|
72
|
-
get_label :delete
|
73
|
-
end
|
74
|
-
|
75
|
-
def confirm_label
|
76
|
-
get_label :confirm
|
57
|
+
# create method :new_label, :index_label and so on ...
|
58
|
+
CanCan::Links::Rest.rest_labels.each do |name|
|
59
|
+
class_eval %{
|
60
|
+
def #{name}_label
|
61
|
+
get_label :#{name}
|
62
|
+
end
|
63
|
+
}
|
77
64
|
end
|
78
65
|
|
66
|
+
# how to retrieve label in single location!
|
79
67
|
def get_label key
|
80
|
-
|
81
|
-
auth_labels[key]
|
68
|
+
CanCan::Links::Rest.labels[key]
|
82
69
|
end
|
83
70
|
|
84
71
|
def index_obj(obj)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
require 'sugar-high/array'
|
3
|
+
require 'active_support/inflector'
|
4
|
+
require 'rails3_artifactor'
|
5
|
+
require 'logging_assist'
|
6
|
+
|
7
|
+
module Cancan
|
8
|
+
module Generators
|
9
|
+
class RestlinksGenerator < Rails::Generators::Base
|
10
|
+
desc "Configures Rails app for use with RestLinks"
|
11
|
+
|
12
|
+
source_root File.dirname(__FILE__) + '/templates'
|
13
|
+
|
14
|
+
def main_flow
|
15
|
+
copy_locale
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
include Rails3::Assist::BasicLogger
|
21
|
+
# extend Rails3::Assist::UseMacro
|
22
|
+
|
23
|
+
def copy_locale
|
24
|
+
template "en.yml", "config/locales/cream.en.yml"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generator-spec'
|
3
|
+
|
4
|
+
require_generator :cancan => :restlinks
|
5
|
+
|
6
|
+
RSpec::Generator.configure do |config|
|
7
|
+
config.debug = true
|
8
|
+
config.remove_temp_dir = true
|
9
|
+
config.default_rails_root(__FILE__)
|
10
|
+
config.lib = File.dirname(__FILE__) + '/../lib'
|
11
|
+
config.logger = :stdout # :file
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe 'Restlinks generator' do
|
16
|
+
use_helpers :controller, :special, :file
|
17
|
+
|
18
|
+
setup_generator :licenses do
|
19
|
+
tests Cancan::Generators::RestlinksGenerator
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Run it!" do
|
23
|
+
before :each do
|
24
|
+
@generator = with_generator do |g|
|
25
|
+
g.run_generator
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have created a locales file for CanCan REST links" do
|
30
|
+
# Rails3::Assist::Files.locale_files.file_names.should include('cream.en.yml')
|
31
|
+
@generator.should have_locale_file 'cream.en'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -14,16 +14,17 @@ describe CanCan::Link::Rest do
|
|
14
14
|
path = 'post/index'
|
15
15
|
post = Post.new
|
16
16
|
|
17
|
-
view.stubs(:auth_labels).returns(:index => label)
|
18
|
-
|
19
17
|
view.stubs(:posts_path).returns path
|
20
|
-
view.stubs(:can?).returns true
|
21
|
-
|
18
|
+
view.stubs(:can?).returns true
|
19
|
+
|
20
|
+
output_label = view.index_label
|
21
|
+
|
22
|
+
view.stubs(:link_to).with(label, path).returns output_label
|
22
23
|
|
23
24
|
res = e.run_template_locals :post => post, :name => label do
|
24
25
|
%{<%= index_link(post, name) %> }
|
25
|
-
end
|
26
|
-
res.should match /
|
26
|
+
end
|
27
|
+
res.should match /#{output_label}/
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
@@ -35,36 +36,38 @@ describe CanCan::Link::Rest do
|
|
35
36
|
path = 'post/create'
|
36
37
|
post = Post.new
|
37
38
|
|
38
|
-
view.stubs(:auth_labels).returns(:index => label)
|
39
|
-
|
40
39
|
view.stubs(:new_post_path).returns path
|
41
40
|
view.stubs(:can?).returns true
|
42
|
-
|
41
|
+
|
42
|
+
output_label = view.new_label
|
43
|
+
|
44
|
+
view.stubs(:link_to).with(label, path).returns output_label
|
43
45
|
|
44
46
|
res = e.run_template_locals :post => post, :name => label do
|
45
47
|
%{<%= create_link(post, name) %> }
|
46
48
|
end
|
47
|
-
res.should match /
|
49
|
+
res.should match /#{output_label}/
|
48
50
|
end
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
52
54
|
describe '#edit_link' do
|
53
|
-
it "should create
|
55
|
+
it "should create an edit link" do
|
54
56
|
view_engine do |e, view|
|
55
57
|
label = 'create'
|
56
58
|
path = 'post/create'
|
57
59
|
post = Post.new
|
58
60
|
|
59
|
-
view.stubs(:auth_labels).returns(:index => label)
|
60
|
-
|
61
61
|
view.stubs(:can?).returns true
|
62
|
-
|
62
|
+
|
63
|
+
output_label = view.edit_label
|
64
|
+
|
65
|
+
view.stubs(:link_to).with(label, [:edit, post]).returns output_label
|
63
66
|
|
64
67
|
res = e.run_template_locals :post => post, :name => label do
|
65
68
|
%{<%= edit_link(post, name) %> }
|
66
69
|
end
|
67
|
-
res.should match /
|
70
|
+
res.should match /#{output_label}/
|
68
71
|
end
|
69
72
|
end
|
70
73
|
end
|
@@ -75,16 +78,15 @@ describe CanCan::Link::Rest do
|
|
75
78
|
label = 'delete'
|
76
79
|
path = 'post/delete'
|
77
80
|
post = Post.new
|
78
|
-
|
79
|
-
view.stubs(:
|
80
|
-
|
81
|
-
view.stubs(:
|
82
|
-
view.stubs(:link_to).returns 'it works'
|
81
|
+
|
82
|
+
view.stubs(:can?).returns true
|
83
|
+
output_label = view.delete_label
|
84
|
+
view.stubs(:link_to).returns output_label
|
83
85
|
|
84
86
|
res = e.run_template_locals :post => post, :name => label do
|
85
87
|
%{<%= delete_link(post, name) %> }
|
86
88
|
end
|
87
|
-
res.should match /
|
89
|
+
res.should match /#{output_label}/
|
88
90
|
end
|
89
91
|
end
|
90
92
|
end
|
@@ -97,14 +99,14 @@ describe CanCan::Link::Rest do
|
|
97
99
|
path = 'post/show'
|
98
100
|
post = Post.new
|
99
101
|
|
100
|
-
view.stubs(:auth_labels).returns(:index => label)
|
101
102
|
view.stubs(:can?).returns true
|
102
|
-
view.
|
103
|
+
output_label = view.show_label
|
104
|
+
view.stubs(:link_to).with(label, post).returns output_label
|
103
105
|
|
104
106
|
res = e.run_template_locals :post => post, :name => label do
|
105
107
|
%{<%= show_link(post, name) %> }
|
106
108
|
end
|
107
|
-
res.should match /
|
109
|
+
res.should match /#{output_label}/
|
108
110
|
end
|
109
111
|
end
|
110
112
|
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# extend_view_with CanCan::Link::Rest
|
4
|
+
require 'cancan-rest-links/rails/configure'
|
5
|
+
|
6
|
+
class Post
|
7
|
+
end
|
8
|
+
|
9
|
+
CanCan::Links::Rest.translate = true
|
10
|
+
|
11
|
+
module CanCan::Links
|
12
|
+
module Rest
|
13
|
+
class << self
|
14
|
+
|
15
|
+
# Using Danish translations!
|
16
|
+
def translations
|
17
|
+
{:index => 'indeks', :new => 'ny', :edit => 'rediger', :delete => 'slet', :show => 'vis', :confirm => 'accepter'}
|
18
|
+
end
|
19
|
+
|
20
|
+
def translate_labels
|
21
|
+
rest_labels.inject({}) {|result, action|
|
22
|
+
result[action.to_sym] = translations[action.to_sym].humanize
|
23
|
+
result
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
describe CanCan::Link::Rest do
|
32
|
+
describe '#index_link' do
|
33
|
+
it "should create an index link" do
|
34
|
+
view_engine do |e, view|
|
35
|
+
label = 'index'
|
36
|
+
path = 'post/index'
|
37
|
+
post = Post.new
|
38
|
+
|
39
|
+
view.stubs(:posts_path).returns path
|
40
|
+
view.stubs(:can?).returns true
|
41
|
+
|
42
|
+
output_label = view.index_label
|
43
|
+
output_label.should == 'Indeks'
|
44
|
+
|
45
|
+
view.stubs(:link_to).with(label, path).returns output_label
|
46
|
+
|
47
|
+
res = e.run_template_locals :post => post, :name => label do
|
48
|
+
%{<%= index_link(post, name) %> }
|
49
|
+
end
|
50
|
+
|
51
|
+
res.should match /#{output_label}/
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#create_link' do
|
57
|
+
it "should create a create link" do
|
58
|
+
view_engine do |e, view|
|
59
|
+
label = 'create'
|
60
|
+
path = 'post/create'
|
61
|
+
post = Post.new
|
62
|
+
|
63
|
+
view.stubs(:new_post_path).returns path
|
64
|
+
view.stubs(:can?).returns true
|
65
|
+
|
66
|
+
output_label = view.new_label
|
67
|
+
output_label.should == 'Ny'
|
68
|
+
|
69
|
+
view.stubs(:link_to).with(label, path).returns output_label
|
70
|
+
|
71
|
+
res = e.run_template_locals :post => post, :name => label do
|
72
|
+
%{<%= create_link(post, name) %> }
|
73
|
+
end
|
74
|
+
res.should match /#{output_label}/
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#edit_link' do
|
80
|
+
it "should create an edit link" do
|
81
|
+
view_engine do |e, view|
|
82
|
+
label = 'create'
|
83
|
+
path = 'post/create'
|
84
|
+
post = Post.new
|
85
|
+
|
86
|
+
view.stubs(:can?).returns true
|
87
|
+
|
88
|
+
output_label = view.edit_label
|
89
|
+
output_label.should == 'Rediger'
|
90
|
+
|
91
|
+
view.stubs(:link_to).with(label, [:edit, post]).returns output_label
|
92
|
+
|
93
|
+
res = e.run_template_locals :post => post, :name => label do
|
94
|
+
%{<%= edit_link(post, name) %> }
|
95
|
+
end
|
96
|
+
res.should match /#{output_label}/
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#delete_link' do
|
102
|
+
it "should create a delete link" do
|
103
|
+
view_engine do |e, view|
|
104
|
+
label = 'delete'
|
105
|
+
path = 'post/delete'
|
106
|
+
post = Post.new
|
107
|
+
|
108
|
+
view.stubs(:can?).returns true
|
109
|
+
output_label = view.delete_label
|
110
|
+
output_label.should == 'Slet'
|
111
|
+
|
112
|
+
view.stubs(:link_to).returns output_label
|
113
|
+
|
114
|
+
res = e.run_template_locals :post => post, :name => label do
|
115
|
+
%{<%= delete_link(post, name) %> }
|
116
|
+
end
|
117
|
+
res.should match /#{output_label}/
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
describe '#show_link' do
|
124
|
+
it "should create a show link" do
|
125
|
+
view_engine do |e, view|
|
126
|
+
label = 'show'
|
127
|
+
path = 'post/show'
|
128
|
+
post = Post.new
|
129
|
+
|
130
|
+
view.stubs(:can?).returns true
|
131
|
+
output_label = view.show_label
|
132
|
+
output_label.should == 'Vis'
|
133
|
+
|
134
|
+
view.stubs(:link_to).with(label, post).returns output_label
|
135
|
+
|
136
|
+
res = e.run_template_locals :post => post, :name => label do
|
137
|
+
%{<%= show_link(post, name) %> }
|
138
|
+
end
|
139
|
+
res.should match /#{output_label}/
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# extend_view_with CanCan::Link::Rest
|
4
|
+
require 'cancan-rest-links/rails/configure'
|
5
|
+
|
6
|
+
class Post
|
7
|
+
end
|
8
|
+
|
9
|
+
module CanCan::Links
|
10
|
+
module Rest
|
11
|
+
class << self
|
12
|
+
def translations
|
13
|
+
{:index => 'indeks', :new => 'ny', :edit => 'rediger', :delete => 'slet', :show => 'vis', :confirm => 'accepter'}
|
14
|
+
end
|
15
|
+
|
16
|
+
def translate_labels
|
17
|
+
rest_labels.inject({}) {|result, action|
|
18
|
+
result[action.to_sym] = translations[action.to_sym].humanize
|
19
|
+
result
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe CanCan::Link::Rest do
|
27
|
+
describe '#index_link' do
|
28
|
+
it "should not allow translations to be switched on later" do
|
29
|
+
CanCan::Links::Rest.labels[:index].should == 'Index'
|
30
|
+
CanCan::Links::Rest.labels[:confirm].should == 'Confirm'
|
31
|
+
|
32
|
+
CanCan::Links::Rest.translate = true
|
33
|
+
CanCan::Links::Rest.translate_labels?.should be_true
|
34
|
+
CanCan::Links::Rest.labels[:index].should_not == 'Indeks'
|
35
|
+
CanCan::Links::Rest.labels[:confirm].should_not == 'Accepter'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should allow translation to be turned on initially" do
|
39
|
+
CanCan::Links::Rest.translate = true
|
40
|
+
CanCan::Links::Rest.translate_labels?.should be_true
|
41
|
+
CanCan::Links::Rest.labels[:index].should_not == 'Indeks'
|
42
|
+
CanCan::Links::Rest.labels[:confirm].should_not == 'Accepter'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
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-11-
|
17
|
+
date: 2010-11-26 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -38,13 +38,13 @@ dependencies:
|
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
segments:
|
44
44
|
- 0
|
45
45
|
- 3
|
46
|
-
-
|
47
|
-
version: 0.3.
|
46
|
+
- 4
|
47
|
+
version: 0.3.4
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id002
|
50
50
|
- !ruby/object:Gem::Dependency
|
@@ -107,6 +107,21 @@ dependencies:
|
|
107
107
|
version: 0.4.0
|
108
108
|
type: :runtime
|
109
109
|
version_requirements: *id006
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: generator-spec
|
112
|
+
prerelease: false
|
113
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
- 7
|
121
|
+
- 0
|
122
|
+
version: 0.7.0
|
123
|
+
type: :runtime
|
124
|
+
version_requirements: *id007
|
110
125
|
description: Guard your links with permissions
|
111
126
|
email: kmandrup@gmail.com
|
112
127
|
executables: []
|
@@ -120,20 +135,28 @@ files:
|
|
120
135
|
- .document
|
121
136
|
- .gitignore
|
122
137
|
- .rspec
|
138
|
+
- Changelog.txt
|
123
139
|
- Gemfile
|
140
|
+
- Ideas and Planning.txt
|
124
141
|
- LICENSE
|
125
142
|
- README.markdown
|
126
143
|
- Rakefile
|
127
144
|
- VERSION
|
128
145
|
- cancan-rest-links.gemspec
|
129
146
|
- lib/cancan-rest-links.rb
|
130
|
-
- lib/cancan-rest-links/
|
147
|
+
- lib/cancan-rest-links/labels.rb
|
131
148
|
- lib/cancan-rest-links/namespaces.rb
|
132
149
|
- lib/cancan-rest-links/rails/configure.rb
|
150
|
+
- lib/cancan-rest-links/rest_links.rb
|
151
|
+
- lib/generators/cancan/restlinks/restlinks_generator.rb
|
152
|
+
- lib/generators/cancan/restlinks/templates/en.yml
|
133
153
|
- log/development.log
|
134
|
-
-
|
135
|
-
- spec/cancan-rest-links/
|
154
|
+
- sandbox/link_with_cream_spec.rb
|
155
|
+
- spec/cancan-rest-links/generators/restlinks_generator.rb
|
136
156
|
- spec/cancan-rest-links/rails/configure_spec.rb
|
157
|
+
- spec/cancan-rest-links/rest_links_default_spec.rb
|
158
|
+
- spec/cancan-rest-links/rest_links_translate_spec.rb
|
159
|
+
- spec/cancan-rest-links/translate_spec.rb
|
137
160
|
- spec/spec_helper.rb
|
138
161
|
has_rdoc: true
|
139
162
|
homepage: http://github.com/kristianmandrup/cancan-rest-links
|
@@ -168,7 +191,9 @@ signing_key:
|
|
168
191
|
specification_version: 3
|
169
192
|
summary: Rest link helpers for CanCan
|
170
193
|
test_files:
|
171
|
-
- spec/cancan-rest-links/
|
172
|
-
- spec/cancan-rest-links/link_with_cream_spec.rb
|
194
|
+
- spec/cancan-rest-links/generators/restlinks_generator.rb
|
173
195
|
- spec/cancan-rest-links/rails/configure_spec.rb
|
196
|
+
- spec/cancan-rest-links/rest_links_default_spec.rb
|
197
|
+
- spec/cancan-rest-links/rest_links_translate_spec.rb
|
198
|
+
- spec/cancan-rest-links/translate_spec.rb
|
174
199
|
- spec/spec_helper.rb
|