simple-navigation 3.11.0 → 3.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +6 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG +11 -0
  5. data/Gemfile +2 -16
  6. data/Guardfile +5 -0
  7. data/LICENSE +22 -0
  8. data/README.md +40 -0
  9. data/Rakefile +6 -39
  10. data/generators/navigation_config/templates/config/navigation.rb +7 -5
  11. data/init.rb +1 -0
  12. data/install.rb +5 -0
  13. data/lib/simple_navigation/adapters/rails.rb +5 -1
  14. data/lib/simple_navigation/core/configuration.rb +5 -1
  15. data/lib/simple_navigation/core/item.rb +2 -1
  16. data/lib/simple_navigation/core/item_adapter.rb +4 -4
  17. data/lib/simple_navigation/core/item_container.rb +6 -1
  18. data/lib/simple_navigation/rendering/renderer/breadcrumbs.rb +2 -2
  19. data/lib/simple_navigation/rendering/renderer/links.rb +2 -2
  20. data/lib/simple_navigation/rendering/renderer/list.rb +1 -1
  21. data/lib/simple_navigation/version.rb +3 -0
  22. data/lib/simple_navigation.rb +1 -0
  23. data/simple-navigation.gemspec +40 -0
  24. data/spec/initializers/have_css_matcher.rb +13 -0
  25. data/spec/lib/simple_navigation/adapters/padrino_spec.rb +23 -25
  26. data/spec/lib/simple_navigation/adapters/rails_spec.rb +276 -250
  27. data/spec/lib/simple_navigation/adapters/sinatra_spec.rb +64 -53
  28. data/spec/lib/simple_navigation/core/configuration_spec.rb +128 -106
  29. data/spec/lib/simple_navigation/core/item_adapter_spec.rb +144 -168
  30. data/spec/lib/simple_navigation/core/item_container_spec.rb +361 -339
  31. data/spec/lib/simple_navigation/core/item_spec.rb +571 -434
  32. data/spec/lib/simple_navigation/core/items_provider_spec.rb +35 -49
  33. data/spec/lib/simple_navigation/rails_controller_methods_spec.rb +194 -173
  34. data/spec/lib/simple_navigation/rendering/helpers_spec.rb +381 -225
  35. data/spec/lib/simple_navigation/rendering/renderer/base_spec.rb +205 -164
  36. data/spec/lib/simple_navigation/rendering/renderer/breadcrumbs_spec.rb +87 -67
  37. data/spec/lib/simple_navigation/rendering/renderer/json_spec.rb +52 -31
  38. data/spec/lib/simple_navigation/rendering/renderer/links_spec.rb +75 -48
  39. data/spec/lib/simple_navigation/rendering/renderer/list_spec.rb +62 -174
  40. data/spec/lib/simple_navigation/rendering/renderer/text_spec.rb +41 -28
  41. data/spec/lib/simple_navigation_spec.rb +207 -225
  42. data/spec/spec_helper.rb +53 -82
  43. data/uninstall.rb +1 -0
  44. metadata +100 -22
  45. data/README +0 -22
  46. data/VERSION +0 -1
@@ -1,209 +1,185 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe SimpleNavigation::ItemAdapter, 'when item is an object' do
3
+ module SimpleNavigation
4
+ describe ItemAdapter do
5
+ let(:item_adapter) { ItemAdapter.new(item) }
4
6
 
5
- before(:each) do
6
- @item = stub(:item)
7
- @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
8
- end
7
+ context 'when item is an object' do
8
+ let(:item) { double(:item, key: 'key', name: 'name', url: 'url') }
9
9
 
10
- describe 'key' do
11
- it "should delegate key to item" do
12
- @item.should_receive(:key)
13
- @item_adapter.key
14
- end
15
- end
10
+ shared_examples 'delegating to item' do |meth|
11
+ it "delegates #{meth} to item" do
12
+ expect(item).to receive(meth)
13
+ item_adapter.public_send(meth)
14
+ end
15
+ end
16
16
 
17
- describe 'url' do
18
- it "should delegate url to item" do
19
- @item.should_receive(:url)
20
- @item_adapter.url
21
- end
22
- end
17
+ it_behaves_like 'delegating to item', :key
18
+ it_behaves_like 'delegating to item', :url
19
+ it_behaves_like 'delegating to item', :name
23
20
 
24
- describe 'name' do
25
- it "should delegate name to item" do
26
- @item.should_receive(:name)
27
- @item_adapter.name
28
- end
29
- end
21
+ describe '#initialize' do
22
+ it 'sets the item' do
23
+ expect(item_adapter.item).to be item
24
+ end
25
+ end
30
26
 
31
- describe 'initialize' do
32
- it "should set the item" do
33
- @item_adapter.item.should == @item
34
- end
35
- end
27
+ describe '#options' do
28
+ context 'when item responds to options' do
29
+ let(:options) { double(:options) }
36
30
 
37
- describe 'options' do
38
- context 'item does respond to options' do
39
- before(:each) do
40
- @options = stub(:options)
41
- @item.stub!(:options => @options)
42
- end
43
- it "should return the item's options'" do
44
- @item_adapter.options.should == @options
45
- end
46
- end
47
- context 'item does not respond to options' do
48
- it "should return an empty hash" do
49
- @item_adapter.options.should == {}
50
- end
51
- end
52
- end
31
+ before { item.stub(options: options) }
53
32
 
54
- describe 'items' do
55
- context 'item does respond to items' do
56
- context 'items is nil' do
57
- before(:each) do
58
- @item.stub!(:items => nil)
33
+ it "returns the item's options" do
34
+ expect(item_adapter.options).to be options
35
+ end
59
36
  end
60
- it "should return nil" do
61
- @item_adapter.items.should be_nil
37
+
38
+ context 'item does not respond to options' do
39
+ it 'returns an empty hash' do
40
+ expect(item_adapter.options).to eq({})
41
+ end
62
42
  end
63
43
  end
64
- context 'items is not nil' do
65
- context 'items is empty' do
66
- before(:each) do
67
- @item.stub!(:items => [])
44
+
45
+ describe '#items' do
46
+ context 'when item responds to items' do
47
+ context 'and items is nil' do
48
+ before { item.stub(items: nil) }
49
+
50
+ it 'returns nil' do
51
+ expect(item_adapter.items).to be_nil
52
+ end
68
53
  end
69
- it "should return nil" do
70
- @item_adapter.items.should be_nil
54
+
55
+ context 'when items is not nil' do
56
+ context 'and items is empty' do
57
+ before { item.stub(items: []) }
58
+
59
+ it 'returns nil' do
60
+ expect(item_adapter.items).to be_nil
61
+ end
62
+ end
63
+
64
+ context 'and items is not empty' do
65
+ let(:items) { double(:items, empty?: false) }
66
+
67
+ before { item.stub(items: items) }
68
+
69
+ it 'returns the items' do
70
+ expect(item_adapter.items).to eq items
71
+ end
72
+ end
71
73
  end
72
74
  end
73
- context 'items is not empty' do
74
- before(:each) do
75
- @items = stub(:items, :empty? => false)
76
- @item.stub!(:items => @items)
77
- end
78
- it "should return the items" do
79
- @item_adapter.items.should == @items
75
+
76
+ context "when item doesn't respond to items" do
77
+ it 'returns nil' do
78
+ expect(item_adapter.items).to be_nil
80
79
  end
81
80
  end
82
81
  end
83
- end
84
- context 'item does not respond to items' do
85
- it "should return nil" do
86
- @item_adapter.items.should be_nil
87
- end
88
- end
89
- end
90
82
 
91
- describe 'to_simple_navigation_item' do
92
- before(:each) do
93
- @container = stub(:container)
94
- @item.stub!(:url => 'url', :name => 'name', :key => 'key', :options => {}, :items => [])
95
- end
96
- it "should create a SimpleNavigation::Item" do
97
- SimpleNavigation::Item.should_receive(:new).with(@container, 'key', 'name', 'url', {}, nil)
98
- @item_adapter.to_simple_navigation_item(@container)
99
- end
100
- end
83
+ describe '#to_simple_navigation_item' do
84
+ let(:container) { double(:container) }
101
85
 
102
- end
86
+ before { item.stub(items: [], options: {}) }
103
87
 
104
- describe SimpleNavigation::ItemAdapter, 'when item is a hash' do
88
+ it 'creates an Item' do
89
+ expect(Item).to receive(:new)
90
+ .with(container, 'key', 'name', 'url', {}, nil)
91
+ item_adapter.to_simple_navigation_item(container)
92
+ end
93
+ end
94
+ end
105
95
 
106
- before(:each) do
107
- @item = {:key => 'key', :url => 'url', :name => 'name'}
108
- @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
109
- end
96
+ context 'when item is a kind of hash' do
97
+ class ModifiedHash < Hash; end
110
98
 
111
- describe 'key' do
112
- it "should delegate key to item" do
113
- @item_adapter.item.should_receive(:key)
114
- @item_adapter.key
115
- end
116
- end
99
+ let(:item) { ModifiedHash[key: 'key', url: 'url', name: 'name'] }
117
100
 
118
- describe 'url' do
119
- it "should delegate url to item" do
120
- @item_adapter.item.should_receive(:url)
121
- @item_adapter.url
122
- end
123
- end
101
+ shared_examples 'delegating to item' do |meth|
102
+ it "delegates #{meth} to item" do
103
+ expect(item_adapter.item).to receive(meth)
104
+ item_adapter.public_send(meth)
105
+ end
106
+ end
124
107
 
125
- describe 'name' do
126
- it "should delegate name to item" do
127
- @item_adapter.item.should_receive(:name)
128
- @item_adapter.name
129
- end
130
- end
108
+ it_behaves_like 'delegating to item', :key
109
+ it_behaves_like 'delegating to item', :url
110
+ it_behaves_like 'delegating to item', :name
131
111
 
132
- describe 'initialize' do
133
- it "should set the item" do
134
- @item_adapter.item.should_not be_nil
135
- end
136
- it "should have converted the item into an object" do
137
- @item_adapter.item.should respond_to(:url)
138
- end
139
- end
112
+ describe '#initialize' do
113
+ it 'sets the item' do
114
+ expect(item_adapter.item).not_to be_nil
115
+ end
140
116
 
141
- describe 'options' do
142
- context 'item does respond to options' do
143
- before(:each) do
144
- @item = {:key => 'key', :url => 'url', :name => 'name', :options => {:my => :options}}
145
- @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
146
- end
147
- it "should return the item's options'" do
148
- @item_adapter.options.should == {:my => :options}
149
- end
150
- end
151
- context 'item does not respond to options' do
152
- it "should return an empty hash" do
153
- @item_adapter.options.should == {}
117
+ it 'converts the item into an object' do
118
+ expect(item_adapter.item).to respond_to(:url)
119
+ end
154
120
  end
155
- end
156
- end
157
121
 
158
- describe 'items' do
159
- context 'item does respond to items' do
160
- context 'items is nil' do
161
- before(:each) do
162
- @item = {:key => 'key', :url => 'url', :name => 'name', :items => nil}
163
- @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
122
+ describe '#options' do
123
+ context 'when item responds to options' do
124
+ before { item[:options] = { my: :options } }
125
+
126
+ it "returns the item's options" do
127
+ expect(item_adapter.options).to eq({ my: :options })
128
+ end
164
129
  end
165
- it "should return nil" do
166
- @item_adapter.items.should be_nil
130
+
131
+ context 'when item does not respond to options' do
132
+ it 'returns an empty hash' do
133
+ expect(item_adapter.options).to eq({})
134
+ end
167
135
  end
168
136
  end
169
- context 'items is not nil' do
170
- context 'items is empty' do
171
- before(:each) do
172
- @item = {:key => 'key', :url => 'url', :name => 'name', :items => []}
173
- @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
137
+
138
+ describe '#items' do
139
+ context 'when item responds to items' do
140
+ context 'and items is nil' do
141
+ before { item[:items] = nil }
142
+
143
+ it 'returns nil' do
144
+ expect(item_adapter.items).to be_nil
145
+ end
174
146
  end
175
- it "should return nil" do
176
- @item_adapter.items.should be_nil
147
+
148
+ context 'when items is not nil' do
149
+ context 'and items is empty' do
150
+ it 'returns nil' do
151
+ expect(item_adapter.items).to be_nil
152
+ end
153
+ end
154
+
155
+ context 'and items is not empty' do
156
+ before { item[:items] = ['not', 'empty'] }
157
+
158
+ it 'returns the items' do
159
+ expect(item_adapter.items).to eq ['not', 'empty']
160
+ end
161
+ end
177
162
  end
178
163
  end
179
- context 'items is not empty' do
180
- before(:each) do
181
- @item = {:key => 'key', :url => 'url', :name => 'name', :items => ['not', 'empty']}
182
- @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
183
- end
184
- it "should return the items" do
185
- @item_adapter.items.should == ['not', 'empty']
164
+
165
+ context 'when item does not respond to items' do
166
+ it 'returns nil' do
167
+ expect(item_adapter.items).to be_nil
186
168
  end
187
169
  end
188
170
  end
189
- end
190
- context 'item does not respond to items' do
191
- it "should return nil" do
192
- @item_adapter.items.should be_nil
193
- end
194
- end
195
- end
196
171
 
197
- describe 'to_simple_navigation_item' do
198
- before(:each) do
199
- @container = stub(:container)
200
- @item = {:key => 'key', :url => 'url', :name => 'name', :items => [], :options => {}}
201
- @item_adapter = SimpleNavigation::ItemAdapter.new(@item)
202
- end
203
- it "should create a SimpleNavigation::Item" do
204
- SimpleNavigation::Item.should_receive(:new).with(@container, 'key', 'name', 'url', {}, nil)
205
- @item_adapter.to_simple_navigation_item(@container)
172
+ describe '#to_simple_navigation_item' do
173
+ let(:container) { double(:container) }
174
+
175
+ before { item.merge(items: [], options: {}) }
176
+
177
+ it 'creates an Item' do
178
+ expect(Item).to receive(:new)
179
+ .with(container, 'key', 'name', 'url', {}, nil)
180
+ item_adapter.to_simple_navigation_item(container)
181
+ end
182
+ end
206
183
  end
207
184
  end
208
-
209
- end
185
+ end