sortablecolumns 0.1.6 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/.specification ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sortablecolumns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ platform: ruby
6
+ authors:
7
+ - Bryan Donovan - http://www.bryandonovan.com
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-20 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.3
24
+ version:
25
+ description: Sortable HTML tables for Rails
26
+ email: b.dondo+rubyforge@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ files:
36
+ - History.txt
37
+ - Manifest.txt
38
+ - README.txt
39
+ - Rakefile
40
+ - lib/sortablecolumns.rb
41
+ - lib/sortablecolumns/helpers.rb
42
+ - lib/sortablecolumns/sortablecolumns.rb
43
+ - test/col_def_test_yaml_files/person/dude/dude_report.yml
44
+ - test/col_def_test_yaml_files/person/mysorter.yml
45
+ - test/col_def_test_yaml_files/person/tacosorter.yml
46
+ - test/sortablecolumns_test.rb
47
+ has_rdoc: true
48
+ homepage: http://rubyforge.org/projects/sortablecolumns/
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --main
54
+ - README.txt
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project: sortablecolumns
72
+ rubygems_version: 1.3.5
73
+ signing_key:
74
+ specification_version: 2
75
+ summary: Sortable HTML tables for Rails
76
+ test_files: []
77
+
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bundletest.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'mocha'
8
+ gem 'hpricot'
9
+ gem 'rails', ">=3.0.3"
10
+ gem 'sqlite3-ruby'
11
+ gem 'rcov'
12
+ end
13
+
14
+ # vim: syntax=Ruby
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 3.0.3 / 2011-02-06
2
+ * Compatible with Rails 3 (tested against Rails 3.0.3 in particular)
3
+ * Changing version numbering to match Rails version tested against.
4
+
1
5
  === 0.1.6 / 2009-02-20
2
6
  * Fixed bugs so tests actually pass in Rails 2.2.2. Erroneously tested against 2.1.2 for release 0.1.5.
3
7
 
data/Rakefile CHANGED
@@ -1,26 +1,28 @@
1
1
  # -*- ruby -*-
2
2
 
3
3
  require 'rubygems'
4
- require 'hoe'
4
+ require 'rake/rdoctask'
5
+ require 'rake/testtask'
6
+ require 'rcov'
7
+ require 'rcov/rcovtask'
5
8
  require './lib/sortablecolumns.rb'
6
-
7
- Hoe.new('sortablecolumns', Sortablecolumns::VERSION) do |p|
8
- p.name = "sortablecolumns"
9
- p.author = "Bryan Donovan - http://www.bryandonovan.com"
10
- p.email = "b.dondo+rubyforge@gmail.com"
11
- p.description = "Sortable HTML tables for Rails"
12
- p.summary = "Sortable HTML tables for Rails"
13
- p.url = "http://rubyforge.org/projects/sortablecolumns/"
14
- p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
15
- p.remote_rdoc_dir = '' # Release to root
9
+ require 'bundler'
10
+ Bundler::GemHelper.install_tasks
11
+
12
+ desc "Run unit tests"
13
+ Rake::TestTask.new("test") do |t|
14
+ t.libs << "test"
15
+ t.pattern = 'test/*_test.rb'
16
+ t.verbose = true
16
17
  end
17
18
 
18
- rule '' do |t|
19
- system "cd test && ruby sortablecolumns_test.rb"
19
+ desc "Run unit tests with rcov"
20
+ Rcov::RcovTask.new('rcov') do |t|
21
+ t.test_files = FileList['test/*_test.rb']
22
+ t.ruby_opts << "-Ilib:ext/rcovrt" # in order to use this rcov
23
+ t.verbose = true
20
24
  end
21
25
 
22
- ALLISON = "/opt/local/lib/ruby/gems/1.8/gems/allison-2.0.3/lib/allison.rb"
23
-
24
26
  Rake::RDocTask.new do |rd|
25
27
  rd.main = "README.txt"
26
28
  rd.rdoc_dir = "doc"
@@ -29,11 +31,9 @@ Rake::RDocTask.new do |rd|
29
31
  "History.txt",
30
32
  "Manifest.txt",
31
33
  "lib/**/*.rb")
32
- rd.title = "SortableColumns RDoc"
34
+ rd.title = "Sortablecolumns RDoc"
33
35
 
34
36
  rd.options << '-S' # inline source
35
-
36
- rd.template = ALLISON if File.exist?(ALLISON)
37
37
  end
38
38
 
39
39
  # vim: syntax=Ruby
@@ -47,7 +47,7 @@ module Sortablecolumns
47
47
  if link_ops[:object_url]
48
48
  #link_to failed in the tests in Rails 2.2.2
49
49
  url = send("#{klass.to_s.downcase}_url", obj)
50
- txt = "<a href=\"#{url}\">#{txt}</a>"
50
+ txt = link_to(txt, url)
51
51
  elsif link_ops[:controller] && link_ops[:action]
52
52
  if link_ops[:id] && link_ops[:id] == 'obj_id'
53
53
  link_ops[:id] = obj.id
@@ -60,19 +60,20 @@ module Sortablecolumns
60
60
  # cycle through link_ops, other than controller, action, and id,
61
61
  # and check if the option value is a method for this object. If not,
62
62
  # assign the value directly in the url.
63
- ops = link_ops.reject{|key,val| key == :controller or key == :action or key == :id}
63
+ ops = link_ops.reject{|key,val| key == :controller || key == :action }# || key == :id}
64
64
  ops.each do |key, val|
65
- link_ops[key] = obj.send(val) if obj.respond_to?(val)
65
+ unless key == :id && val == 'obj_id'
66
+ if val.is_a?(String) || val.is_a?(Symbol)
67
+ link_ops[key] = obj.send(val) if val && obj.respond_to?(val.to_sym)
68
+ end
69
+ end
66
70
  end
67
71
  end
68
72
  txt = link_to(txt, link_ops)
69
73
  end
70
74
  elsif link_ops[:url]
71
75
  url = link_ops[:url].gsub(/:id/, obj.id.to_s)
72
- unless url.match(/http/)
73
- url = 'http://' + default_url_options[:host] + url
74
- end
75
- txt = "<a href=\"#{url}\">#{txt}</a>"
76
+ txt = link_to(txt, url)
76
77
  end
77
78
  end
78
79
 
@@ -102,7 +103,7 @@ module Sortablecolumns
102
103
  cols.each do |col|
103
104
  txt << print_col(obj, sorter, col)
104
105
  end
105
- content_tag("tr", txt, options)
106
+ content_tag("tr", txt.html_safe, options)
106
107
  end
107
108
 
108
109
  #Prints table body with content
@@ -121,7 +122,7 @@ module Sortablecolumns
121
122
  txt << print_table_row(obj, sorter, :class => tr_class)
122
123
  i += 1
123
124
  end
124
- content_tag("tbody", txt)
125
+ content_tag("tbody", txt.html_safe)
125
126
  end
126
127
 
127
128
  #Prints single TH tag with content
@@ -133,8 +134,8 @@ module Sortablecolumns
133
134
  sortable = klass.send("#{sorter}_sortable?", col)
134
135
  return content_tag("th", th_txt, :class => th_class) unless sortable
135
136
  url = get_col_heading_url(klass, sorter, col)
136
- #link = link_to(th_txt, url)
137
- link = "<a href=\"#{url}\">#{th_txt}</a>"
137
+ link = link_to(th_txt, url)
138
+ #link = "<a href=\"#{url}\">#{th_txt}</a>"
138
139
  return content_tag("th", link, :class => th_class)
139
140
  end
140
141
 
@@ -174,14 +175,12 @@ module Sortablecolumns
174
175
  cols.each do |col|
175
176
  txt << print_col_heading(klass, sorter, col)
176
177
  end
177
- txt
178
- content_tag("tr", txt, options)
178
+ content_tag("tr", txt.html_safe, options)
179
179
  end
180
180
 
181
181
  #Prints THEAD tags with content
182
182
  def print_table_thead(klass, sorter)
183
183
  content_tag('thead', print_table_heading_row(klass, sorter))
184
184
  end
185
-
186
185
  end
187
186
  end
@@ -5,6 +5,7 @@
5
5
 
6
6
  require 'active_record'
7
7
  require 'active_support'
8
+ require 'active_support/core_ext/hash/keys'
8
9
  require 'action_controller'
9
10
 
10
11
  module ActiveRecord #:nodoc:
@@ -15,7 +16,7 @@ module ActiveRecord #:nodoc:
15
16
  end
16
17
 
17
18
  module ClassMethods
18
- include ActiveSupport::CoreExtensions::Hash::Keys
19
+ #include ActiveSupport::CoreExtensions::Hash::Keys
19
20
 
20
21
  # == Configuration options
21
22
  #
@@ -63,7 +64,7 @@ module ActiveRecord #:nodoc:
63
64
 
64
65
  def self.#{sorter_name}_yaml_path
65
66
  raise "RAILS_ROOT is not defined" unless defined?(RAILS_ROOT)
66
- klass_name = ActiveSupport::Inflector.underscore(self.class_name)
67
+ klass_name = ActiveSupport::Inflector.underscore(self.table_name.classify)
67
68
  file_name = "#{sorter_name}.yml"
68
69
  if sorter_options[:subclass_name]
69
70
  sub_path = File.join(klass_name, ActiveSupport::Inflector.underscore(sorter_options[:subclass_name]), file_name)
@@ -0,0 +1,3 @@
1
+ module Sortablecolumns #:nodoc:
2
+ VERSION = '3.0.3'
3
+ end
@@ -1,6 +1,3 @@
1
- module Sortablecolumns #:nodoc:
2
- VERSION = '0.1.6'
3
- end
4
1
  Dir[File.join(File.dirname(__FILE__), "sortablecolumns/**/*.rb")].sort.each { |lib| require lib }
5
2
  ActiveRecord::Base.send(:include, ActiveRecord::Acts::Sortablecolumns)
6
3
  ActionView::Base.send(:include, Sortablecolumns::Helpers)
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sortablecolumns/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sortablecolumns"
7
+ s.version = Sortablecolumns::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Bryan Donovan"]
10
+ s.email = ["b.dondo+rubyforge@gmail.com"]
11
+ s.homepage = "http://rubyforge.org/projects/sortablecolumns/"
12
+ s.summary = "Sortable HTML tables for Rails"
13
+ s.description = "Sortable HTML tables for Rails"
14
+
15
+ s.rubyforge_project = "sortablecolumns"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- test/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "activerecord", ">=3.0.3"
23
+ s.add_dependency "activesupport", ">=3.0.3"
24
+ s.add_dependency "actionpack", ">=3.0.3"
25
+ end
@@ -1,8 +1,17 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
+ require 'mocha'
4
+ require 'hpricot'
3
5
  $:.unshift File.dirname(__FILE__) + '/../lib'
4
6
  require 'sortablecolumns'
5
- require 'action_controller/integration'
7
+ require 'rails'
8
+ require 'action_dispatch/testing/integration'
9
+ require 'active_record/railtie'
10
+
11
+ module MySorterApp
12
+ class Application < Rails::Application
13
+ end
14
+ end
6
15
 
7
16
  RAILS_ROOT = File.dirname(__FILE__) + '/../'
8
17
 
@@ -11,7 +20,7 @@ RAILS_ROOT = File.dirname(__FILE__) + '/../'
11
20
  #Based on test code for Rails' acts_as_tree
12
21
  #http://dev.rubyonrails.org/svn/rails/plugins/acts_as_tree/test/acts_as_tree_test.rb
13
22
 
14
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
23
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
15
24
 
16
25
  # AR keeps printing annoying schema statements
17
26
  $stdout = StringIO.new
@@ -74,7 +83,6 @@ class Dude < Person
74
83
  def dudename
75
84
  firstname
76
85
  end
77
-
78
86
  end
79
87
 
80
88
  class SubPerson < Person
@@ -85,32 +93,35 @@ end
85
93
  #---------------------------------------------------
86
94
  # Routes
87
95
  #---------------------------------------------------
88
- ActionController::Routing::Routes.draw do |map|
89
- map.person '/people/show/:id',
90
- :controller => 'people',
91
- :action => 'show'
92
- map.people_foods '/people/:person_id/foods',
93
- :controller => 'foods',
94
- :action => 'show'
96
+ MySorterApp::Application.routes.draw do
97
+ # match 'products/:id' => 'catalog#view'
98
+ match 'people/show/:id' => 'people#show', :as => :person
99
+ match 'people/:person_id/foods' => 'foods#show', :as => :people_foods
100
+ #match 'foods/meats/:id' => 'foods#show', :as => :meat
101
+
102
+ #map.people_foods '/people/:person_id/foods',
103
+ #:controller => 'foods',
104
+ #:action => 'show'
95
105
  #simulate the RESTful urls:
96
- map.dude '/dudes/:id',
97
- :controller => 'dudes',
98
- :action => 'show'
106
+ resources :dudes
107
+ #map.dude '/dudes/:id',
108
+ #:controller => 'dudes',
109
+ #:action => 'show'
99
110
 
100
- map.connect '/:controller/:action/:id'
101
-
111
+ match ':controller(/:action(/:id(.:format)))'
102
112
  end
103
113
 
104
114
 
105
115
  #---------------------------------------------------
106
116
  # Tests
107
117
  #---------------------------------------------------
108
- class SortableColumnsTest< Test::Unit::TestCase
118
+ class SortableColumnsTest < Test::Unit::TestCase
109
119
  def setup
110
120
  setup_db
111
121
  @person = Person.create(:firstname => "Billy", :lastname => "Jones", :age => 24,
112
122
  :description => "Billy is an awesome guy.\nHowever, he is also a punk. He loves www.google.com. ")
113
123
  @person.save
124
+ @this_dir = File.expand_path(File.dirname(__FILE__))
114
125
  end
115
126
 
116
127
  def teardown
@@ -122,12 +133,14 @@ class SortableColumnsTest< Test::Unit::TestCase
122
133
  end
123
134
 
124
135
  def test_person_yaml_path
125
- assert_equal "./../test/col_def_test_yaml_files/person/mysorter.yml", Person.mysorter_yaml_path
136
+ expected = File.expand_path(File.join(@this_dir,"col_def_test_yaml_files/person/mysorter.yml"))
137
+ assert_equal expected, File.expand_path(Person.mysorter_yaml_path)
126
138
  end
127
139
 
128
140
  def test_sub_person_yaml_path
129
141
  #test sub-models & models with multi-word names, such as SubPerson
130
- assert_equal "./../test/col_def_test_yaml_files/person/sub_person/cool_sorter_thing.yml", SubPerson.cool_sorter_thing_yaml_path
142
+ expected = File.expand_path(File.join(@this_dir,"col_def_test_yaml_files/person/sub_person/cool_sorter_thing.yml"))
143
+ assert_equal expected, File.expand_path(SubPerson.cool_sorter_thing_yaml_path)
131
144
  end
132
145
 
133
146
  def test_person_mysorter_yaml_load
@@ -152,7 +165,8 @@ class SortableColumnsTest< Test::Unit::TestCase
152
165
  end
153
166
 
154
167
  def test_dude_yaml_path
155
- assert_equal "./../test/col_def_test_yaml_files/person/dude/dude_report.yml", Dude.dude_report_yaml_path
168
+ expected = File.expand_path(File.join(@this_dir,"col_def_test_yaml_files/person/dude/dude_report.yml"))
169
+ assert_equal expected, File.expand_path(Dude.dude_report_yaml_path)
156
170
  end
157
171
 
158
172
  def test_dude_yaml_load
@@ -343,7 +357,6 @@ class SortableColumnsTest< Test::Unit::TestCase
343
357
  assert_equal 'number', Person.default_sorter_datatype('age')
344
358
  assert_equal 'Balance', Person.default_sorter_heading('balance')
345
359
  end
346
-
347
360
  end
348
361
 
349
362
 
@@ -360,9 +373,9 @@ class SortablecolumnsHelperTest < Test::Unit::TestCase
360
373
  include ActionView::Helpers::SanitizeHelper
361
374
  include ActionView::Helpers::TagHelper
362
375
  include ActionView::Helpers::UrlHelper
363
- include ActionController::UrlWriter
364
-
376
+ include Rails.application.routes.url_helpers
365
377
  include Sortablecolumns::Helpers
378
+
366
379
  default_url_options[:host] = 'test.host'
367
380
  attr_accessor :params
368
381
  attr_accessor :request
@@ -382,6 +395,7 @@ class SortablecolumnsHelperTest < Test::Unit::TestCase
382
395
 
383
396
  def setup
384
397
  @view = View.new
398
+ @view.stubs(:controller).returns('people')
385
399
  setup_db
386
400
  @person = Person.create(:firstname => "Billy", :lastname => "Jones",
387
401
  :age => 24, :balance => '1234.5678',
@@ -420,7 +434,17 @@ class SortablecolumnsHelperTest < Test::Unit::TestCase
420
434
  def test_print_col_person_description
421
435
  #should be same as: simple_format(sanitize(auto_link(@person.description)))
422
436
  expected = "<p>Billy is an awesome guy.\n<br />However, he is also a punk. <a href=\"http://www.google.com\">www.google.com</a></p>"
423
- assert_equal "<td class=\"left\">#{expected}</td>", @view.print_col(@person, :mysorter, :description)
437
+ html = @view.print_col(@person, :mysorter, :description)
438
+ doc = Hpricot(html)
439
+ td = doc.at("/td")
440
+ assert_equal 'left', td['class']
441
+ _p = doc.at("/td/p").inner_text
442
+ assert _p.match(/Billy.*\n.*punk/)
443
+ assert_equal 1, doc.search("/td/p/br").size
444
+ link = doc.search("/td/p/a").last
445
+ assert_equal 'http://www.google.com', link['href']
446
+ assert_equal 'www.google.com', link.inner_text
447
+ assert_equal 0, doc.search("/script").size
424
448
  end
425
449
 
426
450
  def test_print_col_dude_description
@@ -438,7 +462,7 @@ class SortablecolumnsHelperTest < Test::Unit::TestCase
438
462
  end
439
463
 
440
464
  def test_print_col_person_firstname
441
- assert_equal "<td class=\"left\"><a href=\"http://test.host/people/show/#{@person.id}\">Billy</a></td>", @view.print_col(@person, :mysorter, :firstname)
465
+ assert_equal "<td class=\"left\"><a href=\"/people/show/#{@person.id}\">Billy</a></td>", @view.print_col(@person, :mysorter, :firstname)
442
466
  end
443
467
 
444
468
  def test_print_col_dude_dudename
@@ -446,7 +470,7 @@ class SortablecolumnsHelperTest < Test::Unit::TestCase
446
470
  end
447
471
 
448
472
  def test_print_col_taco_meat
449
- assert_equal "<td><a href=\"http://test.host/foods/meats/#{@person.id}\">Beef</a></td>", @view.print_col(@person, :tacosorter, :meat)
473
+ assert_equal "<td><a href=\"/foods/meats/#{@person.id}\">Beef</a></td>", @view.print_col(@person, :tacosorter, :meat)
450
474
  end
451
475
 
452
476
  def test_print_col_taco_type
@@ -455,7 +479,7 @@ class SortablecolumnsHelperTest < Test::Unit::TestCase
455
479
 
456
480
  def test_print_col_taco_calories
457
481
  #testing if we can have extra parameters in the url
458
- assert_equal "<td><a href=\"http://test.host/foods/calories?foo=bar\">1200.00</a></td>", @view.print_col(@person, :tacosorter, :calories)
482
+ assert_equal "<td><a href=\"/foods/calories?foo=bar\">1200.00</a></td>", @view.print_col(@person, :tacosorter, :calories)
459
483
  end
460
484
 
461
485
  def test_print_col_dude_print_view
@@ -471,7 +495,7 @@ class SortablecolumnsHelperTest < Test::Unit::TestCase
471
495
  #
472
496
  # Where person_id is a field in the result set (in this test, there's a mock method instead)
473
497
 
474
- expected = "<td><a href=\"http://test.host/dudes/print_view?person_id=23445\">Print</a></td>"
498
+ expected = "<td><a href=\"/dudes/print_view?person_id=23445\">Print</a></td>"
475
499
  assert_equal expected, @view.print_col(@dude, :dude_report, :print_view)
476
500
  end
477
501
 
@@ -491,13 +515,22 @@ class SortablecolumnsHelperTest < Test::Unit::TestCase
491
515
  end
492
516
 
493
517
  def test_print_col_edit
494
- expected = "<td><a href=\"http://test.host/people/edit/#{@person.id}\">Edit</a></td>"
518
+ expected = "<td><a href=\"/people/edit/#{@person.id}\">Edit</a></td>"
495
519
  assert_equal expected, @view.print_col(@person, :mysorter, :edit)
496
520
  end
497
521
 
498
522
  def test_print_col_delete
499
- expected = "<td><a href=\"http://test.host/people/destroy/1\" onclick=\"if (confirm('Are you sure?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);f.submit(); };return false;\">Delete</a></td>"
500
- assert_equal expected, @view.print_col(@person, :mysorter, :delete)
523
+ # Should be something like:
524
+ # <td><a href=\"/people/destroy/1\" data-confirm=\"Are you sure?\" data-method=\"delete\" rel=\"nofollow\">Delete</a></td>
525
+ html = @view.print_col(@person, :mysorter, :delete)
526
+ doc = Hpricot(html)
527
+ assert_equal 1, doc.search("/td").size
528
+ link = doc.at("/td/a")
529
+ assert_equal "/people/destroy/1", link['href']
530
+ assert_equal "Delete", link.inner_text
531
+ ['data-confirm', 'data-method', 'rel'].each do |attr|
532
+ assert_not_nil link[attr]
533
+ end
501
534
  end
502
535
 
503
536
  #---[ Column Headings ]-------------------------------------------------
@@ -511,7 +544,7 @@ class SortablecolumnsHelperTest < Test::Unit::TestCase
511
544
  @view.params[:dir] = 'desc'
512
545
  new_order = 'windshield_strength'
513
546
  new_dir = 'asc'
514
- expected = "http://test.host/cars/wheels?bar=123&dir=asc&foo=blah&order_by=windshield_strength"
547
+ expected = "/cars/wheels?bar=123&dir=asc&foo=blah&order_by=windshield_strength"
515
548
  assert_equal expected, @view.get_url(new_order, new_dir)
516
549
  end
517
550
 
@@ -530,49 +563,52 @@ class SortablecolumnsHelperTest < Test::Unit::TestCase
530
563
  @view.params[:page] = '2'
531
564
  new_order = 'windshield_strength'
532
565
  new_dir = 'asc'
533
- expected = "http://test.host/cars/wheels?bar=123&dir=asc&foo=blah&order_by=windshield_strength"
566
+ expected = "/cars/wheels?bar=123&dir=asc&foo=blah&order_by=windshield_strength"
534
567
  assert_equal expected, @view.get_url(new_order, new_dir)
535
568
  end
536
569
 
537
570
  def test_person_heading_firstname
538
- expected = "<th><a href=\"http://test.host/people?dir=asc&order_by=firstname\">First</a></th>"
571
+ expected = "<th><a href=\"/people?dir=asc&amp;order_by=firstname\">First</a></th>"
539
572
  assert_equal expected, @view.print_col_heading(Person, :mysorter, :firstname)
540
573
 
541
574
  #test if controller changes
575
+ #@view.stubs(:controller).returns('blah')
542
576
  @view.params[:controller] = 'blah'
543
- expected = "<th><a href=\"http://test.host/blah?dir=asc&order_by=firstname\">First</a></th>"
577
+ expected = "<th><a href=\"/blah?dir=asc&amp;order_by=firstname\">First</a></th>"
544
578
  assert_equal expected, @view.print_col_heading(Person, :mysorter, :firstname)
545
579
 
546
580
  #test if action changes
547
581
  @view.params[:action] = 'foo'
548
- expected = "<th><a href=\"http://test.host/blah/foo?dir=asc&order_by=firstname\">First</a></th>"
582
+ expected = "<th><a href=\"/blah/foo?dir=asc&amp;order_by=firstname\">First</a></th>"
549
583
  assert_equal expected, @view.print_col_heading(Person, :mysorter, :firstname)
550
584
 
551
585
  #test if sort direction changes
552
586
  @view = View.new
587
+ @view.stubs(:controller).returns('people')
553
588
  @view.params[:order_by] = 'firstname'
554
589
  @view.params[:dir] = 'asc'
555
590
  #should switch the direction to descending:
556
- expected = "<th><a href=\"http://test.host/people?dir=desc&order_by=firstname\">First</a></th>"
591
+ expected = "<th><a href=\"/people?dir=desc&amp;order_by=firstname\">First</a></th>"
557
592
  assert_equal expected, @view.print_col_heading(Person, :mysorter, :firstname)
558
593
 
559
594
  #test a url route that has more than just controller and action
560
595
  @view = View.new
596
+ @view.stubs(:controller).returns('people')
561
597
  @view.params[:controller] = 'foods'
562
598
  @view.params[:action] = 'show'
563
599
  @view.params[:person_id] = 1
564
- expected = "<th><a href=\"http://test.host/people/1/foods?dir=asc&order_by=firstname\">First</a></th>"
600
+ expected = "<th><a href=\"/people/1/foods?dir=asc&amp;order_by=firstname\">First</a></th>"
565
601
  assert_equal expected, @view.print_col_heading(Person, :mysorter, :firstname)
566
602
  end
567
603
 
568
604
  def test_person_heading_age
569
605
  #default direction should be desc
570
- expected = "<th><a href=\"http://test.host/people?dir=desc&order_by=age\">Age</a></th>"
606
+ expected = "<th><a href=\"/people?dir=desc&amp;order_by=age\">Age</a></th>"
571
607
  assert_equal expected, @view.print_col_heading(Person, :mysorter, :age)
572
608
  @view.params[:order_by] = 'age'
573
609
  @view.params[:dir] = 'desc'
574
610
  #back to asc
575
- expected = "<th><a href=\"http://test.host/people?dir=asc&order_by=age\">Age</a></th>"
611
+ expected = "<th><a href=\"/people?dir=asc&amp;order_by=age\">Age</a></th>"
576
612
  assert_equal expected, @view.print_col_heading(Person, :mysorter, :age)
577
613
  end
578
614
 
@@ -584,7 +620,7 @@ class SortablecolumnsHelperTest < Test::Unit::TestCase
584
620
 
585
621
  def test_taco_heading_meat
586
622
  #test order_by sort_option from col_defs
587
- expected = "<th><a href=\"http://test.host/people?dir=asc&order_by=meats.id\">Meat</a></th>"
623
+ expected = "<th><a href=\"/people?dir=asc&amp;order_by=meats.id\">Meat</a></th>"
588
624
  assert_equal expected, @view.print_col_heading(Person, :tacosorter, :meat)
589
625
  end
590
626
 
@@ -594,42 +630,67 @@ class SortablecolumnsHelperTest < Test::Unit::TestCase
594
630
  end
595
631
 
596
632
  def test_person_print_table_row
597
- assert_equal @expected_person_row, @view.print_table_row(@person, :mysorter)
633
+ html = @view.print_table_row(@person, :mysorter)
634
+ doc = Hpricot(html)
635
+ assert_equal 1, doc.search("/tr").size
636
+ assert_equal 7, doc.search("/tr/td").size
637
+ first_td = doc.at("/tr/td")
638
+ assert_equal 'left', first_td['class']
639
+ assert_equal "/people/show/1", first_td.at("/a")['href']
598
640
  end
599
641
 
600
642
  def test_person_print_table_heading_row
601
- assert_equal @expected_person_heading_row, @view.print_table_heading_row(Person, :mysorter)
643
+ html = @view.print_table_heading_row(Person, :mysorter)
644
+ doc = Hpricot(html)
645
+ assert_equal 1, doc.search("/tr").size
646
+ assert_equal 7, doc.search("/tr/th").size
647
+ first_th = doc.at("/tr/th")
648
+ assert_equal "/people?dir=asc&order_by=firstname", first_th.at("/a")['href']
602
649
  end
603
650
 
604
651
  def test_person_print_table_thead
605
652
  expected = "<thead>#{@expected_person_heading_row}</thead>"
606
- assert_equal expected, @view.print_table_thead(Person, :mysorter)
653
+ html = @view.print_table_thead(Person, :mysorter)
654
+ doc = Hpricot(html)
655
+ assert_equal 1, doc.search("/thead").size
656
+ assert_equal 7, doc.search("/thead/tr/th").size
607
657
  end
608
658
 
659
+
609
660
  def test_person_print_table_body
610
661
  people = [@person, @person2]
611
662
  expected = "<tbody>" + @expected_person_row + @expected_person2_row + "</tbody>"
612
- assert_equal expected, @view.print_table_body(people, :mysorter)
663
+ html = @view.print_table_body(people, :mysorter)
664
+ doc = Hpricot(html)
665
+ assert_equal 2, doc.search("/tbody/tr").size
666
+ assert_equal 14, doc.search("/tbody/tr/td").size
613
667
  end
614
668
 
615
669
  def test_person_print_table
616
670
  people = [@person, @person2]
617
- expected = "<table><thead>#{@expected_person_heading_row}</thead>" +
618
- "<tbody>" + @expected_person_row + @expected_person2_row + "</tbody></table>"
619
- assert_equal expected, @view.print_table(people, :mysorter)
620
-
621
- expected = "<table class=\"yui-skin-sam\" id=\"yui_table\">" +
622
- "<thead>#{@expected_person_heading_row}</thead>" +
623
- "<tbody>" + @expected_person_row + @expected_person2_row + "</tbody></table>"
624
- assert_equal expected, @view.print_table(people, :mysorter,
671
+ html = @view.print_table(people, :mysorter)
672
+ doc = Hpricot(html)
673
+ assert_equal 1, doc.search("/table").size
674
+ assert_equal 2, doc.search("/table/tbody/tr").size
675
+ assert_equal 14, doc.search("/table/tbody/tr/td").size
676
+
677
+ html = @view.print_table(people, :mysorter,
625
678
  {:table => {:class => 'yui-skin-sam', :id => 'yui_table'}})
679
+ doc = Hpricot(html)
680
+ table = doc.at("/table")
681
+ assert_equal 'yui-skin-sam', table['class']
682
+ assert_equal 'yui_table', table['id']
626
683
 
627
- expected = "<table class=\"yui-skin-sam\" id=\"yui_table\">" +
628
- "<thead>#{@expected_person_heading_row}</thead>" +
629
- "<tbody>" + @expected_person_row_alternate + @expected_person2_row_alternate +
630
- "</tbody></table>"
631
- assert_equal expected, @view.print_table(people, :mysorter,
684
+ html = @view.print_table(people, :mysorter,
632
685
  :table => {:class => 'yui-skin-sam', :id => 'yui_table'},
633
686
  :tr => {:classes => ['even','odd']})
687
+ doc = Hpricot(html)
688
+ assert_equal 'yui-skin-sam', table['class']
689
+ assert_equal 'yui_table', table['id']
690
+ rows = doc.search("/table/tbody/tr")
691
+ first_td_row = rows[0]
692
+ assert_equal 'even', first_td_row['class']
693
+ second_td_row = rows[1]
694
+ assert_equal 'odd', second_td_row['class']
634
695
  end
635
696
  end
metadata CHANGED
@@ -1,38 +1,84 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sortablecolumns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ hash: 1
5
+ prerelease:
6
+ segments:
7
+ - 3
8
+ - 0
9
+ - 3
10
+ version: 3.0.3
5
11
  platform: ruby
6
12
  authors:
7
- - Bryan Donovan - http://www.bryandonovan.com
13
+ - Bryan Donovan
8
14
  autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-02-20 00:00:00 -08:00
18
+ date: 2011-02-06 00:00:00 -08:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
- name: hoe
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ name: activerecord
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
23
- version: 1.8.3
24
- version:
29
+ hash: 1
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 3
34
+ version: 3.0.3
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: activesupport
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 1
46
+ segments:
47
+ - 3
48
+ - 0
49
+ - 3
50
+ version: 3.0.3
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: actionpack
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 1
62
+ segments:
63
+ - 3
64
+ - 0
65
+ - 3
66
+ version: 3.0.3
67
+ type: :runtime
68
+ version_requirements: *id003
25
69
  description: Sortable HTML tables for Rails
26
- email: b.dondo+rubyforge@gmail.com
70
+ email:
71
+ - b.dondo+rubyforge@gmail.com
27
72
  executables: []
28
73
 
29
74
  extensions: []
30
75
 
31
- extra_rdoc_files:
32
- - History.txt
33
- - Manifest.txt
34
- - README.txt
76
+ extra_rdoc_files: []
77
+
35
78
  files:
79
+ - .gitignore
80
+ - .specification
81
+ - Gemfile
36
82
  - History.txt
37
83
  - Manifest.txt
38
84
  - README.txt
@@ -40,36 +86,48 @@ files:
40
86
  - lib/sortablecolumns.rb
41
87
  - lib/sortablecolumns/helpers.rb
42
88
  - lib/sortablecolumns/sortablecolumns.rb
89
+ - lib/sortablecolumns/version.rb
90
+ - sortablecolumns.gemspec
43
91
  - test/col_def_test_yaml_files/person/dude/dude_report.yml
44
92
  - test/col_def_test_yaml_files/person/mysorter.yml
45
93
  - test/col_def_test_yaml_files/person/tacosorter.yml
46
94
  - test/sortablecolumns_test.rb
47
95
  has_rdoc: true
48
96
  homepage: http://rubyforge.org/projects/sortablecolumns/
97
+ licenses: []
98
+
49
99
  post_install_message:
50
- rdoc_options:
51
- - --main
52
- - README.txt
100
+ rdoc_options: []
101
+
53
102
  require_paths:
54
103
  - lib
55
104
  required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
56
106
  requirements:
57
107
  - - ">="
58
108
  - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
59
112
  version: "0"
60
- version:
61
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
62
115
  requirements:
63
116
  - - ">="
64
117
  - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
65
121
  version: "0"
66
- version:
67
122
  requirements: []
68
123
 
69
124
  rubyforge_project: sortablecolumns
70
- rubygems_version: 1.3.1
125
+ rubygems_version: 1.4.2
71
126
  signing_key:
72
- specification_version: 2
127
+ specification_version: 3
73
128
  summary: Sortable HTML tables for Rails
74
- test_files: []
75
-
129
+ test_files:
130
+ - test/col_def_test_yaml_files/person/dude/dude_report.yml
131
+ - test/col_def_test_yaml_files/person/mysorter.yml
132
+ - test/col_def_test_yaml_files/person/tacosorter.yml
133
+ - test/sortablecolumns_test.rb