easycrumbs 1.1.0 → 2.0.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/Gemfile +11 -0
- data/Gemfile.lock +98 -0
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/easycrumbs.gemspec +55 -31
- data/lib/easycrumbs/breadcrumb.rb +3 -3
- data/lib/easycrumbs/collection.rb +82 -40
- data/test/helper.rb +4 -3
- data/test/routes.rb +10 -7
- data/test/support/helpers/actors_helper.rb +0 -0
- data/test/support/helpers/application_helper.rb +0 -0
- data/test/support/helpers/countries_helper.rb +0 -0
- data/test/support/helpers/movies_helper.rb +0 -0
- data/test/support/stub_request.rb +4 -0
- data/test/test_easycrumbs.rb +51 -49
- metadata +101 -54
- data/.gitignore +0 -21
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: http://gemcutter.org/
|
|
3
|
+
remote: http://gems.github.com/
|
|
4
|
+
specs:
|
|
5
|
+
actionmailer (3.2.1)
|
|
6
|
+
actionpack (= 3.2.1)
|
|
7
|
+
mail (~> 2.4.0)
|
|
8
|
+
actionpack (3.2.1)
|
|
9
|
+
activemodel (= 3.2.1)
|
|
10
|
+
activesupport (= 3.2.1)
|
|
11
|
+
builder (~> 3.0.0)
|
|
12
|
+
erubis (~> 2.7.0)
|
|
13
|
+
journey (~> 1.0.1)
|
|
14
|
+
rack (~> 1.4.0)
|
|
15
|
+
rack-cache (~> 1.1)
|
|
16
|
+
rack-test (~> 0.6.1)
|
|
17
|
+
sprockets (~> 2.1.2)
|
|
18
|
+
activemodel (3.2.1)
|
|
19
|
+
activesupport (= 3.2.1)
|
|
20
|
+
builder (~> 3.0.0)
|
|
21
|
+
activerecord (3.2.1)
|
|
22
|
+
activemodel (= 3.2.1)
|
|
23
|
+
activesupport (= 3.2.1)
|
|
24
|
+
arel (~> 3.0.0)
|
|
25
|
+
tzinfo (~> 0.3.29)
|
|
26
|
+
activeresource (3.2.1)
|
|
27
|
+
activemodel (= 3.2.1)
|
|
28
|
+
activesupport (= 3.2.1)
|
|
29
|
+
activesupport (3.2.1)
|
|
30
|
+
i18n (~> 0.6)
|
|
31
|
+
multi_json (~> 1.0)
|
|
32
|
+
arel (3.0.2)
|
|
33
|
+
builder (3.0.0)
|
|
34
|
+
erubis (2.7.0)
|
|
35
|
+
git (1.2.5)
|
|
36
|
+
hike (1.2.1)
|
|
37
|
+
i18n (0.6.0)
|
|
38
|
+
jeweler (1.5.2)
|
|
39
|
+
bundler (~> 1.0.0)
|
|
40
|
+
git (>= 1.2.5)
|
|
41
|
+
rake
|
|
42
|
+
journey (1.0.3)
|
|
43
|
+
json (1.6.5)
|
|
44
|
+
mail (2.4.1)
|
|
45
|
+
i18n (>= 0.4.0)
|
|
46
|
+
mime-types (~> 1.16)
|
|
47
|
+
treetop (~> 1.4.8)
|
|
48
|
+
mime-types (1.17.2)
|
|
49
|
+
mocha (0.9.12)
|
|
50
|
+
multi_json (1.1.0)
|
|
51
|
+
polyglot (0.3.3)
|
|
52
|
+
rack (1.4.1)
|
|
53
|
+
rack-cache (1.1)
|
|
54
|
+
rack (>= 0.4)
|
|
55
|
+
rack-ssl (1.3.2)
|
|
56
|
+
rack
|
|
57
|
+
rack-test (0.6.1)
|
|
58
|
+
rack (>= 1.0)
|
|
59
|
+
rails (3.2.1)
|
|
60
|
+
actionmailer (= 3.2.1)
|
|
61
|
+
actionpack (= 3.2.1)
|
|
62
|
+
activerecord (= 3.2.1)
|
|
63
|
+
activeresource (= 3.2.1)
|
|
64
|
+
activesupport (= 3.2.1)
|
|
65
|
+
bundler (~> 1.0)
|
|
66
|
+
railties (= 3.2.1)
|
|
67
|
+
railties (3.2.1)
|
|
68
|
+
actionpack (= 3.2.1)
|
|
69
|
+
activesupport (= 3.2.1)
|
|
70
|
+
rack-ssl (~> 1.3.2)
|
|
71
|
+
rake (>= 0.8.7)
|
|
72
|
+
rdoc (~> 3.4)
|
|
73
|
+
thor (~> 0.14.6)
|
|
74
|
+
rake (0.9.2.2)
|
|
75
|
+
rdoc (3.12)
|
|
76
|
+
json (~> 1.4)
|
|
77
|
+
shoulda (2.11.3)
|
|
78
|
+
sprockets (2.1.2)
|
|
79
|
+
hike (~> 1.2)
|
|
80
|
+
rack (~> 1.0)
|
|
81
|
+
tilt (~> 1.1, != 1.3.0)
|
|
82
|
+
sqlite3 (1.3.5)
|
|
83
|
+
thor (0.14.6)
|
|
84
|
+
tilt (1.3.3)
|
|
85
|
+
treetop (1.4.10)
|
|
86
|
+
polyglot
|
|
87
|
+
polyglot (>= 0.3.1)
|
|
88
|
+
tzinfo (0.3.31)
|
|
89
|
+
|
|
90
|
+
PLATFORMS
|
|
91
|
+
ruby
|
|
92
|
+
|
|
93
|
+
DEPENDENCIES
|
|
94
|
+
jeweler (= 1.5.2)
|
|
95
|
+
mocha (= 0.9.12)
|
|
96
|
+
rails (~> 3.2.0)
|
|
97
|
+
shoulda (= 2.11.3)
|
|
98
|
+
sqlite3
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
2.0.0
|
data/easycrumbs.gemspec
CHANGED
|
@@ -1,61 +1,85 @@
|
|
|
1
1
|
# Generated by jeweler
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
|
-
s.name =
|
|
8
|
-
s.version = "
|
|
7
|
+
s.name = "easycrumbs"
|
|
8
|
+
s.version = "2.0.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
-
s.authors = ["Stanis\
|
|
12
|
-
s.date =
|
|
13
|
-
s.description =
|
|
14
|
-
s.email =
|
|
11
|
+
s.authors = ["Stanis\u{142}aw Kolarzowski"]
|
|
12
|
+
s.date = "2012-04-23"
|
|
13
|
+
s.description = "Easy breadcrumbs for your website"
|
|
14
|
+
s.email = "stanislaw.kolarzowski@gmail.com"
|
|
15
15
|
s.extra_rdoc_files = [
|
|
16
16
|
"LICENSE",
|
|
17
|
-
|
|
17
|
+
"README.rdoc"
|
|
18
18
|
]
|
|
19
19
|
s.files = [
|
|
20
20
|
".document",
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
"Gemfile",
|
|
22
|
+
"Gemfile.lock",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"README.rdoc",
|
|
25
|
+
"Rakefile",
|
|
26
|
+
"VERSION",
|
|
27
|
+
"easycrumbs.gemspec",
|
|
28
|
+
"lib/easycrumbs.rb",
|
|
29
|
+
"lib/easycrumbs/breadcrumb.rb",
|
|
30
|
+
"lib/easycrumbs/collection.rb",
|
|
31
|
+
"lib/easycrumbs/errors.rb",
|
|
32
|
+
"lib/easycrumbs/view_helpers.rb",
|
|
33
|
+
"test/helper.rb",
|
|
34
|
+
"test/routes.rb",
|
|
35
|
+
"test/support/helpers/actors_helper.rb",
|
|
36
|
+
"test/support/helpers/application_helper.rb",
|
|
37
|
+
"test/support/helpers/countries_helper.rb",
|
|
38
|
+
"test/support/helpers/movies_helper.rb",
|
|
39
|
+
"test/support/stub_request.rb",
|
|
40
|
+
"test/test_custom_collection.rb",
|
|
41
|
+
"test/test_easycrumbs.rb"
|
|
36
42
|
]
|
|
37
|
-
s.homepage =
|
|
38
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
|
43
|
+
s.homepage = "http://github.com/staszek/easycrumbs"
|
|
39
44
|
s.require_paths = ["lib"]
|
|
40
|
-
s.rubygems_version =
|
|
41
|
-
s.summary =
|
|
45
|
+
s.rubygems_version = "1.8.10"
|
|
46
|
+
s.summary = "Easy breadcrumbs"
|
|
42
47
|
s.test_files = [
|
|
43
48
|
"test/helper.rb",
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
"test/routes.rb",
|
|
50
|
+
"test/support/helpers/actors_helper.rb",
|
|
51
|
+
"test/support/helpers/application_helper.rb",
|
|
52
|
+
"test/support/helpers/countries_helper.rb",
|
|
53
|
+
"test/support/helpers/movies_helper.rb",
|
|
54
|
+
"test/support/stub_request.rb",
|
|
55
|
+
"test/test_custom_collection.rb",
|
|
56
|
+
"test/test_easycrumbs.rb"
|
|
47
57
|
]
|
|
48
58
|
|
|
49
59
|
if s.respond_to? :specification_version then
|
|
50
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
51
60
|
s.specification_version = 3
|
|
52
61
|
|
|
53
62
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
63
|
+
s.add_runtime_dependency(%q<rails>, ["~> 3.2.0"])
|
|
64
|
+
s.add_development_dependency(%q<mocha>, ["= 0.9.12"])
|
|
65
|
+
s.add_development_dependency(%q<shoulda>, ["= 2.11.3"])
|
|
66
|
+
s.add_development_dependency(%q<jeweler>, ["= 1.5.2"])
|
|
67
|
+
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
|
54
68
|
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
|
55
69
|
else
|
|
70
|
+
s.add_dependency(%q<rails>, ["~> 3.2.0"])
|
|
71
|
+
s.add_dependency(%q<mocha>, ["= 0.9.12"])
|
|
72
|
+
s.add_dependency(%q<shoulda>, ["= 2.11.3"])
|
|
73
|
+
s.add_dependency(%q<jeweler>, ["= 1.5.2"])
|
|
74
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
|
56
75
|
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
|
57
76
|
end
|
|
58
77
|
else
|
|
78
|
+
s.add_dependency(%q<rails>, ["~> 3.2.0"])
|
|
79
|
+
s.add_dependency(%q<mocha>, ["= 0.9.12"])
|
|
80
|
+
s.add_dependency(%q<shoulda>, ["= 2.11.3"])
|
|
81
|
+
s.add_dependency(%q<jeweler>, ["= 1.5.2"])
|
|
82
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
|
59
83
|
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
|
60
84
|
end
|
|
61
85
|
end
|
|
@@ -88,15 +88,15 @@ module EasyCrumbs
|
|
|
88
88
|
i18n == true ? I18n.t("breadcrumbs.actions.#{action}", :name => name) : "#{action.titlecase} #{name}"
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
-
# Set path using hash from
|
|
91
|
+
# Set path using hash from Rails.application.routes.recognize_path
|
|
92
92
|
# Example looks like:
|
|
93
93
|
# {:country_id => "1", :movie_id => "1", :id => "1", :action => "show", :controller => "movies"}
|
|
94
94
|
def set_path(path, blank_links)
|
|
95
|
-
path.nil? || path.empty? ? "/" :
|
|
95
|
+
path.nil? || path.empty? ? "/" : Rails.application.routes.generate_extras(path).first
|
|
96
96
|
rescue ActionController::RoutingError => e
|
|
97
97
|
raise EasyCrumbs::NoPath.new(e.message) unless blank_links == true
|
|
98
98
|
nil
|
|
99
99
|
end
|
|
100
100
|
|
|
101
101
|
end
|
|
102
|
-
end
|
|
102
|
+
end
|
|
@@ -16,10 +16,8 @@ module EasyCrumbs
|
|
|
16
16
|
|
|
17
17
|
# Finding route with given path and method
|
|
18
18
|
# Return ActionController:Routing::Route object
|
|
19
|
-
def find_route
|
|
20
|
-
routes =
|
|
21
|
-
route.recognize(request_path, :method => request_method) != nil
|
|
22
|
-
end
|
|
19
|
+
def find_route(request = @request)
|
|
20
|
+
routes = Rails.application.routes.router.send(:find_routes, request.env)
|
|
23
21
|
raise EasyCrumbs::NotRecognized if routes.empty?
|
|
24
22
|
routes.first
|
|
25
23
|
end
|
|
@@ -28,40 +26,72 @@ module EasyCrumbs
|
|
|
28
26
|
# for example:
|
|
29
27
|
# { :controller => 'movies', :action => 'show', :country_id => '23', :id => '12' }
|
|
30
28
|
def find_path
|
|
31
|
-
|
|
29
|
+
#@route.recognize(request_path, :method => request_method)
|
|
30
|
+
@route.second
|
|
32
31
|
end
|
|
33
32
|
|
|
34
33
|
# Select only static and dynamic segments from route. Static segments points at controllers and dynamic points at models.
|
|
35
34
|
# It is given in right order
|
|
36
35
|
# If last segment is equal to member action then it should be deleted. for example movies/123/edit should not return "edit" segment
|
|
37
36
|
def segments
|
|
38
|
-
segments = @route.segments.select do |segment|
|
|
39
|
-
|
|
37
|
+
#segments = @route.segments.select do |segment|
|
|
38
|
+
# [ActionController::Routing::DynamicSegment, ActionController::Routing::StaticSegment].include? segment.class
|
|
39
|
+
#end
|
|
40
|
+
#segments.pop if segments.last.is_a?(ActionController::Routing::StaticSegment) && segments.last.value == @action && segments.last.value != 'new'
|
|
41
|
+
#segments
|
|
42
|
+
resolve_segments
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Return array of dynamic segments
|
|
46
|
+
# for example
|
|
47
|
+
# [ :country_id, :dynamic], [:movie_id, :dynamic], [:id, :dynamic] ]
|
|
48
|
+
def dynamic_segments
|
|
49
|
+
@route.third.path.names.map do |segment|
|
|
50
|
+
[segment.to_sym, :dynamic]
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Return array of all segments with :static and :dynamic annotation
|
|
55
|
+
# for examle:
|
|
56
|
+
# [[:countries, :static], [:country_id, :dynamic], [:movies, :static], [:movie_id, :dynamic], [:actors, :static] ]
|
|
57
|
+
def resolve_segments
|
|
58
|
+
@route.third.path.spec.to_s.split(/[\/(\)\.]/).map do |segment|
|
|
59
|
+
[segment.delete(":").to_sym, :static] unless segment.blank?
|
|
60
|
+
end.compact.map do |segment|
|
|
61
|
+
if dynamic_segments.map(&:first).include? segment.first
|
|
62
|
+
[segment.first, :dynamic]
|
|
63
|
+
else
|
|
64
|
+
segment
|
|
65
|
+
end
|
|
40
66
|
end
|
|
41
|
-
segments.pop if segments.last.is_a?(ActionController::Routing::StaticSegment) && segments.last.value == @action && segments.last.value != 'new'
|
|
42
|
-
segments
|
|
43
67
|
end
|
|
44
68
|
|
|
45
69
|
# Returning controller object from static segment
|
|
46
70
|
def pick_controller(segment)
|
|
47
|
-
segment = last_controller_segment if segment.value == "new"
|
|
48
|
-
"#{segment.value.titlecase}Controller".constantize.new
|
|
71
|
+
#segment = last_controller_segment if segment.value == "new"
|
|
72
|
+
#"#{segment.value.titlecase}Controller".constantize.new
|
|
73
|
+
segment = last_controller_segment if segment.first == :new
|
|
74
|
+
"#{segment.first.to_s.titlecase}Controller".constantize.new rescue nil
|
|
49
75
|
end
|
|
50
76
|
|
|
51
77
|
# Returns last controller segment in segments
|
|
52
78
|
def last_controller_segment
|
|
53
|
-
segments.select{ |seg| seg.is_a?(ActionController::Routing::StaticSegment) && seg.value != "new"}.last
|
|
79
|
+
#segments.select{ |seg| seg.is_a?(ActionController::Routing::StaticSegment) && seg.value != "new"}.last
|
|
80
|
+
segments.select{ |seg| seg.second == :static && seg.first != :new }.last
|
|
54
81
|
end
|
|
55
82
|
|
|
56
83
|
# Retrung model object from dynamic segment
|
|
57
84
|
# If key has not model name then it is taken from current controller(it is taken from path)
|
|
58
85
|
def pick_model(segment)
|
|
59
|
-
key = segment.
|
|
86
|
+
key = segment.first
|
|
60
87
|
if key == :id
|
|
61
88
|
model = @controller.singularize
|
|
62
|
-
|
|
89
|
+
elsif key.to_s.include?("_id")
|
|
63
90
|
model = key.to_s[0..-4] # model_id without last 3 signs = model
|
|
91
|
+
else
|
|
92
|
+
return nil
|
|
64
93
|
end
|
|
94
|
+
|
|
65
95
|
model = model.titlecase.constantize
|
|
66
96
|
model.find(@path[key])
|
|
67
97
|
end
|
|
@@ -71,12 +101,12 @@ module EasyCrumbs
|
|
|
71
101
|
# [#<CountriesController:0x001>, #<Country:0x001 @name="usa">, #<MoviesController:0x001>, #<Movie:0x001 @name="titanic">]
|
|
72
102
|
def objects
|
|
73
103
|
segments.map do |segment|
|
|
74
|
-
if segment.
|
|
104
|
+
if segment.second == :dynamic
|
|
75
105
|
pick_model(segment)
|
|
76
106
|
else
|
|
77
107
|
pick_controller(segment)
|
|
78
108
|
end
|
|
79
|
-
end
|
|
109
|
+
end.compact
|
|
80
110
|
end
|
|
81
111
|
|
|
82
112
|
# Return array of breadcrumbs object in right order
|
|
@@ -92,23 +122,23 @@ module EasyCrumbs
|
|
|
92
122
|
|
|
93
123
|
# Retrurn parameters for path of model
|
|
94
124
|
# If it is last object then action is equal to request action
|
|
95
|
-
def path_for_model(segment)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
end
|
|
125
|
+
#def path_for_model(segment)
|
|
126
|
+
# key = segment.value
|
|
127
|
+
# if key == :id
|
|
128
|
+
# {:action => @action, :id => @path[key]}
|
|
129
|
+
# else
|
|
130
|
+
# {:action => 'show', key => @path[key]}
|
|
131
|
+
# end
|
|
132
|
+
#end
|
|
103
133
|
|
|
104
134
|
# Retrun parameters for path of controller
|
|
105
|
-
def path_for_controller(segment)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
end
|
|
135
|
+
#def path_for_controller(segment)
|
|
136
|
+
# if segment.value == "new"
|
|
137
|
+
# {:action => "new", :controller => last_controller_segment.value}
|
|
138
|
+
# else
|
|
139
|
+
# {:action => 'index', :controller => segment.value}
|
|
140
|
+
# end
|
|
141
|
+
#end
|
|
112
142
|
|
|
113
143
|
# If controller name is connected with object then parameter should be :id instead of :object_id
|
|
114
144
|
# {:controller => 'movies', :movie_id => 1} will be {:controller => 'movies', :id => 1}
|
|
@@ -130,16 +160,28 @@ module EasyCrumbs
|
|
|
130
160
|
# {:action => 'index', :controller => 'actors', :country_id => 1, :movie_id => 2},
|
|
131
161
|
# {:action => 'update', :controller => 'actors', :country_id => 1, :movie_id => 2, :id => 3}
|
|
132
162
|
def make_pathes
|
|
133
|
-
path = {}
|
|
134
|
-
segments.map do |segment|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
163
|
+
#path = {}
|
|
164
|
+
#segments.map do |segment|
|
|
165
|
+
# if segment.is_a? ActionController::Routing::DynamicSegment
|
|
166
|
+
# path.merge! path_for_model(segment)
|
|
167
|
+
# result = repaired_model_path(path)
|
|
168
|
+
# else
|
|
169
|
+
# result = path.merge! path_for_controller(segment)
|
|
170
|
+
# end
|
|
171
|
+
# result.dup
|
|
172
|
+
#end
|
|
173
|
+
result = []
|
|
174
|
+
@route.first.to_s.split("/")[1...-1].inject([]) do |current_path, segment|
|
|
175
|
+
current_path << segment
|
|
176
|
+
request = ActionDispatch::Request.new("PATH_INFO" => "/#{current_path.join("/")}",
|
|
177
|
+
"REQUEST_METHOD" => "GET")
|
|
178
|
+
|
|
179
|
+
result << (find_route(request).second rescue nil)
|
|
180
|
+
|
|
181
|
+
current_path
|
|
142
182
|
end
|
|
183
|
+
|
|
184
|
+
(result << @route.second).compact
|
|
143
185
|
end
|
|
144
186
|
|
|
145
187
|
def render(options = {})
|
data/test/helper.rb
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
1
|
require 'test/unit'
|
|
3
2
|
require 'shoulda'
|
|
4
3
|
require "mocha"
|
|
5
|
-
require
|
|
6
|
-
require "
|
|
4
|
+
require "rails"
|
|
5
|
+
require "active_record"
|
|
7
6
|
require "action_controller"
|
|
8
7
|
require "routes"
|
|
9
8
|
|
|
10
9
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
10
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'support', 'helpers'))
|
|
11
11
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
12
|
+
require 'support/stub_request'
|
|
12
13
|
require 'easycrumbs'
|
|
13
14
|
|
|
14
15
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
data/test/routes.rb
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
module EasyCrumbs
|
|
2
|
+
class Application < ::Rails::Application
|
|
3
|
+
end
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
EasyCrumbs::Application.routes.draw do
|
|
7
|
+
resources :countries do
|
|
8
|
+
resources :movies do
|
|
9
|
+
resources :actors
|
|
6
10
|
end
|
|
7
11
|
end
|
|
8
|
-
|
|
9
|
-
end
|
|
12
|
+
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/test/test_easycrumbs.rb
CHANGED
|
@@ -132,17 +132,17 @@ class TestEasycrumbs < Test::Unit::TestCase
|
|
|
132
132
|
context "Collection" do
|
|
133
133
|
setup do
|
|
134
134
|
Collection.any_instance.stubs(:request_path => "/countries/#{@usa.id}/movies/#{@titanic.id}/actors/#{@leo.id}", :request_method => :put)
|
|
135
|
-
@collection = Collection.new("
|
|
135
|
+
@collection = Collection.new(stub_request("/countries/#{@usa.id}/movies/#{@titanic.id}/actors/#{@leo.id}", :put))
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
context "finding route" do
|
|
139
139
|
should "return route if it can find it" do
|
|
140
|
-
assert_equal(
|
|
140
|
+
assert_equal(Journey::Route, @collection.route.third.class)
|
|
141
141
|
end
|
|
142
142
|
|
|
143
143
|
should "raise error when it can not find route" do
|
|
144
144
|
assert_raise(EasyCrumbs::NotRecognized) do
|
|
145
|
-
@collection.
|
|
145
|
+
@collection = Collection.new(stub_request("/countres/1/videos/"))
|
|
146
146
|
@collection.find_route
|
|
147
147
|
end
|
|
148
148
|
end
|
|
@@ -157,61 +157,63 @@ class TestEasycrumbs < Test::Unit::TestCase
|
|
|
157
157
|
context "selecting right segments" do
|
|
158
158
|
should "select only static and dynamic segments" do
|
|
159
159
|
results = @collection.segments
|
|
160
|
-
results = results.map(&:
|
|
161
|
-
results.delete(
|
|
162
|
-
results.delete(
|
|
160
|
+
results = results.map(&:second).uniq
|
|
161
|
+
results.delete(:static)
|
|
162
|
+
results.delete(:dynamic)
|
|
163
163
|
assert_equal(true, results.empty?)
|
|
164
164
|
end
|
|
165
165
|
|
|
166
166
|
should "return proper segments for member action" do
|
|
167
|
-
Collection.any_instance.stubs(:request_path => "/countries/#{@usa.id}/movies/#{@titanic.id}/actors/#{@leo.id}/edit", :request_method => :get)
|
|
168
|
-
collection = Collection.new("
|
|
169
|
-
assert_equal(
|
|
167
|
+
#Collection.any_instance.stubs(:request_path => "/countries/#{@usa.id}/movies/#{@titanic.id}/actors/#{@leo.id}/edit", :request_method => :get)
|
|
168
|
+
collection = Collection.new(stub_request("/countries/#{@usa.id}/movies/#{@titanic.id}/actors/#{@leo.id}/edit", :get))
|
|
169
|
+
assert_equal(8, collection.segments.size)
|
|
170
170
|
end
|
|
171
171
|
|
|
172
172
|
should "return proper segments for new action" do
|
|
173
|
-
Collection.any_instance.stubs(:request_path => "/countries/#{@usa.id}/movies/#{@titanic.id}/actors/new", :request_method => :get)
|
|
174
|
-
collection = Collection.new("
|
|
175
|
-
assert_equal(
|
|
173
|
+
#Collection.any_instance.stubs(:request_path => "/countries/#{@usa.id}/movies/#{@titanic.id}/actors/new", :request_method => :get)
|
|
174
|
+
collection = Collection.new(stub_request("/countries/#{@usa.id}/movies/#{@titanic.id}/actors/new", :get))
|
|
175
|
+
assert_equal(7, collection.segments.size)
|
|
176
176
|
end
|
|
177
177
|
end
|
|
178
178
|
|
|
179
179
|
context "pick_controller" do
|
|
180
180
|
should "return controller object" do
|
|
181
|
-
assert_equal(MoviesController, @collection.pick_controller(
|
|
181
|
+
assert_equal(MoviesController, @collection.pick_controller([:movies, :static]).class)
|
|
182
182
|
end
|
|
183
183
|
|
|
184
184
|
should "return controller object if action is new" do
|
|
185
|
-
assert_equal(ActorsController, @collection.pick_controller(
|
|
185
|
+
assert_equal(ActorsController, @collection.pick_controller([:new, :static]).class)
|
|
186
186
|
end
|
|
187
187
|
end
|
|
188
188
|
|
|
189
189
|
context "last controller" do
|
|
190
190
|
should "return last controller object if last segment is dynamic" do
|
|
191
|
-
assert_equal(
|
|
191
|
+
assert_equal(:actors, @collection.last_controller_segment.first)
|
|
192
192
|
end
|
|
193
193
|
|
|
194
194
|
should "return last controller object if last segment is static" do
|
|
195
|
-
Collection.any_instance.stubs(:request_path => "/countries/#{@usa.id}/movies/#{@titanic.id}/actors", :request_method => :get)
|
|
196
|
-
collection = Collection.new("
|
|
197
|
-
assert_equal(
|
|
195
|
+
#Collection.any_instance.stubs(:request_path => "/countries/#{@usa.id}/movies/#{@titanic.id}/actors", :request_method => :get)
|
|
196
|
+
collection = Collection.new(stub_request("/countries/#{@usa.id}/movies/#{@titanic.id}/actors", :get))
|
|
197
|
+
assert_equal(:actors, collection.last_controller_segment.first)
|
|
198
198
|
end
|
|
199
199
|
|
|
200
200
|
should "return last controller object if last segment is new action" do
|
|
201
|
-
Collection.any_instance.stubs(:request_path => "/countries/#{@usa.id}/movies/#{@titanic.id}/actors/new", :request_method => :get)
|
|
202
|
-
collection = Collection.new("
|
|
203
|
-
assert_equal(
|
|
201
|
+
#Collection.any_instance.stubs(:request_path => "/countries/#{@usa.id}/movies/#{@titanic.id}/actors/new", :request_method => :get)
|
|
202
|
+
collection = Collection.new(stub_request("/countries/#{@usa.id}/movies/#{@titanic.id}/actors/new", :get))
|
|
203
|
+
assert_equal(:actors, collection.last_controller_segment.first)
|
|
204
204
|
end
|
|
205
205
|
end
|
|
206
206
|
|
|
207
207
|
context "pick_model" do
|
|
208
208
|
should "return model object when key has model name" do
|
|
209
|
-
segment = ActionController::Routing::DynamicSegment.new(:movie_id)
|
|
209
|
+
#segment = ActionController::Routing::DynamicSegment.new(:movie_id)
|
|
210
|
+
segment = [:movie_id, :dynamic]
|
|
210
211
|
assert_equal(@titanic, @collection.pick_model(segment))
|
|
211
212
|
end
|
|
212
213
|
|
|
213
214
|
should "return model object when key has not model name"do
|
|
214
|
-
segment = ActionController::Routing::DynamicSegment.new(:id)
|
|
215
|
+
#segment = ActionController::Routing::DynamicSegment.new(:id)
|
|
216
|
+
segment = [:id, :dynamic]
|
|
215
217
|
assert_equal(@leo, @collection.pick_model(segment))
|
|
216
218
|
end
|
|
217
219
|
end
|
|
@@ -222,29 +224,29 @@ class TestEasycrumbs < Test::Unit::TestCase
|
|
|
222
224
|
end
|
|
223
225
|
end
|
|
224
226
|
|
|
225
|
-
context "path_for_model" do
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
context "path_for_controller" do
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
end
|
|
227
|
+
#context "path_for_model" do
|
|
228
|
+
# should "return id and current action for last object" do
|
|
229
|
+
# segment = ActionController::Routing::DynamicSegment.new(:id)
|
|
230
|
+
# assert_equal({:action => 'update', :id => @leo.id.to_s}, @collection.path_for_model(segment))
|
|
231
|
+
# end
|
|
232
|
+
#
|
|
233
|
+
# should "return show action and object id for not last object" do
|
|
234
|
+
# segment = ActionController::Routing::DynamicSegment.new(:movie_id)
|
|
235
|
+
# assert_equal({:action => 'show', :movie_id => @titanic.id.to_s}, @collection.path_for_model(segment))
|
|
236
|
+
# end
|
|
237
|
+
#end
|
|
238
|
+
|
|
239
|
+
#context "path_for_controller" do
|
|
240
|
+
# should "return index action and controller name" do
|
|
241
|
+
# segment = ActionController::Routing::StaticSegment.new("movies")
|
|
242
|
+
# assert_equal({:action => 'index', :controller => 'movies'}, @collection.path_for_controller(segment))
|
|
243
|
+
# end
|
|
244
|
+
#
|
|
245
|
+
# should "return new action and controller name for new action segment" do
|
|
246
|
+
# segment = ActionController::Routing::StaticSegment.new("new")
|
|
247
|
+
# assert_equal({:action => 'new', :controller => 'actors'}, @collection.path_for_controller(segment))
|
|
248
|
+
# end
|
|
249
|
+
#end
|
|
248
250
|
|
|
249
251
|
context "repaired_model_path" do
|
|
250
252
|
should "return repaired path if model is connected with controller" do
|
|
@@ -271,8 +273,8 @@ class TestEasycrumbs < Test::Unit::TestCase
|
|
|
271
273
|
end
|
|
272
274
|
|
|
273
275
|
should "return patches array for objects for new action" do
|
|
274
|
-
Collection.any_instance.stubs(:request_path => "/countries/#{@usa.id}/movies/#{@titanic.id}/actors/new", :request_method => :get)
|
|
275
|
-
collection = Collection.new("
|
|
276
|
+
#Collection.any_instance.stubs(:request_path => "/countries/#{@usa.id}/movies/#{@titanic.id}/actors/new", :request_method => :get)
|
|
277
|
+
collection = Collection.new(stub_request("/countries/#{@usa.id}/movies/#{@titanic.id}/actors/new", :get))
|
|
276
278
|
assert_equal([
|
|
277
279
|
{:action => 'index', :controller => 'countries'},
|
|
278
280
|
{:action => 'show', :controller => 'countries', :id => @usa.id.to_s},
|
|
@@ -291,7 +293,7 @@ class TestEasycrumbs < Test::Unit::TestCase
|
|
|
291
293
|
|
|
292
294
|
should "return array of breadcrumbs objects" do
|
|
293
295
|
assert_equal(@collection.objects.size + 1, @results.size)
|
|
294
|
-
@results.
|
|
296
|
+
@results.uniq == [EasyCrumbs::Breadcrumb]
|
|
295
297
|
end
|
|
296
298
|
|
|
297
299
|
should "last breadcrumb have name with action prefix" do
|
metadata
CHANGED
|
@@ -1,49 +1,93 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: easycrumbs
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
5
|
-
prerelease:
|
|
6
|
-
segments:
|
|
7
|
-
- 1
|
|
8
|
-
- 1
|
|
9
|
-
- 0
|
|
10
|
-
version: 1.1.0
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.0.0
|
|
5
|
+
prerelease:
|
|
11
6
|
platform: ruby
|
|
12
|
-
authors:
|
|
13
|
-
-
|
|
7
|
+
authors:
|
|
8
|
+
- Stanisław Kolarzowski
|
|
14
9
|
autorequire:
|
|
15
10
|
bindir: bin
|
|
16
11
|
cert_chain: []
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
date: 2012-04-23 00:00:00.000000000Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rails
|
|
16
|
+
requirement: &2174258960 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 3.2.0
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *2174258960
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: mocha
|
|
27
|
+
requirement: &2174258320 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - =
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 0.9.12
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *2174258320
|
|
36
|
+
- !ruby/object:Gem::Dependency
|
|
37
|
+
name: shoulda
|
|
38
|
+
requirement: &2174257540 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - =
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: 2.11.3
|
|
44
|
+
type: :development
|
|
23
45
|
prerelease: false
|
|
24
|
-
|
|
46
|
+
version_requirements: *2174257540
|
|
47
|
+
- !ruby/object:Gem::Dependency
|
|
48
|
+
name: jeweler
|
|
49
|
+
requirement: &2174256760 !ruby/object:Gem::Requirement
|
|
25
50
|
none: false
|
|
26
|
-
requirements:
|
|
27
|
-
- -
|
|
28
|
-
- !ruby/object:Gem::Version
|
|
29
|
-
|
|
30
|
-
segments:
|
|
31
|
-
- 0
|
|
32
|
-
version: "0"
|
|
51
|
+
requirements:
|
|
52
|
+
- - =
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 1.5.2
|
|
33
55
|
type: :development
|
|
34
|
-
|
|
56
|
+
prerelease: false
|
|
57
|
+
version_requirements: *2174256760
|
|
58
|
+
- !ruby/object:Gem::Dependency
|
|
59
|
+
name: sqlite3
|
|
60
|
+
requirement: &2174256060 !ruby/object:Gem::Requirement
|
|
61
|
+
none: false
|
|
62
|
+
requirements:
|
|
63
|
+
- - ! '>='
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: '0'
|
|
66
|
+
type: :development
|
|
67
|
+
prerelease: false
|
|
68
|
+
version_requirements: *2174256060
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: thoughtbot-shoulda
|
|
71
|
+
requirement: &2174255340 !ruby/object:Gem::Requirement
|
|
72
|
+
none: false
|
|
73
|
+
requirements:
|
|
74
|
+
- - ! '>='
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0'
|
|
77
|
+
type: :development
|
|
78
|
+
prerelease: false
|
|
79
|
+
version_requirements: *2174255340
|
|
35
80
|
description: Easy breadcrumbs for your website
|
|
36
81
|
email: stanislaw.kolarzowski@gmail.com
|
|
37
82
|
executables: []
|
|
38
|
-
|
|
39
83
|
extensions: []
|
|
40
|
-
|
|
41
|
-
extra_rdoc_files:
|
|
84
|
+
extra_rdoc_files:
|
|
42
85
|
- LICENSE
|
|
43
86
|
- README.rdoc
|
|
44
|
-
files:
|
|
87
|
+
files:
|
|
45
88
|
- .document
|
|
46
|
-
-
|
|
89
|
+
- Gemfile
|
|
90
|
+
- Gemfile.lock
|
|
47
91
|
- LICENSE
|
|
48
92
|
- README.rdoc
|
|
49
93
|
- Rakefile
|
|
@@ -56,44 +100,47 @@ files:
|
|
|
56
100
|
- lib/easycrumbs/view_helpers.rb
|
|
57
101
|
- test/helper.rb
|
|
58
102
|
- test/routes.rb
|
|
103
|
+
- test/support/helpers/actors_helper.rb
|
|
104
|
+
- test/support/helpers/application_helper.rb
|
|
105
|
+
- test/support/helpers/countries_helper.rb
|
|
106
|
+
- test/support/helpers/movies_helper.rb
|
|
107
|
+
- test/support/stub_request.rb
|
|
59
108
|
- test/test_custom_collection.rb
|
|
60
109
|
- test/test_easycrumbs.rb
|
|
61
|
-
has_rdoc: true
|
|
62
110
|
homepage: http://github.com/staszek/easycrumbs
|
|
63
111
|
licenses: []
|
|
64
|
-
|
|
65
112
|
post_install_message:
|
|
66
|
-
rdoc_options:
|
|
67
|
-
|
|
68
|
-
require_paths:
|
|
113
|
+
rdoc_options: []
|
|
114
|
+
require_paths:
|
|
69
115
|
- lib
|
|
70
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
117
|
none: false
|
|
72
|
-
requirements:
|
|
73
|
-
- -
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
|
|
76
|
-
segments:
|
|
118
|
+
requirements:
|
|
119
|
+
- - ! '>='
|
|
120
|
+
- !ruby/object:Gem::Version
|
|
121
|
+
version: '0'
|
|
122
|
+
segments:
|
|
77
123
|
- 0
|
|
78
|
-
|
|
79
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
|
+
hash: -899090780415789417
|
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
126
|
none: false
|
|
81
|
-
requirements:
|
|
82
|
-
- -
|
|
83
|
-
- !ruby/object:Gem::Version
|
|
84
|
-
|
|
85
|
-
segments:
|
|
86
|
-
- 0
|
|
87
|
-
version: "0"
|
|
127
|
+
requirements:
|
|
128
|
+
- - ! '>='
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
88
131
|
requirements: []
|
|
89
|
-
|
|
90
132
|
rubyforge_project:
|
|
91
|
-
rubygems_version: 1.
|
|
133
|
+
rubygems_version: 1.8.10
|
|
92
134
|
signing_key:
|
|
93
135
|
specification_version: 3
|
|
94
136
|
summary: Easy breadcrumbs
|
|
95
|
-
test_files:
|
|
137
|
+
test_files:
|
|
96
138
|
- test/helper.rb
|
|
97
139
|
- test/routes.rb
|
|
140
|
+
- test/support/helpers/actors_helper.rb
|
|
141
|
+
- test/support/helpers/application_helper.rb
|
|
142
|
+
- test/support/helpers/countries_helper.rb
|
|
143
|
+
- test/support/helpers/movies_helper.rb
|
|
144
|
+
- test/support/stub_request.rb
|
|
98
145
|
- test/test_custom_collection.rb
|
|
99
146
|
- test/test_easycrumbs.rb
|