presenting 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/LICENSE +20 -20
  2. data/README +10 -10
  3. data/Rakefile +22 -22
  4. data/app/assets/javascripts/search.js +13 -13
  5. data/app/assets/stylesheets/details-color.css +7 -7
  6. data/app/assets/stylesheets/details.css +10 -10
  7. data/app/assets/stylesheets/form.css +1 -1
  8. data/app/assets/stylesheets/grid-color.css +71 -71
  9. data/app/assets/stylesheets/grid.css +64 -64
  10. data/app/assets/stylesheets/search-color.css +16 -16
  11. data/app/assets/stylesheets/search.css +45 -45
  12. data/app/controllers/presentation/assets_controller.rb +42 -42
  13. data/app/views/presentations/_details.erb +11 -11
  14. data/app/views/presentations/_field_search.erb +14 -14
  15. data/app/views/presentations/_form.erb +20 -20
  16. data/app/views/presentations/_grid.erb +70 -70
  17. data/app/views/presentations/_search.erb +7 -7
  18. data/lib/presentation/base.rb +31 -31
  19. data/lib/presentation/details.rb +21 -21
  20. data/lib/presentation/field_search.rb +67 -67
  21. data/lib/presentation/form.rb +149 -149
  22. data/lib/presentation/grid.rb +162 -160
  23. data/lib/presentation/search.rb +9 -9
  24. data/lib/presenting/attribute.rb +51 -51
  25. data/lib/presenting/configurable.rb +10 -10
  26. data/lib/presenting/defaults.rb +10 -10
  27. data/lib/presenting/field_set.rb +26 -26
  28. data/lib/presenting/form_helpers.rb +51 -51
  29. data/lib/presenting/helpers.rb +114 -114
  30. data/lib/presenting/sanitize.rb +19 -19
  31. data/lib/presenting/search.rb +185 -185
  32. data/lib/presenting/sorting.rb +87 -87
  33. data/test/attribute_test.rb +61 -61
  34. data/test/configurable_test.rb +20 -20
  35. data/test/details_test.rb +68 -68
  36. data/test/field_search_test.rb +102 -102
  37. data/test/field_set_test.rb +46 -46
  38. data/test/grid_test.rb +246 -239
  39. data/test/helpers_test.rb +72 -72
  40. data/test/presenting_test.rb +15 -15
  41. data/test/r3/Gemfile +7 -7
  42. data/test/r3/Gemfile.lock +86 -82
  43. data/test/r3/config/application.rb +12 -12
  44. data/test/r3/config/boot.rb +6 -6
  45. data/test/r3/config/database.yml +22 -22
  46. data/test/r3/config/environment.rb +5 -5
  47. data/test/r3/config/environments/test.rb +35 -35
  48. data/test/r3/db/test.sqlite3 +0 -0
  49. data/test/r3/log/test.log +336 -0
  50. data/test/r3/public/javascripts/presenting/grid.js +0 -0
  51. data/test/r3/public/javascripts/presenting/search.js +13 -13
  52. data/test/r3/public/stylesheets/presenting/details-color.css +7 -7
  53. data/test/r3/public/stylesheets/presenting/details.css +10 -10
  54. data/test/r3/public/stylesheets/presenting/form.css +1 -1
  55. data/test/r3/public/stylesheets/presenting/grid-color.css +71 -71
  56. data/test/r3/public/stylesheets/presenting/grid.css +64 -64
  57. data/test/r3/public/stylesheets/presenting/search-color.css +16 -16
  58. data/test/r3/public/stylesheets/presenting/search.css +45 -45
  59. data/test/sanitize_test.rb +15 -15
  60. data/test/search_conditions_test.rb +137 -137
  61. data/test/search_test.rb +30 -30
  62. data/test/sorting_test.rb +63 -63
  63. metadata +74 -74
@@ -1,20 +1,20 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class ConfigurableTest < Presenting::Test
4
- class ConfigurableUser
5
- include Presenting::Configurable
6
- attr_accessor :first_name
7
- attr_reader :name
8
- end
9
-
10
- def test_setting_first_name_with_initializer
11
- user = ConfigurableUser.new(:first_name => "Bob")
12
- assert_equal 'Bob', user.first_name
13
- end
14
-
15
- def test_setting_unsettable_attribute
16
- assert_raises NoMethodError do
17
- ConfigurableUser.new(:name => 'Bob Jenkins')
18
- end
19
- end
20
- end
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ConfigurableTest < Presenting::Test
4
+ class ConfigurableUser
5
+ include Presenting::Configurable
6
+ attr_accessor :first_name
7
+ attr_reader :name
8
+ end
9
+
10
+ def test_setting_first_name_with_initializer
11
+ user = ConfigurableUser.new(:first_name => "Bob")
12
+ assert_equal 'Bob', user.first_name
13
+ end
14
+
15
+ def test_setting_unsettable_attribute
16
+ assert_raises NoMethodError do
17
+ ConfigurableUser.new(:name => 'Bob Jenkins')
18
+ end
19
+ end
20
+ end
data/test/details_test.rb CHANGED
@@ -1,68 +1,68 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class DetailsTest < Presenting::Test
4
- def setup
5
- @d = Presentation::Details.new
6
- end
7
-
8
- def test_adding_a_field_by_name
9
- @d.fields = ["foo"]
10
- assert_equal "foo", @d.fields.first.name, "name is stringified"
11
- assert_equal "foo", @d.fields.first.value, "value is assumed to be a method"
12
- end
13
-
14
- def test_adding_a_field_by_name_and_value
15
- @d.fields = [{"foo" => :bar}]
16
- assert_equal "foo", @d.fields.first.name, "key is name"
17
- assert_equal :bar, @d.fields.first.value, "value is value"
18
- end
19
-
20
- def test_adding_a_field_by_name_and_options
21
- @d.fields = [{"foo" => {:value => :bar}}]
22
- assert_equal "foo", @d.fields.first.name, "key is name"
23
- assert_equal :bar, @d.fields.first.value, "value is found and saved"
24
- end
25
- end
26
-
27
- class DetailsRenderTest < Presentation::RenderTest
28
- def setup
29
- @presentation = Presentation::Details.new
30
- @presentation.presentable = stub('user', :name => 'foo', :email => 'foo@example.com')
31
- @presentation.controller = ActionView::TestCase::TestController.new
32
- end
33
-
34
- def test_rendering_a_title
35
- @presentation.title = 'Hello World'
36
-
37
- assert_select '.presentation-details h3', 'Hello World'
38
- end
39
-
40
- def test_rendering_an_attribute
41
- @presentation.fields = [:email]
42
-
43
- assert_select '.presentation-details' do
44
- assert_select 'dl' do
45
- assert_select 'dt', 'Email'
46
- assert_select 'dd', 'foo@example.com'
47
- end
48
- end
49
- end
50
-
51
- def test_rendering_sanitized_data
52
- @presentation.fields = [
53
- {:email => {:sanitize => false}},
54
- {:name => {:sanitize => true}}
55
- ]
56
- @presentation.presentable = stub('user', :name => '&', :email => '&')
57
-
58
- assert_select '.presentation-details' do
59
- assert_select 'dl' do
60
- assert_select 'dt:nth-of-type(1)', 'Email'
61
- assert_select 'dd:nth-of-type(1)', '&'
62
-
63
- assert_select 'dt:nth-of-type(2)', 'Name'
64
- assert_select 'dd:nth-of-type(2)', '&amp;'
65
- end
66
- end
67
- end
68
- end
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class DetailsTest < Presenting::Test
4
+ def setup
5
+ @d = Presentation::Details.new
6
+ end
7
+
8
+ def test_adding_a_field_by_name
9
+ @d.fields = ["foo"]
10
+ assert_equal "foo", @d.fields.first.name, "name is stringified"
11
+ assert_equal "foo", @d.fields.first.value, "value is assumed to be a method"
12
+ end
13
+
14
+ def test_adding_a_field_by_name_and_value
15
+ @d.fields = [{"foo" => :bar}]
16
+ assert_equal "foo", @d.fields.first.name, "key is name"
17
+ assert_equal :bar, @d.fields.first.value, "value is value"
18
+ end
19
+
20
+ def test_adding_a_field_by_name_and_options
21
+ @d.fields = [{"foo" => {:value => :bar}}]
22
+ assert_equal "foo", @d.fields.first.name, "key is name"
23
+ assert_equal :bar, @d.fields.first.value, "value is found and saved"
24
+ end
25
+ end
26
+
27
+ class DetailsRenderTest < Presentation::RenderTest
28
+ def setup
29
+ @presentation = Presentation::Details.new
30
+ @presentation.presentable = stub('user', :name => 'foo', :email => 'foo@example.com')
31
+ @presentation.controller = ActionView::TestCase::TestController.new
32
+ end
33
+
34
+ def test_rendering_a_title
35
+ @presentation.title = 'Hello World'
36
+
37
+ assert_select '.presentation-details h3', 'Hello World'
38
+ end
39
+
40
+ def test_rendering_an_attribute
41
+ @presentation.fields = [:email]
42
+
43
+ assert_select '.presentation-details' do
44
+ assert_select 'dl' do
45
+ assert_select 'dt', 'Email'
46
+ assert_select 'dd', 'foo@example.com'
47
+ end
48
+ end
49
+ end
50
+
51
+ def test_rendering_sanitized_data
52
+ @presentation.fields = [
53
+ {:email => {:sanitize => false}},
54
+ {:name => {:sanitize => true}}
55
+ ]
56
+ @presentation.presentable = stub('user', :name => '&', :email => '&')
57
+
58
+ assert_select '.presentation-details' do
59
+ assert_select 'dl' do
60
+ assert_select 'dt:nth-of-type(1)', 'Email'
61
+ assert_select 'dd:nth-of-type(1)', '&'
62
+
63
+ assert_select 'dt:nth-of-type(2)', 'Name'
64
+ assert_select 'dd:nth-of-type(2)', '&amp;'
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,102 +1,102 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class FieldSearchTest < Presenting::Test
4
- def setup
5
- @s = Presentation::FieldSearch.new
6
- end
7
-
8
- def test_adding_a_field_by_name
9
- @s.fields = [:foo]
10
- assert_equal "Foo", @s.fields.first.name
11
- assert_equal :text, @s.fields.first.type
12
- end
13
-
14
- def test_adding_a_field_by_name_and_type
15
- @s.fields = [{"foo" => :bar}]
16
- assert_equal "foo", @s.fields.first.name
17
- assert_equal :bar, @s.fields.first.type
18
- end
19
-
20
- def test_adding_a_field_by_name_and_options
21
- @s.fields = [{"foo" => {:type => :bar}}]
22
- assert_equal "foo", @s.fields.first.name
23
- assert_equal :bar, @s.fields.first.type
24
- end
25
- end
26
-
27
- class FieldSearchFieldTest < Presenting::Test
28
- def setup
29
- @f = Presentation::FieldSearch::Field.new
30
- end
31
-
32
- def test_assigning_a_symbol_name
33
- @f.name = :foo
34
- assert_equal "Foo", @f.name, "name is typecast to a string and titleized"
35
- end
36
-
37
- def test_assigning_a_string_name
38
- @f.name = "foo"
39
- assert_equal "foo", @f.name, "name remains a string"
40
- end
41
-
42
- def test_default_type
43
- assert_equal :text, @f.type
44
- end
45
- end
46
-
47
- class FieldSearchRenderingTest < Presentation::RenderTest
48
- def setup
49
- @presentation = Presentation::FieldSearch.new
50
- @presentation.controller = ActionView::TestCase::TestController.new
51
- @presentation.controller.request.path = '/users'
52
- end
53
-
54
- def test_rendering_a_form_reuses_current_path
55
- assert_select 'form[action=/users?][method=get]'
56
- end
57
-
58
- def test_rendering_a_text_field
59
- @presentation.fields << {:foo => :text}
60
- assert_select "form input[type=text][name='search[foo][value]']"
61
- end
62
-
63
- def test_rendering_a_text_field_with_existing_value
64
- @presentation.fields << {:foo => :text}
65
- @presentation.controller.params[:search] = {'foo' => {:value => 'bar'}}
66
- assert_select "form input[type=text][name='search[foo][value]'][value=bar]"
67
- end
68
-
69
- def test_rendering_a_checkbox_field
70
- @presentation.fields << {:foo => :checkbox}
71
- assert_select "form input[type=checkbox][name='search[foo][value]'][value=1]"
72
- end
73
-
74
- def test_rendering_a_checkbox_field_with_existing_value
75
- @presentation.fields << {:foo => :checkbox}
76
- @presentation.controller.params[:search] = {'foo' => {:value => '1'}}
77
-
78
- assert_select "form input[type=checkbox][name='search[foo][value]'][value=1][checked=checked]"
79
- end
80
-
81
- def test_rendering_a_dropdown_field_with_existing_value
82
- @presentation.fields << {:foo => {:type => :dropdown, :options => [["Dollar", "$"], ["Kroner", "DKK"]]}}
83
- @presentation.controller.params[:search] = {'foo' => {:value => 'DKK'}}
84
-
85
- assert_select "form select[name='search[foo][value]']" do
86
- assert_select "option[value='$']"
87
- assert_select "option[value='$'][selected='selected']", false
88
- assert_select "option[value='DKK'][selected='selected']"
89
- end
90
- end
91
-
92
- def test_rendering_a_dropdown_field_with_integers_and_existing_value
93
- @presentation.fields << {:foo => {:type => :dropdown, :options => [["Dollar", 1], ["Kroner", 2]]}}
94
- @presentation.controller.params[:search] = {'foo' => {:value => '2'}}
95
-
96
- assert_select "form select[name='search[foo][value]']" do
97
- assert_select "option[value='1']"
98
- assert_select "option[value='1'][selected='selected']", false
99
- assert_select "option[value='2'][selected='selected']"
100
- end
101
- end
102
- end
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class FieldSearchTest < Presenting::Test
4
+ def setup
5
+ @s = Presentation::FieldSearch.new
6
+ end
7
+
8
+ def test_adding_a_field_by_name
9
+ @s.fields = [:foo]
10
+ assert_equal "Foo", @s.fields.first.name
11
+ assert_equal :text, @s.fields.first.type
12
+ end
13
+
14
+ def test_adding_a_field_by_name_and_type
15
+ @s.fields = [{"foo" => :bar}]
16
+ assert_equal "foo", @s.fields.first.name
17
+ assert_equal :bar, @s.fields.first.type
18
+ end
19
+
20
+ def test_adding_a_field_by_name_and_options
21
+ @s.fields = [{"foo" => {:type => :bar}}]
22
+ assert_equal "foo", @s.fields.first.name
23
+ assert_equal :bar, @s.fields.first.type
24
+ end
25
+ end
26
+
27
+ class FieldSearchFieldTest < Presenting::Test
28
+ def setup
29
+ @f = Presentation::FieldSearch::Field.new
30
+ end
31
+
32
+ def test_assigning_a_symbol_name
33
+ @f.name = :foo
34
+ assert_equal "Foo", @f.name, "name is typecast to a string and titleized"
35
+ end
36
+
37
+ def test_assigning_a_string_name
38
+ @f.name = "foo"
39
+ assert_equal "foo", @f.name, "name remains a string"
40
+ end
41
+
42
+ def test_default_type
43
+ assert_equal :text, @f.type
44
+ end
45
+ end
46
+
47
+ class FieldSearchRenderingTest < Presentation::RenderTest
48
+ def setup
49
+ @presentation = Presentation::FieldSearch.new
50
+ @presentation.controller = ActionView::TestCase::TestController.new
51
+ @presentation.controller.request.path = '/users'
52
+ end
53
+
54
+ def test_rendering_a_form_reuses_current_path
55
+ assert_select 'form[action=/users?][method=get]'
56
+ end
57
+
58
+ def test_rendering_a_text_field
59
+ @presentation.fields << {:foo => :text}
60
+ assert_select "form input[type=text][name='search[foo][value]']"
61
+ end
62
+
63
+ def test_rendering_a_text_field_with_existing_value
64
+ @presentation.fields << {:foo => :text}
65
+ @presentation.controller.params[:search] = {'foo' => {:value => 'bar'}}
66
+ assert_select "form input[type=text][name='search[foo][value]'][value=bar]"
67
+ end
68
+
69
+ def test_rendering_a_checkbox_field
70
+ @presentation.fields << {:foo => :checkbox}
71
+ assert_select "form input[type=checkbox][name='search[foo][value]'][value=1]"
72
+ end
73
+
74
+ def test_rendering_a_checkbox_field_with_existing_value
75
+ @presentation.fields << {:foo => :checkbox}
76
+ @presentation.controller.params[:search] = {'foo' => {:value => '1'}}
77
+
78
+ assert_select "form input[type=checkbox][name='search[foo][value]'][value=1][checked=checked]"
79
+ end
80
+
81
+ def test_rendering_a_dropdown_field_with_existing_value
82
+ @presentation.fields << {:foo => {:type => :dropdown, :options => [["Dollar", "$"], ["Kroner", "DKK"]]}}
83
+ @presentation.controller.params[:search] = {'foo' => {:value => 'DKK'}}
84
+
85
+ assert_select "form select[name='search[foo][value]']" do
86
+ assert_select "option[value='$']"
87
+ assert_select "option[value='$'][selected='selected']", false
88
+ assert_select "option[value='DKK'][selected='selected']"
89
+ end
90
+ end
91
+
92
+ def test_rendering_a_dropdown_field_with_integers_and_existing_value
93
+ @presentation.fields << {:foo => {:type => :dropdown, :options => [["Dollar", 1], ["Kroner", 2]]}}
94
+ @presentation.controller.params[:search] = {'foo' => {:value => '2'}}
95
+
96
+ assert_select "form select[name='search[foo][value]']" do
97
+ assert_select "option[value='1']"
98
+ assert_select "option[value='1'][selected='selected']", false
99
+ assert_select "option[value='2'][selected='selected']"
100
+ end
101
+ end
102
+ end
@@ -1,46 +1,46 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class FieldSetTest < Presenting::Test
4
- def setup
5
- @set = Presenting::FieldSet.new(Presenting::Attribute, :name, :value)
6
- end
7
-
8
- def test_reading_a_field_by_name
9
- @set << "foo"
10
- assert_equal "foo", @set["foo"].name
11
- end
12
-
13
- def test_pushing_a_field_by_name
14
- @set << "foo"
15
- assert_equal "foo", @set.first.name
16
- end
17
-
18
- def test_pushing_a_field_by_name_and_value
19
- @set << {"foo" => :bar}
20
- assert_equal "foo", @set.first.name
21
- assert_equal :bar, @set.first.value
22
- end
23
-
24
- def test_pushing_a_field_by_name_and_options
25
- @set << {"foo" => {:value => :bar}}
26
- assert_equal "foo", @set.first.name
27
- assert_equal :bar, @set.first.value
28
- end
29
-
30
- def test_adding_a_field_by_name
31
- @set["foo"] = nil
32
- assert_equal "foo", @set.first.name
33
- end
34
-
35
- def test_adding_a_field_by_name_and_value
36
- @set["foo"] = :bar
37
- assert_equal "foo", @set.first.name
38
- assert_equal :bar, @set.first.value
39
- end
40
-
41
- def test_adding_a_field_by_name_and_options
42
- @set["foo"] = {:value => :bar}
43
- assert_equal "foo", @set.first.name
44
- assert_equal :bar, @set.first.value
45
- end
46
- end
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class FieldSetTest < Presenting::Test
4
+ def setup
5
+ @set = Presenting::FieldSet.new(Presenting::Attribute, :name, :value)
6
+ end
7
+
8
+ def test_reading_a_field_by_name
9
+ @set << "foo"
10
+ assert_equal "foo", @set["foo"].name
11
+ end
12
+
13
+ def test_pushing_a_field_by_name
14
+ @set << "foo"
15
+ assert_equal "foo", @set.first.name
16
+ end
17
+
18
+ def test_pushing_a_field_by_name_and_value
19
+ @set << {"foo" => :bar}
20
+ assert_equal "foo", @set.first.name
21
+ assert_equal :bar, @set.first.value
22
+ end
23
+
24
+ def test_pushing_a_field_by_name_and_options
25
+ @set << {"foo" => {:value => :bar}}
26
+ assert_equal "foo", @set.first.name
27
+ assert_equal :bar, @set.first.value
28
+ end
29
+
30
+ def test_adding_a_field_by_name
31
+ @set["foo"] = nil
32
+ assert_equal "foo", @set.first.name
33
+ end
34
+
35
+ def test_adding_a_field_by_name_and_value
36
+ @set["foo"] = :bar
37
+ assert_equal "foo", @set.first.name
38
+ assert_equal :bar, @set.first.value
39
+ end
40
+
41
+ def test_adding_a_field_by_name_and_options
42
+ @set["foo"] = {:value => :bar}
43
+ assert_equal "foo", @set.first.name
44
+ assert_equal :bar, @set.first.value
45
+ end
46
+ end