Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: cainlevy/presenting
base: da9993fe37
...
head fork: cainlevy/presenting
compare: ad1a67f53c
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
View
2  Rakefile
@@ -1,6 +1,6 @@
require 'rake'
require 'rake/testtask'
-require 'rake/rdoctask'
+require 'rdoc/task'
desc 'Default: run unit tests.'
task :default => :test
View
36 lib/presentation/grid.rb
@@ -6,13 +6,13 @@ module Presentation
class Grid < Base
# The id for this presentation. Required.
attr_accessor :id
-
+
# The display title for this presentation. Will default based on the id.
attr_writer :title
def title
@title ||= self.id.titleize
end
-
+
# Paradigm Example:
# Grid.new(:fields => [
# :email,
@@ -30,15 +30,15 @@ def fields=(args)
self.fields << field
end
end
-
+
def fields
@fields ||= Presenting::FieldSet.new(Field, :name, :value)
end
-
+
def colspan
@colspan ||= fields.size + (record_links.empty? ? 0 : 1)
end
-
+
def iname; :grid end
class Field < Presenting::Attribute
@@ -59,20 +59,22 @@ class Field < Presenting::Attribute
# Field.new(:sortable => false)
def sortable=(val)
@sort_name = case val
- when TrueClass: self.id
- when FalseClass, NilClass: nil
- else val.to_s
+ when TrueClass, FalseClass, NilClass
+ val
+ else
+ val.to_s
end
end
-
+
# if the field is sortable at all
def sortable?
self.sortable = Presenting::Defaults.grid_is_sortable unless defined? @sort_name
+ self.sortable = self.id if @sort_name == true
!@sort_name.blank?
end
-
+
attr_reader :sort_name
-
+
# is this field sorted in the given request?
def is_sorted?(request)
@is_sorted ||= if sortable? and sorting = request.query_parameters["sort"] and sorting[sort_name]
@@ -81,7 +83,7 @@ def is_sorted?(request)
false
end
end
-
+
# for the view -- modifies the current request such that it would sort this field.
def sorted_url(request)
if current_direction = is_sorted?(request)
@@ -91,7 +93,7 @@ def sorted_url(request)
end
request.path + '?' + request.query_parameters.merge("sort" => {sort_name => next_direction}).to_param
end
-
+
##
## Planned
##
@@ -100,10 +102,10 @@ def sorted_url(request)
# TODO: decorate a Hash object so type is specifiable there as well
# PLAN: type should determine how a field renders. custom types for custom renders. this should be the second option to present().
# attr_accessor :type
-
+
# PLAN: a field's description would appear in the header column, perhaps only visibly in a tooltip
# attr_accessor :description
-
+
# PLAN: any field may be linked. this would happen after :value and :type.
# attr_accessor :link
end
@@ -135,7 +137,7 @@ def links=(set)
def links
@links ||= []
end
-
+
# Like links, except the link will appear for each record. This means that the link must be a block that accepts the
# record as its argument. For example:
#
@@ -152,7 +154,7 @@ def record_links=(set)
def record_links
@record_links ||= []
end
-
+
def paginate?
defined? WillPaginate and (presentable.is_a? WillPaginate::Collection or presentable.respond_to?(:total_entries))
end
View
2  presenting.gemspec
@@ -2,7 +2,7 @@ $LOAD_PATH << File.dirname(__FILE__) + '/lib'
Gem::Specification.new do |s|
s.name = 'presenting'
- s.version = '2.0.0'
+ s.version = '2.0.1'
s.authors = ['Lance Ivy']
s.email = 'lance@cainlevy.net'
s.homepage = 'http://github.com/cainlevy/presenting'
View
59 test/grid_test.rb
@@ -4,7 +4,7 @@ class GridTest < Presenting::Test
def setup
@g = Presentation::Grid.new
end
-
+
def test_default_title
@g.id = "something_or_other"
assert_equal "Something Or Other", @g.title
@@ -15,30 +15,30 @@ def test_adding_a_field_by_name
assert_equal "foo", @g.fields.first.name, "name is stringified"
assert_equal "foo", @g.fields.first.value, "value is assumed to be a method"
end
-
+
def test_adding_a_field_by_name_and_value
@g.fields = [{"foo" => :bar}]
assert_equal "foo", @g.fields.first.name, "key is name"
assert_equal :bar, @g.fields.first.value, "value is value"
end
-
+
def test_adding_a_field_by_name_and_options
@g.fields = [{"foo" => {:value => :bar}}]
assert_equal "foo", @g.fields.first.name, "key is name"
assert_equal :bar, @g.fields.first.value, "value is found and saved"
end
-
+
def test_adding_links_as_strings
@g.links = ['<a href="/foo">foo</a>']
assert_equal 1, @g.links.size
end
-
+
def test_adding_links_as_procs
assert_raises ArgumentError do
@g.links = [proc{|record| link_to(record.name, record)}]
end
end
-
+
def test_adding_record_links_as_procs
@g.record_links = [proc{|record| link_to(record.name, record)}]
assert_equal 1, @g.record_links.size
@@ -51,18 +51,18 @@ def test_adding_nil_record_links
end
assert @g.record_links.empty?
end
-
+
def test_adding_record_links_as_strings
assert_raises ArgumentError do
@g.record_links = ['<a href="/foo">foo</a>']
end
end
-
+
def test_arrays_will_not_paginate
@g.presentable = []
assert !@g.paginate?
end
-
+
def test_paginated_collections_will_paginate
@g.presentable = WillPaginate::Collection.new(1, 1)
assert @g.paginate?
@@ -88,27 +88,34 @@ class GridFieldTest < Presenting::Test
def setup
@f = Presentation::Grid::Field.new
end
-
+
def test_default_sorting_for_field
@f.name = "First Name"
assert @f.sortable?
assert_equal "first_name", @f.sort_name
end
-
+
def test_sortable_field
@f.name = "First Name"
@f.sortable = true
assert @f.sortable?
assert_equal "first_name", @f.sort_name
end
-
+
+ def test_sortable_field_with_delayed_name
+ @f.sortable = true
+ @f.name = 'First Name'
+ assert @f.sortable?
+ assert_equal 'first_name', @f.sort_name
+ end
+
def test_specified_sort_name
@f.name = "First Name"
@f.sortable = "foo"
assert @f.sortable?
assert_equal "foo", @f.sort_name
end
-
+
def test_unsortable_field
@f.sortable = false
assert !@f.sortable?
@@ -127,7 +134,7 @@ def setup
@presentation.controller = ActionView::TestCase::TestController.new
@presentation.controller.params = {:controller => 'users', :action => 'index'} # WillPaginate reuses existing params
end
-
+
def teardown
Rails.application.reload_routes!
end
@@ -135,7 +142,7 @@ def teardown
def test_rendering_the_title
assert_select "#users table caption", 'Users'
end
-
+
def test_rendering_links
@presentation.links = ['<a href="/foo" class="foo">bar</a>'.html_safe]
@@ -143,7 +150,7 @@ def test_rendering_links
assert_select 'li a.foo', 'bar'
end
end
-
+
def test_rendering_record_links
@presentation.record_links = [proc{|r| "<a href='/foo' class='record-link'>#{r.name}</a>".html_safe}]
@@ -174,7 +181,7 @@ def test_rendering_rows
end
end
end
-
+
def test_rendering_no_rows
@presentation.presentable = []
assert_select "#users tbody" do
@@ -187,46 +194,46 @@ def test_rendering_sanitized_data
@presentation.fields['Name'].sanitize = true
@presentation.fields['Email'].sanitize = false
@records << stub('row', :name => '&', :email => '&')
-
+
assert_select "#users tbody tr" do
assert_select 'td.name', '&amp;'
assert_select 'td.email', '&'
end
end
-
+
def test_rendering_sanitized_arrays
@records << stub('row', :name => ['bob', '&', 'lucy'], :email => '')
-
+
assert_select "#users tbody tr" do
assert_select 'td.name' do
assert_select 'ol li:nth-child(2)', '&amp;'
end
end
end
-
+
def test_rendering_with_pagination
@presentation.presentable = WillPaginate::Collection.new(1, 1, 2)
assert_select '#users tfoot .pagination'
end
-
+
def test_rendering_sortable_columns
@presentation.fields.each{|f| f.sortable = true}
-
+
assert_select "#users thead" do
assert_select "th a.sortable", "Name"
assert_select "th a.sortable", "Email"
end
end
-
+
def test_rendering_unsortable_columns
@presentation.fields.each{|f| f.sortable = false}
-
+
assert_select "#users thead" do
assert_select "th", "Name"
assert_select "th", "Email"
end
end
-
+
def test_rendering_a_sorted_column
@presentation.fields.each{|f| f.sortable = true}
@presentation.controller.request.env['QUERY_STRING'] = 'sort[name]=desc'
View
2  test/r3/Gemfile
@@ -1,6 +1,6 @@
source 'http://rubygems.org'
-gem 'rails', '3.0.7'
+gem 'rails', '3.0.10'
gem 'sqlite3'
gem 'presenting', :path => File.dirname(__FILE__) + '/../../'
View
72 test/r3/Gemfile.lock
@@ -1,18 +1,18 @@
PATH
- remote: /home/cainlevy/development/presenting
+ remote: /Users/cainlevy/Code/presenting
specs:
- presenting (2.0.0rc3)
+ presenting (2.0.0)
GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
- actionmailer (3.0.7)
- actionpack (= 3.0.7)
- mail (~> 2.2.15)
- actionpack (3.0.7)
- activemodel (= 3.0.7)
- activesupport (= 3.0.7)
+ actionmailer (3.0.10)
+ actionpack (= 3.0.10)
+ mail (~> 2.2.19)
+ actionpack (3.0.10)
+ activemodel (= 3.0.10)
+ activesupport (= 3.0.10)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.5.0)
@@ -20,56 +20,60 @@ GEM
rack-mount (~> 0.6.14)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
- activemodel (3.0.7)
- activesupport (= 3.0.7)
+ activemodel (3.0.10)
+ activesupport (= 3.0.10)
builder (~> 2.1.2)
i18n (~> 0.5.0)
- activerecord (3.0.7)
- activemodel (= 3.0.7)
- activesupport (= 3.0.7)
- arel (~> 2.0.2)
+ activerecord (3.0.10)
+ activemodel (= 3.0.10)
+ activesupport (= 3.0.10)
+ arel (~> 2.0.10)
tzinfo (~> 0.3.23)
- activeresource (3.0.7)
- activemodel (= 3.0.7)
- activesupport (= 3.0.7)
- activesupport (3.0.7)
+ activeresource (3.0.10)
+ activemodel (= 3.0.10)
+ activesupport (= 3.0.10)
+ activesupport (3.0.10)
arel (2.0.10)
builder (2.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.5.0)
+ json (1.6.1)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
- mime-types (1.16)
- polyglot (0.3.2)
- rack (1.2.3)
+ mime-types (1.17.2)
+ polyglot (0.3.3)
+ rack (1.2.4)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-test (0.5.7)
rack (>= 1.0)
- rails (3.0.7)
- actionmailer (= 3.0.7)
- actionpack (= 3.0.7)
- activerecord (= 3.0.7)
- activeresource (= 3.0.7)
- activesupport (= 3.0.7)
+ rails (3.0.10)
+ actionmailer (= 3.0.10)
+ actionpack (= 3.0.10)
+ activerecord (= 3.0.10)
+ activeresource (= 3.0.10)
+ activesupport (= 3.0.10)
bundler (~> 1.0)
- railties (= 3.0.7)
- railties (3.0.7)
- actionpack (= 3.0.7)
- activesupport (= 3.0.7)
+ railties (= 3.0.10)
+ railties (3.0.10)
+ actionpack (= 3.0.10)
+ activesupport (= 3.0.10)
rake (>= 0.8.7)
+ rdoc (~> 3.4)
thor (~> 0.14.4)
- rake (0.9.2)
+ rake (0.9.2.2)
+ rdoc (3.11)
+ json (~> 1.4)
sqlite3 (1.3.3)
thor (0.14.6)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
- tzinfo (0.3.29)
+ tzinfo (0.3.31)
will_paginate (3.0.0)
PLATFORMS
@@ -77,6 +81,6 @@ PLATFORMS
DEPENDENCIES
presenting!
- rails (= 3.0.7)
+ rails (= 3.0.10)
sqlite3
will_paginate (~> 3.0.0)

No commit comments for this range

Something went wrong with that request. Please try again.