tabs_on_rails 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,6 +1,21 @@
1
1
  = Changelog
2
2
 
3
3
 
4
+ == Release 1.1.0
5
+
6
+ * FIXED: Incompatibility with release < 1.0.0 caused by open_tabs and close_tabs methods changes compared to 0.8.0.
7
+
8
+ * CHANGED: Removed BUILD and STATUS constants. Added Version::ALPHA constant to be used when I need to package prereleases (see RubyGem --prerelease flag).
9
+
10
+ * CHANGED: Removed empty install/uninstall hooks and tasks folder.
11
+
12
+ * CHANGED: Removed rails/init hook because deprecated in Rails 3.
13
+
14
+ * CHANGED: Drop dependency from Echoe. Change Rakefile to use custom tasks.
15
+
16
+ * REMOVED: Deleted empty install.rb file.
17
+
18
+
4
19
  == Release 1.0.0
5
20
 
6
21
  * ADDED: Ability to pass arbitrary options to open_tabs and close_tags method. Thanks to aaronchi (closes #315)
data/LICENSE.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Simone Carletti
1
+ Copyright (c) 2009-2010 Simone Carletti
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -9,7 +9,7 @@ It provides helpers for creating tabs with a flexible interface.
9
9
  * Ruby >= 1.8.6
10
10
  * Rails >= 2.2
11
11
 
12
- Note. TabsOnRails doesn't work with Rails 2.1 or previous versions (see {Ticket #245}[http://code.simonecarletti.com/issues/show/245]).
12
+ Note. TabsOnRails doesn't work with Rails 2.1 or previous versions (see {this comment}[http://www.simonecarletti.com/blog/2009/04/tabsonrails/#comment-2901] and {this commit}[http://github.com/weppos/tabs_on_rails/commit/d5ae9f401e3d0acc87251fa8957a8625e90ba4b3]).
13
13
 
14
14
 
15
15
  == Rails Installation
@@ -17,9 +17,9 @@ Note. TabsOnRails doesn't work with Rails 2.1 or previous versions (see {Ticket
17
17
  === As a Gem
18
18
 
19
19
  This is the preferred way to install TabsOnRails and the best way if you want install a stable version.
20
- The GEM is hosted on {Gemcutter}[http://gemcutter.org/gems/tabs_on_rails].
20
+ The GEM is hosted on {RubyGems}[http://rubygems.org/gems/tabs_on_rails].
21
21
 
22
- $ gem install tabs_on_rails --source http://gemcutter.org/
22
+ $ gem install tabs_on_rails
23
23
 
24
24
  With Rails >= 2.2, you can specify the GEM dependency in your environment.rb file so that Rails will automatically check the requirement on startup.
25
25
 
@@ -28,7 +28,7 @@ With Rails >= 2.2, you can specify the GEM dependency in your environment.rb fil
28
28
  # other configurations
29
29
  # ...
30
30
 
31
- config.gem "tabs_on_rails", :source => "http://gemcutter.org/"
31
+ config.gem "tabs_on_rails"
32
32
 
33
33
  end
34
34
 
@@ -39,7 +39,7 @@ This is the preferred way if you want to live on the edge and install a developm
39
39
  $ script/plugin install git://github.com/weppos/tabs_on_rails.git
40
40
 
41
41
 
42
- == Quick Start
42
+ == Usage
43
43
 
44
44
  In your template use the <tt>tabs_tag</tt> helper to create your tab.
45
45
 
@@ -84,7 +84,7 @@ Use the <tt>current_tab</tt> helper method if you need to access the value of cu
84
84
  # In your view
85
85
  <p>The name of current tab is <%= current_tab %>.</p>
86
86
 
87
- The open tag can be customized with the `:open_tabs` option.
87
+ The open_tag can be customized with the `:open_tabs` option.
88
88
 
89
89
  <% tabs_tag :open_tabs => { :id => "tabs", :class => "cool" } do |tab| %>
90
90
  <%= tab.home 'Homepage', root_path %>
@@ -267,23 +267,19 @@ This is the final result.
267
267
  <li class="" style="float: right;"><a href="/account">Account</a></li>
268
268
  </ul>
269
269
 
270
- == Documentation
271
270
 
272
- The library is still under development and this README file might not be contain the latest changes.
273
- For the full documentation, development roadmap and more information please visit the {project page}[http://code.simonecarletti.com/wiki/tabsonrails].
271
+ == Author
274
272
 
275
-
276
- == Credits
277
-
278
- Author:: {Simone Carletti}[http://www.simonecarletti.com/] <weppos@weppos.net>
273
+ * {Simone Carletti}[http://www.simonecarletti.com] <weppos@weppos.net>
279
274
 
280
275
 
281
276
  == Resources
282
277
 
283
- * {Homepage}[http://code.simonecarletti.com/tabsonrails]
284
- * {GitHub}[http://github.com/weppos/tabs_on_rails/]
278
+ * {Homepage}[http://www.simonecarletti.com/code/tabs_on_rails]
279
+ * {Source}[http://github.com/weppos/tabs_on_rails]
280
+ * {Bugs & Features}[http://github.com/weppos/tabs_on_rails/issues]
285
281
 
286
282
 
287
283
  == License
288
284
 
289
- Copyright (c) 2009 Simone Carletti, TabsOnRails is released under the MIT license.
285
+ Copyright (c) 2009-2010 Simone Carletti, TabsOnRails is released under the MIT license.
data/Rakefile CHANGED
@@ -1,42 +1,115 @@
1
- $:.unshift(File.dirname(__FILE__) + "/lib")
1
+ require "rubygems"
2
+ require "rake/testtask"
3
+ require "rake/rdoctask"
4
+ require "rake/gempackagetask"
2
5
 
3
- require 'rubygems'
4
- require 'rake'
5
- require 'echoe'
6
- require 'tabs_on_rails'
6
+ $:.unshift(File.dirname(__FILE__) + "/lib")
7
+ require "tabs_on_rails"
7
8
 
8
9
 
9
10
  PKG_NAME = ENV['PKG_NAME'] || TabsOnRails::GEM
10
11
  PKG_VERSION = ENV['PKG_VERSION'] || TabsOnRails::VERSION
11
- RUBYFORGE_PROJECT = nil
12
12
 
13
13
  if ENV['SNAPSHOT'].to_i == 1
14
14
  PKG_VERSION << "." << Time.now.utc.strftime("%Y%m%d%H%M%S")
15
15
  end
16
-
17
-
18
- Echoe.new(PKG_NAME, PKG_VERSION) do |p|
19
- p.author = "Simone Carletti"
20
- p.email = "weppos@weppos.net"
21
- p.summary = "A simple Ruby on Rails plugin for creating and managing Tabs."
22
- p.url = "http://code.simonecarletti.com/tabsonrails"
23
- p.description = <<-EOD
16
+
17
+
18
+ # Run all the tests in the /test folder
19
+ Rake::TestTask.new do |t|
20
+ t.libs << "test"
21
+ t.test_files = FileList["test/**/*_test.rb"]
22
+ t.verbose = true
23
+ end
24
+
25
+ # Generate documentation
26
+ Rake::RDocTask.new do |rd|
27
+ rd.main = "README.rdoc"
28
+ rd.rdoc_files.include("*.rdoc", "lib/**/*.rb")
29
+ rd.rdoc_dir = "rdoc"
30
+ end
31
+
32
+ # Run test by default.
33
+ task :default => ["test"]
34
+
35
+ # This builds the actual gem. For details of what all these options
36
+ # mean, and other ones you can add, check the documentation here:
37
+ #
38
+ # http://rubygems.org/read/chapter/20
39
+ #
40
+ spec = Gem::Specification.new do |s|
41
+
42
+ s.name = PKG_NAME
43
+ s.version = PKG_VERSION
44
+ s.summary = "A simple Ruby on Rails plugin for creating and managing Tabs."
45
+ s.author = "Simone Carletti"
46
+ s.email = "weppos@weppos.net"
47
+ s.homepage = "http://www.simonecarletti.com/code/tabs_on_rails"
48
+ s.description = <<-EOD
24
49
  TabsOnRails is a simple Ruby on Rails plugin for creating and managing Tabs. \
25
50
  It provides helpers for creating tabs with a flexible interface.
26
51
  EOD
27
- p.project = RUBYFORGE_PROJECT
28
52
 
29
- p.need_zip = true
53
+ s.has_rdoc = true
54
+ # You should probably have a README of some kind. Change the filename
55
+ # as appropriate
56
+ s.extra_rdoc_files = Dir.glob("*.rdoc")
57
+ s.rdoc_options = %w(--main README.rdoc)
30
58
 
31
- p.development_dependencies += ["rake ~>0.8.7",
32
- "echoe ~>3.2.0"]
59
+ # Add any extra files to include in the gem (like your README)
60
+ s.files = %w(Rakefile init.rb) + Dir.glob("*.{rdoc,gemspec}") + Dir.glob("{test,lib,rails}/**/*")
61
+ s.require_paths = ["lib"]
33
62
 
34
- p.rcov_options = ["-Itest -x Rakefile,rcov,json,mocha,rack,actionpack,activesupport"]
63
+ # If you want to depend on other gems, add them here, along with any
64
+ # relevant versions
65
+ # s.add_dependency("some_other_gem", "~> 0.1.0")
66
+
67
+ # If your tests use any gems, include them here
68
+ # s.add_development_dependency("mocha") # for example
35
69
  end
36
70
 
71
+ # This task actually builds the gem. We also regenerate a static
72
+ # .gemspec file, which is useful if something (i.e. GitHub) will
73
+ # be automatically building a gem for this project. If you're not
74
+ # using GitHub, edit as appropriate.
75
+ Rake::GemPackageTask.new(spec) do |pkg|
76
+ pkg.gem_spec = spec
77
+ end
78
+
79
+ desc "Build the gemspec file #{spec.name}.gemspec"
80
+ task :gemspec do
81
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
82
+ File.open(file, "w") {|f| f << spec.to_ruby }
83
+ end
84
+
85
+ desc "Remove any temporary products, including gemspec."
86
+ task :clean => [:clobber] do
87
+ rm "#{spec.name}.gemspec"
88
+ end
89
+
90
+ desc "Remove any generated file"
91
+ task :clobber => [:clobber_rdoc, :clobber_rcov, :clobber_package]
92
+
93
+ desc "Package the library and generates the gemspec"
94
+ task :package => [:gemspec]
95
+
96
+ begin
97
+ require "rcov/rcovtask"
98
+
99
+ desc "Create a code coverage report."
100
+ Rcov::RcovTask.new do |t|
101
+ t.test_files = FileList["test/**/*_test.rb"]
102
+ t.ruby_opts << "-Itest -x mocha,rcov,Rakefile"
103
+ t.verbose = true
104
+ end
105
+ rescue LoadError
106
+ task :clobber_rcov
107
+ puts "RCov is not available"
108
+ end
37
109
 
38
110
  begin
39
- require 'code_statistics'
111
+ require "code_statistics"
112
+
40
113
  desc "Show library's code statistics"
41
114
  task :stats do
42
115
  CodeStatistics.new(["TabsOnRails", "lib"],
@@ -27,10 +27,19 @@ module TabsOnRails
27
27
  @builder = (options.delete(:builder) || TabsBuilder).new(@context, options)
28
28
  end
29
29
 
30
- %w(open_tabs close_tabs).each do |method|
31
- define_method(method) do |*args|
32
- @builder.send(method, *args)
33
- end
30
+ %w(open_tabs close_tabs).each do |name|
31
+ define_method(name) do |*args| # def open_tabs(*args)
32
+ method = @builder.method(name) # method = @builder.method(:open_tabs)
33
+ if method.arity.zero? # if method.arity.zero?
34
+ message = "Incomplete `#{name}' definition. " + # ...
35
+ "Use #{name}(*args) to ignore arguments " + # ...
36
+ "or #{name}(options) to collect options" # ...
37
+ ActiveSupport::Deprecation.warn(message) # ...
38
+ method.call # method.call
39
+ else # else
40
+ method.call(*args) # method.call(*args)
41
+ end # end
42
+ end # end
34
43
  end
35
44
 
36
45
  def method_missing(*args)
@@ -18,14 +18,13 @@ module TabsOnRails
18
18
 
19
19
  module Version
20
20
  MAJOR = 1
21
- MINOR = 0
22
- TINY = 0
21
+ MINOR = 1
22
+ PATCH = 0
23
+ BUILD = nil
23
24
 
24
- STRING = [MAJOR, MINOR, TINY].join('.')
25
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join(".")
25
26
  end
26
27
 
27
- VERSION = Version::STRING
28
- STATUS = 'stable'
29
- BUILD = ''.match(/(\d+)/).to_a.first
28
+ VERSION = Version::STRING
30
29
 
31
30
  end
data/rails/init.rb CHANGED
@@ -1,5 +1,3 @@
1
1
  require 'tabs_on_rails'
2
2
 
3
3
  ActionController::Base.send :include, TabsOnRails::ControllerMixin
4
-
5
- RAILS_DEFAULT_LOGGER.info("** TabsOnRails: initialized properly") if defined?(RAILS_DEFAULT_LOGGER)
@@ -2,36 +2,29 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{tabs_on_rails}
5
- s.version = "1.0.0"
5
+ s.version = "1.1.0"
6
6
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Simone Carletti"]
9
- s.date = %q{2009-10-29}
9
+ s.date = %q{2010-08-09}
10
10
  s.description = %q{ TabsOnRails is a simple Ruby on Rails plugin for creating and managing Tabs. It provides helpers for creating tabs with a flexible interface.
11
11
  }
12
12
  s.email = %q{weppos@weppos.net}
13
- s.extra_rdoc_files = ["CHANGELOG.rdoc", "LICENSE.rdoc", "README.rdoc", "lib/tabs_on_rails.rb", "lib/tabs_on_rails/controller_mixin.rb", "lib/tabs_on_rails/tabs.rb", "lib/tabs_on_rails/tabs/builder.rb", "lib/tabs_on_rails/tabs/tabs_builder.rb", "lib/tabs_on_rails/version.rb", "tasks/tabs_on_rails_tasks.rake"]
14
- s.files = ["CHANGELOG.rdoc", "LICENSE.rdoc", "Manifest", "README.rdoc", "Rakefile", "init.rb", "install.rb", "lib/tabs_on_rails.rb", "lib/tabs_on_rails/controller_mixin.rb", "lib/tabs_on_rails/tabs.rb", "lib/tabs_on_rails/tabs/builder.rb", "lib/tabs_on_rails/tabs/tabs_builder.rb", "lib/tabs_on_rails/version.rb", "rails/init.rb", "tasks/tabs_on_rails_tasks.rake", "test/controller_mixin_helpers_test.rb", "test/controller_mixin_test.rb", "test/controller_mixin_with_controller_test.rb", "test/fixtures/mixin/default.html.erb", "test/fixtures/mixin/with_open_close_tabs.html.erb", "test/tabs/builder_test.rb", "test/tabs/tabs_builder_test.rb", "test/test_helper.rb", "uninstall.rb", "tabs_on_rails.gemspec"]
15
- s.homepage = %q{http://code.simonecarletti.com/tabsonrails}
16
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Tabs_on_rails", "--main", "README.rdoc"]
13
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "LICENSE.rdoc", "README.rdoc"]
14
+ s.files = ["Rakefile", "init.rb", "CHANGELOG.rdoc", "LICENSE.rdoc", "README.rdoc", "tabs_on_rails.gemspec", "test/controller_mixin_test.rb", "test/fixtures", "test/fixtures/mixin", "test/fixtures/mixin/default.html.erb", "test/fixtures/mixin/with_open_close_tabs.html.erb", "test/tabs", "test/tabs/builder_test.rb", "test/tabs/tabs_builder_test.rb", "test/tabs_test.rb", "test/test_helper.rb", "lib/tabs_on_rails", "lib/tabs_on_rails/controller_mixin.rb", "lib/tabs_on_rails/tabs", "lib/tabs_on_rails/tabs/builder.rb", "lib/tabs_on_rails/tabs/tabs_builder.rb", "lib/tabs_on_rails/tabs.rb", "lib/tabs_on_rails/version.rb", "lib/tabs_on_rails.rb", "rails/init.rb"]
15
+ s.homepage = %q{http://www.simonecarletti.com/code/tabs_on_rails}
16
+ s.rdoc_options = ["--main", "README.rdoc"]
17
17
  s.require_paths = ["lib"]
18
- s.rubygems_version = %q{1.3.5}
18
+ s.rubygems_version = %q{1.3.7}
19
19
  s.summary = %q{A simple Ruby on Rails plugin for creating and managing Tabs.}
20
- s.test_files = ["test/controller_mixin_helpers_test.rb", "test/controller_mixin_test.rb", "test/controller_mixin_with_controller_test.rb", "test/tabs/builder_test.rb", "test/tabs/tabs_builder_test.rb", "test/test_helper.rb"]
21
20
 
22
21
  if s.respond_to? :specification_version then
23
22
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
23
  s.specification_version = 3
25
24
 
26
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
- s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
28
- s.add_development_dependency(%q<echoe>, ["~> 3.2.0"])
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
29
26
  else
30
- s.add_dependency(%q<rake>, ["~> 0.8.7"])
31
- s.add_dependency(%q<echoe>, ["~> 3.2.0"])
32
27
  end
33
28
  else
34
- s.add_dependency(%q<rake>, ["~> 0.8.7"])
35
- s.add_dependency(%q<echoe>, ["~> 3.2.0"])
36
29
  end
37
30
  end
@@ -13,7 +13,7 @@ class ControllerMixinTest < ActionController::TestCase
13
13
  @response = ActionController::TestResponse.new
14
14
  end
15
15
 
16
-
16
+
17
17
  def test_set_tab
18
18
  controller.set_tab :footab
19
19
  assert_equal(:footab, controller.tab_stack[:default])
@@ -87,4 +87,186 @@ class ControllerMixinTest < ActionController::TestCase
87
87
  assert(!controller.current_tab?(:firsttab, :custom))
88
88
  end
89
89
 
90
- end
90
+ end
91
+
92
+
93
+ class ControllerMixinHelpersTest < ActionView::TestCase
94
+ tests TabsOnRails::ControllerMixin::HelperMethods
95
+ include ActionView::Helpers::TagHelper
96
+ include ActionView::Helpers::UrlHelper
97
+
98
+ MockBuilder = Class.new(TabsOnRails::Tabs::Builder) do
99
+ def initialize_with_mocha(*args)
100
+ checkpoint
101
+ initialize_without_mocha(*args)
102
+ end
103
+ alias_method_chain :initialize, :mocha
104
+
105
+ def checkpoint
106
+ end
107
+
108
+ def tab_for(tab, name, *args)
109
+ end
110
+ end
111
+
112
+ NilBoundariesBuilder = Class.new(TabsOnRails::Tabs::Builder) do
113
+ def tab_for(tab, name, *args)
114
+ @context.content_tag(:span, name)
115
+ end
116
+ end
117
+
118
+ NilOpenBoundaryBuilder = Class.new(NilBoundariesBuilder) do
119
+ def close_tabs(options = {})
120
+ '<br />'
121
+ end
122
+ end
123
+
124
+ NilCloseBoundaryBuilder = Class.new(NilBoundariesBuilder) do
125
+ def open_tabs(options = {})
126
+ '<br />'
127
+ end
128
+ end
129
+
130
+
131
+ def test_tabs_tag_should_raise_local_jump_error_without_block
132
+ assert_raise(LocalJumpError) { tabs_tag }
133
+ end
134
+
135
+ def test_tabs_tag_with_builder
136
+ MockBuilder.any_instance.expects(:checkpoint).once
137
+ tabs_tag(:builder => MockBuilder) {}
138
+ end
139
+
140
+ def test_tabs_tag_with_namespace
141
+ MockBuilder.any_instance.expects(:checkpoint).once
142
+ tabs_tag(:builder => MockBuilder, :namespace => :custom) do |tabs|
143
+ builder = tabs.instance_variable_get(:'@builder')
144
+ assert_equal(:custom, builder.instance_variable_get(:'@namespace'))
145
+ end
146
+ end
147
+
148
+
149
+ def test_tabs_tag_should_not_concat_open_close_tabs_when_nil
150
+ content = tabs_tag(:builder => NilBoundariesBuilder) do |t|
151
+ concat t.single('Single', '#')
152
+ end
153
+
154
+ assert_dom_equal('<span>Single</span>', content)
155
+ end
156
+
157
+ def test_tabs_tag_should_not_concat_open_tabs_when_nil
158
+ content = tabs_tag(:builder => NilOpenBoundaryBuilder) do |t|
159
+ concat t.single('Single', '#')
160
+ end
161
+
162
+ assert_dom_equal('<span>Single</span><br />', content)
163
+ end
164
+
165
+ def test_tabs_tag_should_not_concat_close_tabs_when_nil
166
+ content = tabs_tag(:builder => NilCloseBoundaryBuilder) do |t|
167
+ concat t.single('Single', '#')
168
+ end
169
+
170
+ assert_dom_equal('<br /><span>Single</span>', content)
171
+ end
172
+
173
+ end
174
+
175
+
176
+ class ControllerMixinWithControllerTest < ActionController::TestCase
177
+ include ControllerTestHelpers
178
+
179
+ class MixinController < ActionController::Base
180
+ def self.controller_name; "mixin"; end
181
+ def self.controller_path; "mixin"; end
182
+
183
+ layout false
184
+
185
+ set_tab :dashboard
186
+ set_tab :welcome, :only => %w(action_welcome)
187
+ set_tab :dashboard, :only => %w(action_namespace)
188
+ set_tab :homepage, :namespace, :only => %w(action_namespace)
189
+
190
+ def method_missing(method, *args)
191
+ if method =~ /^action_(.*)/
192
+ render :action => (params[:template] || 'default')
193
+ end
194
+ end
195
+
196
+ def rescue_action(e) raise end
197
+ end
198
+
199
+ MixinController.view_paths = [ File.dirname(__FILE__) + "/fixtures/" ]
200
+
201
+ def setup
202
+ @controller = MixinController.new
203
+ @controller_proxy = ControllerProxy.new(@controller)
204
+ @request = ActionController::TestRequest.new
205
+ @response = ActionController::TestResponse.new
206
+ end
207
+
208
+
209
+ def test_render_default
210
+ get :action_dashboard
211
+ assert_equal(%Q{<ul>
212
+ <li><span>Dashboard</span></li>
213
+ <li><a href="/w">Welcome</a></li>
214
+ </ul>}, @response.body)
215
+ end
216
+
217
+ def test_render_with_open_close_tabs
218
+ get :action_dashboard, :template => "with_open_close_tabs"
219
+ assert_equal(%Q{<ul id="tabs">
220
+ <li><span>Dashboard</span></li>
221
+ <li><a href="/w">Welcome</a></li>
222
+ </ul>}, @response.body)
223
+ end
224
+
225
+
226
+ def test_set_tab
227
+ get :action_dashboard
228
+ assert_equal(:dashboard, controller.current_tab)
229
+ assert_equal(:dashboard, controller.current_tab(:default))
230
+ assert_equal(%Q{<ul>
231
+ <li><span>Dashboard</span></li>
232
+ <li><a href="/w">Welcome</a></li>
233
+ </ul>}, @response.body)
234
+ end
235
+
236
+ def test_set_tab_with_only_option
237
+ get :action_welcome
238
+ assert_equal(:welcome, controller.current_tab)
239
+ assert_equal(:welcome, controller.current_tab(:default))
240
+ assert_equal(%Q{<ul>
241
+ <li><a href="/d">Dashboard</a></li>
242
+ <li><span>Welcome</span></li>
243
+ </ul>}, @response.body)
244
+ end
245
+
246
+ def test_set_tab_with_namespace
247
+ get :action_namespace
248
+ assert_equal(:dashboard, controller.current_tab)
249
+ assert_equal(:dashboard, controller.current_tab(:default))
250
+ assert_equal(:homepage, controller.current_tab(:namespace))
251
+ assert_equal(%Q{<ul>
252
+ <li><span>Dashboard</span></li>
253
+ <li><a href="/w">Welcome</a></li>
254
+ </ul>}, @response.body)
255
+ end
256
+
257
+
258
+ def test_current_tab
259
+ get :action_dashboard
260
+ assert_equal :dashboard, controller.current_tab
261
+ assert_equal :dashboard, controller.current_tab(:default)
262
+ end
263
+
264
+ def test_current_tab_question
265
+ get :action_dashboard
266
+ assert controller.current_tab?(:dashboard)
267
+ assert controller.current_tab?(:dashboard, :default)
268
+ assert !controller.current_tab?(:foobar)
269
+ assert !controller.current_tab?(:foobar, :default)
270
+ end
271
+
272
+ end
@@ -1,8 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class BuilderTest < ActiveSupport::TestCase
4
-
5
- BuilderTemplate = Class.new do
4
+
5
+ Template = Class.new do
6
6
  include ActionView::Helpers::TagHelper
7
7
  include ActionView::Helpers::UrlHelper
8
8
 
@@ -17,12 +17,12 @@ class BuilderTest < ActiveSupport::TestCase
17
17
  end
18
18
  end
19
19
  end
20
-
20
+
21
21
  def setup
22
- @template = BuilderTemplate.new
22
+ @template = Template.new
23
23
  @builder = TabsOnRails::Tabs::Builder.new(@template)
24
24
  end
25
-
25
+
26
26
 
27
27
  def test_initialize_should_require_context
28
28
  assert_raise(ArgumentError) { TabsOnRails::Tabs::Builder.new }
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class TabsBuilderTest < ActionView::TestCase
4
4
 
5
- TabsBuilderTemplate = Class.new do
5
+ Template = Class.new do
6
6
  include ActionView::Helpers::TagHelper
7
7
  include ActionView::Helpers::UrlHelper
8
8
 
@@ -19,7 +19,7 @@ class TabsBuilderTest < ActionView::TestCase
19
19
  end
20
20
 
21
21
  def setup
22
- @template = TabsBuilderTemplate.new
22
+ @template = Template.new
23
23
  @builder = TabsOnRails::Tabs::TabsBuilder.new(@template)
24
24
  end
25
25
 
@@ -44,15 +44,15 @@ class TabsBuilderTest < ActionView::TestCase
44
44
  def test_should_implement_builder
45
45
  assert_equal(TabsOnRails::Tabs::Builder, TabsOnRails::Tabs::TabsBuilder.superclass)
46
46
  end
47
-
47
+
48
48
  def test_tab_for_should_return_link_to_unless_current_tab
49
49
  assert_dom_equal('<li><a href="#">Welcome</a></li>', @builder.tab_for(:welcome, 'Welcome', '#'))
50
50
  assert_dom_equal('<li><a href="http://foobar.com/">Foo Bar</a></li>', @builder.tab_for(:welcome, 'Foo Bar', 'http://foobar.com/'))
51
51
  end
52
-
52
+
53
53
  def test_tab_for_should_return_span_if_current_tab
54
54
  assert_dom_equal('<li><span>Dashboard</span></li>', @builder.tab_for(:dashboard, 'Dashboard', '#'))
55
55
  assert_dom_equal('<li><span>Foo Bar</span></li>', @builder.tab_for(:dashboard, 'Foo Bar', '#'))
56
56
  end
57
-
57
+
58
58
  end
data/test/tabs_test.rb ADDED
@@ -0,0 +1,85 @@
1
+ require 'test_helper'
2
+
3
+ class TabsTest < ActiveSupport::TestCase
4
+
5
+ Template = Class.new do
6
+ include ActionView::Helpers::TagHelper
7
+ include ActionView::Helpers::UrlHelper
8
+
9
+ def current_tab(namespace)
10
+ case namespace
11
+ when nil, :default
12
+ :dashboard
13
+ when :foospace
14
+ :footab
15
+ else
16
+ :elsetab
17
+ end
18
+ end
19
+ end
20
+
21
+ OpenZeroArgsBuilder = Class.new(TabsOnRails::Tabs::Builder) do
22
+ def open_tabs
23
+ '<ul>'
24
+ end
25
+ end
26
+
27
+ CloseZeroArgsBuilder = Class.new(TabsOnRails::Tabs::Builder) do
28
+ def close_tabs
29
+ '</ul>'
30
+ end
31
+ end
32
+
33
+
34
+ def setup
35
+ @template = Template.new
36
+ @klass = TabsOnRails::Tabs
37
+ @tabs = @klass.new(@template)
38
+ end
39
+
40
+
41
+ def test_initialize
42
+ @tabs = @klass.new(@template)
43
+ assert_equal @template, @tabs.instance_variable_get(:"@context")
44
+ assert_instance_of TabsOnRails::Tabs::TabsBuilder, @tabs.instance_variable_get(:"@builder")
45
+ end
46
+
47
+ def test_initialize_with_option_builder
48
+ builder = Class.new(TabsOnRails::Tabs::TabsBuilder)
49
+ @tabs = @klass.new(@template, :builder => builder)
50
+ assert_equal @template, @tabs.instance_variable_get(:"@context")
51
+ assert_instance_of builder, @tabs.instance_variable_get(:"@builder")
52
+ end
53
+
54
+
55
+ def test_open_tabs
56
+ assert_equal '<ul>', @tabs.open_tabs
57
+ end
58
+
59
+ def test_open_tabs_with_options
60
+ assert_equal '<ul class="foo">', @tabs.open_tabs(:class => "foo")
61
+ end
62
+
63
+ def test_open_tabs_should_ignore_options_if_arity_is_zero
64
+ @tabs = @klass.new(@template, :builder => OpenZeroArgsBuilder)
65
+ assert_nothing_raised do
66
+ assert_equal '<ul>', @tabs.open_tabs(:class => "foo")
67
+ end
68
+ end
69
+
70
+ def test_close_tabs
71
+ assert_equal '</ul>', @tabs.close_tabs
72
+ end
73
+
74
+ def test_close_tabs_with_options
75
+ assert_equal '</ul>', @tabs.close_tabs(:class => "foo")
76
+ end
77
+
78
+ def test_open_tabs_should_ignore_options_if_arity_is_zero
79
+ @tabs = @klass.new(@template, :builder => CloseZeroArgsBuilder)
80
+ assert_nothing_raised do
81
+ assert_equal '</ul>', @tabs.close_tabs(:class => "foo")
82
+ end
83
+ end
84
+
85
+ end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
- gem 'rails', '~>2.3.0'
3
- gem 'mocha', '~>0.9.7'
2
+ gem 'rails', '~>2.3.5'
3
+ gem 'mocha', '~>0.9.8'
4
4
 
5
5
  # Remember! Due to some Mocha internal changes,
6
6
  # Rails 2.2.x requires Mocha 0.9.5 and
@@ -45,5 +45,5 @@ module ControllerTestHelpers
45
45
  end
46
46
  end
47
47
  end
48
-
49
- end
48
+
49
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabs_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 0
10
+ version: 1.1.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Simone Carletti
@@ -9,29 +15,10 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-10-29 00:00:00 +01:00
18
+ date: 2010-08-09 00:00:00 +02:00
13
19
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rake
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ~>
22
- - !ruby/object:Gem::Version
23
- version: 0.8.7
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: echoe
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 3.2.0
34
- version:
20
+ dependencies: []
21
+
35
22
  description: " TabsOnRails is a simple Ruby on Rails plugin for creating and managing Tabs. It provides helpers for creating tabs with a flexible interface.\n"
36
23
  email: weppos@weppos.net
37
24
  executables: []
@@ -42,76 +29,61 @@ extra_rdoc_files:
42
29
  - CHANGELOG.rdoc
43
30
  - LICENSE.rdoc
44
31
  - README.rdoc
45
- - lib/tabs_on_rails.rb
46
- - lib/tabs_on_rails/controller_mixin.rb
47
- - lib/tabs_on_rails/tabs.rb
48
- - lib/tabs_on_rails/tabs/builder.rb
49
- - lib/tabs_on_rails/tabs/tabs_builder.rb
50
- - lib/tabs_on_rails/version.rb
51
- - tasks/tabs_on_rails_tasks.rake
52
32
  files:
33
+ - Rakefile
34
+ - init.rb
53
35
  - CHANGELOG.rdoc
54
36
  - LICENSE.rdoc
55
- - Manifest
56
37
  - README.rdoc
57
- - Rakefile
58
- - init.rb
59
- - install.rb
60
- - lib/tabs_on_rails.rb
61
- - lib/tabs_on_rails/controller_mixin.rb
62
- - lib/tabs_on_rails/tabs.rb
63
- - lib/tabs_on_rails/tabs/builder.rb
64
- - lib/tabs_on_rails/tabs/tabs_builder.rb
65
- - lib/tabs_on_rails/version.rb
66
- - rails/init.rb
67
- - tasks/tabs_on_rails_tasks.rake
68
- - test/controller_mixin_helpers_test.rb
38
+ - tabs_on_rails.gemspec
69
39
  - test/controller_mixin_test.rb
70
- - test/controller_mixin_with_controller_test.rb
71
40
  - test/fixtures/mixin/default.html.erb
72
41
  - test/fixtures/mixin/with_open_close_tabs.html.erb
73
42
  - test/tabs/builder_test.rb
74
43
  - test/tabs/tabs_builder_test.rb
44
+ - test/tabs_test.rb
75
45
  - test/test_helper.rb
76
- - uninstall.rb
77
- - tabs_on_rails.gemspec
46
+ - lib/tabs_on_rails/controller_mixin.rb
47
+ - lib/tabs_on_rails/tabs/builder.rb
48
+ - lib/tabs_on_rails/tabs/tabs_builder.rb
49
+ - lib/tabs_on_rails/tabs.rb
50
+ - lib/tabs_on_rails/version.rb
51
+ - lib/tabs_on_rails.rb
52
+ - rails/init.rb
78
53
  has_rdoc: true
79
- homepage: http://code.simonecarletti.com/tabsonrails
54
+ homepage: http://www.simonecarletti.com/code/tabs_on_rails
80
55
  licenses: []
81
56
 
82
57
  post_install_message:
83
58
  rdoc_options:
84
- - --line-numbers
85
- - --inline-source
86
- - --title
87
- - Tabs_on_rails
88
59
  - --main
89
60
  - README.rdoc
90
61
  require_paths:
91
62
  - lib
92
63
  required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
93
65
  requirements:
94
66
  - - ">="
95
67
  - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
96
71
  version: "0"
97
- version:
98
72
  required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
99
74
  requirements:
100
75
  - - ">="
101
76
  - !ruby/object:Gem::Version
102
- version: "1.2"
103
- version:
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
104
81
  requirements: []
105
82
 
106
83
  rubyforge_project:
107
- rubygems_version: 1.3.5
84
+ rubygems_version: 1.3.7
108
85
  signing_key:
109
86
  specification_version: 3
110
87
  summary: A simple Ruby on Rails plugin for creating and managing Tabs.
111
- test_files:
112
- - test/controller_mixin_helpers_test.rb
113
- - test/controller_mixin_test.rb
114
- - test/controller_mixin_with_controller_test.rb
115
- - test/tabs/builder_test.rb
116
- - test/tabs/tabs_builder_test.rb
117
- - test/test_helper.rb
88
+ test_files: []
89
+
data/Manifest DELETED
@@ -1,24 +0,0 @@
1
- CHANGELOG.rdoc
2
- LICENSE.rdoc
3
- Manifest
4
- README.rdoc
5
- Rakefile
6
- init.rb
7
- install.rb
8
- lib/tabs_on_rails.rb
9
- lib/tabs_on_rails/controller_mixin.rb
10
- lib/tabs_on_rails/tabs.rb
11
- lib/tabs_on_rails/tabs/builder.rb
12
- lib/tabs_on_rails/tabs/tabs_builder.rb
13
- lib/tabs_on_rails/version.rb
14
- rails/init.rb
15
- tasks/tabs_on_rails_tasks.rake
16
- test/controller_mixin_helpers_test.rb
17
- test/controller_mixin_test.rb
18
- test/controller_mixin_with_controller_test.rb
19
- test/fixtures/mixin/default.html.erb
20
- test/fixtures/mixin/with_open_close_tabs.html.erb
21
- test/tabs/builder_test.rb
22
- test/tabs/tabs_builder_test.rb
23
- test/test_helper.rb
24
- uninstall.rb
data/install.rb DELETED
@@ -1 +0,0 @@
1
- # Install hook code here
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :tabs_on_rails do
3
- # # Task goes here
4
- # end
@@ -1,86 +0,0 @@
1
- require 'test_helper'
2
-
3
- class MockBuilder < TabsOnRails::Tabs::Builder
4
-
5
- def initialize_with_mocha(*args)
6
- checkpoint
7
- initialize_without_mocha(*args)
8
- end
9
- alias_method_chain :initialize, :mocha
10
-
11
- def checkpoint
12
- end
13
-
14
- def tab_for(tab, name, *args)
15
- end
16
-
17
- end
18
-
19
- class NilBoundariesBuilder < TabsOnRails::Tabs::Builder
20
- def tab_for(tab, name, *args)
21
- @context.content_tag(:span, name)
22
- end
23
- end
24
-
25
- class NilOpenBoundaryBuilder < NilBoundariesBuilder
26
- def close_tabs(options = {})
27
- '<br />'
28
- end
29
- end
30
-
31
- class NilCloseBoundaryBuilder < NilBoundariesBuilder
32
- def open_tabs(options = {})
33
- '<br />'
34
- end
35
- end
36
-
37
-
38
- class ControllerMixinHelpersTest < ActionView::TestCase
39
- tests TabsOnRails::ControllerMixin::HelperMethods
40
- include ActionView::Helpers::TagHelper
41
- include ActionView::Helpers::UrlHelper
42
-
43
-
44
- def test_tabs_tag_should_raise_local_jump_error_without_block
45
- assert_raise(LocalJumpError) { tabs_tag }
46
- end
47
-
48
- def test_tabs_tag_with_builder
49
- MockBuilder.any_instance.expects(:checkpoint).once
50
- tabs_tag(:builder => MockBuilder) {}
51
- end
52
-
53
- def test_tabs_tag_with_namespace
54
- MockBuilder.any_instance.expects(:checkpoint).once
55
- tabs_tag(:builder => MockBuilder, :namespace => :custom) do |tabs|
56
- builder = tabs.instance_variable_get(:'@builder')
57
- assert_equal(:custom, builder.instance_variable_get(:'@namespace'))
58
- end
59
- end
60
-
61
-
62
- def test_tabs_tag_should_not_concat_open_close_tabs_when_nil
63
- content = tabs_tag(:builder => NilBoundariesBuilder) do |t|
64
- concat t.single('Single', '#')
65
- end
66
-
67
- assert_dom_equal('<span>Single</span>', content)
68
- end
69
-
70
- def test_tabs_tag_should_not_concat_open_tabs_when_nil
71
- content = tabs_tag(:builder => NilOpenBoundaryBuilder) do |t|
72
- concat t.single('Single', '#')
73
- end
74
-
75
- assert_dom_equal('<span>Single</span><br />', content)
76
- end
77
-
78
- def test_tabs_tag_should_not_concat_close_tabs_when_nil
79
- content = tabs_tag(:builder => NilCloseBoundaryBuilder) do |t|
80
- concat t.single('Single', '#')
81
- end
82
-
83
- assert_dom_equal('<br /><span>Single</span>', content)
84
- end
85
-
86
- end
@@ -1,99 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ControllerMixinWithControllerTest < ActionController::TestCase
4
- include ControllerTestHelpers
5
-
6
- class MixinController < ActionController::Base
7
- def self.controller_name; "mixin"; end
8
- def self.controller_path; "mixin"; end
9
-
10
- layout false
11
-
12
- set_tab :dashboard
13
- set_tab :welcome, :only => %w(action_welcome)
14
- set_tab :dashboard, :only => %w(action_namespace)
15
- set_tab :homepage, :namespace, :only => %w(action_namespace)
16
-
17
- def method_missing(method, *args)
18
- if method =~ /^action_(.*)/
19
- render :action => (params[:template] || 'default')
20
- end
21
- end
22
-
23
- def rescue_action(e) raise end
24
- end
25
-
26
- MixinController.view_paths = [ File.dirname(__FILE__) + "/fixtures/" ]
27
-
28
- def setup
29
- @controller = MixinController.new
30
- @controller_proxy = ControllerProxy.new(@controller)
31
- @request = ActionController::TestRequest.new
32
- @response = ActionController::TestResponse.new
33
- end
34
-
35
-
36
- def test_render_default
37
- get :action_dashboard
38
- assert_equal(%Q{<ul>
39
- <li><span>Dashboard</span></li>
40
- <li><a href="/w">Welcome</a></li>
41
- </ul>}, @response.body)
42
- end
43
-
44
- def test_render_with_open_close_tabs
45
- get :action_dashboard, :template => "with_open_close_tabs"
46
- assert_equal(%Q{<ul id="tabs">
47
- <li><span>Dashboard</span></li>
48
- <li><a href="/w">Welcome</a></li>
49
- </ul>}, @response.body)
50
- end
51
-
52
-
53
- def test_set_tab
54
- get :action_dashboard
55
- assert_equal(:dashboard, controller.current_tab)
56
- assert_equal(:dashboard, controller.current_tab(:default))
57
- assert_equal(%Q{<ul>
58
- <li><span>Dashboard</span></li>
59
- <li><a href="/w">Welcome</a></li>
60
- </ul>}, @response.body)
61
- end
62
-
63
- def test_set_tab_with_only_option
64
- get :action_welcome
65
- assert_equal(:welcome, controller.current_tab)
66
- assert_equal(:welcome, controller.current_tab(:default))
67
- assert_equal(%Q{<ul>
68
- <li><a href="/d">Dashboard</a></li>
69
- <li><span>Welcome</span></li>
70
- </ul>}, @response.body)
71
- end
72
-
73
- def test_set_tab_with_namespace
74
- get :action_namespace
75
- assert_equal(:dashboard, controller.current_tab)
76
- assert_equal(:dashboard, controller.current_tab(:default))
77
- assert_equal(:homepage, controller.current_tab(:namespace))
78
- assert_equal(%Q{<ul>
79
- <li><span>Dashboard</span></li>
80
- <li><a href="/w">Welcome</a></li>
81
- </ul>}, @response.body)
82
- end
83
-
84
-
85
- def test_current_tab
86
- get :action_dashboard
87
- assert_equal :dashboard, controller.current_tab
88
- assert_equal :dashboard, controller.current_tab(:default)
89
- end
90
-
91
- def test_current_tab_question
92
- get :action_dashboard
93
- assert controller.current_tab?(:dashboard)
94
- assert controller.current_tab?(:dashboard, :default)
95
- assert !controller.current_tab?(:foobar)
96
- assert !controller.current_tab?(:foobar, :default)
97
- end
98
-
99
- end
data/uninstall.rb DELETED
@@ -1 +0,0 @@
1
- # Uninstall hook code here