viewaide 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,130 @@
1
+ require "test_helper"
2
+
3
+ class NavigationHelperTest < ActiveSupport::TestCase
4
+ include Viewaide::Helpers::NavigationHelper
5
+
6
+ context "tab" do
7
+ should "parse tab options properly" do
8
+ expects(:parse_tab_options).with("test", {:b => 2}).returns({})
9
+ stubs(:link_to)
10
+ stubs(:content_tag)
11
+ stubs(:clean_css_classes)
12
+ tab("test", "/", {:a => 1}, {:b => 2})
13
+ end
14
+
15
+ should "call link_to properly" do
16
+ stubs(:content_tag)
17
+ stubs(:clean_css_classes)
18
+ stubs(:parse_tab_options).returns({})
19
+ expects(:link_to).with("test", "/path", {:a => 1, :b => 2})
20
+ tab("test", "/path", {:a => 1, :b => 2})
21
+ end
22
+
23
+ context "compiling li classes" do
24
+ setup do
25
+ @result_options = { :active => "1",
26
+ :comparison => "2",
27
+ :compare => false,
28
+ :li_classes => "one two three" }
29
+ stubs(:link_to).returns("link_to")
30
+ stubs(:content_tag)
31
+ end
32
+
33
+ should "properly use classes passed in the options" do
34
+ stubs(:parse_tab_options).returns(@result_options)
35
+ expects(:clean_css_classes).with(["one two three", nil])
36
+ tab("test", "/")
37
+ end
38
+
39
+ should "properly compare information" do
40
+ @result_options[:comparison] = "1"
41
+ stubs(:parse_tab_options).returns(@result_options)
42
+ expects(:clean_css_classes).with(["one two three", "active"])
43
+ tab("test", "/")
44
+ end
45
+
46
+ should "properly use compare value" do
47
+ @result_options[:compare] = true
48
+ stubs(:parse_tab_options).returns(@result_options)
49
+ expects(:clean_css_classes).with(["one two three", "active"])
50
+ tab("test", "/")
51
+ end
52
+
53
+ should "not assign class if css_classes is blank" do
54
+ @result_options[:li_classes] = nil
55
+ stubs(:parse_tab_options).returns({})
56
+ stubs(:clean_css_classes).returns("")
57
+ expects(:content_tag).with(:li, "link_to", {})
58
+ tab("test", "/")
59
+ end
60
+ end
61
+
62
+ context "parse_tab_options" do
63
+ context "calculating :active" do
64
+ setup do
65
+ stubs(:controller).returns(stub_everything)
66
+ end
67
+
68
+ should "be based on option" do
69
+ result = send(:parse_tab_options, "name", {:active => "words"})
70
+ assert_equal "words", result[:active]
71
+ end
72
+
73
+ should "be based on name" do
74
+ name = tableized_name = stub
75
+ name.expects(:gsub).with(/\s/, '').returns(tableized_name)
76
+ tableized_name.expects(:tableize).returns("name")
77
+
78
+ result = send(:parse_tab_options, name, {})
79
+ assert_equal "name", result[:active]
80
+ end
81
+ end
82
+
83
+ context "calculating :comparison" do
84
+ should "be based on option" do
85
+ result = send(:parse_tab_options, "name", {:active_compare => "active"})
86
+ assert_equal "active", result[:comparison]
87
+ end
88
+
89
+ should "be based on controller name" do
90
+ controller = stub(:controller_name => "controller-name")
91
+ expects(:controller).returns(controller)
92
+ result = send(:parse_tab_options, "name", {})
93
+ assert_equal "controller-name", result[:comparison]
94
+ end
95
+ end
96
+
97
+ context "calculating :compare" do
98
+ setup do
99
+ stubs(:controller).returns(stub_everything)
100
+ end
101
+
102
+ should "be based on option" do
103
+ result = send(:parse_tab_options, "name", {:compare => true})
104
+ assert_equal true, result[:compare]
105
+ end
106
+
107
+ should "have a default value" do
108
+ result = send(:parse_tab_options, "name")
109
+ assert_equal false, result[:compare]
110
+ end
111
+ end
112
+
113
+ context "calculating :li_classes" do
114
+ setup do
115
+ stubs(:controller).returns(stub_everything)
116
+ end
117
+
118
+ should "be based on option" do
119
+ result = send(:parse_tab_options, "name", {:class => "custom classes"})
120
+ assert_equal "custom classes", result[:li_classes]
121
+ end
122
+
123
+ should "be nil if no option is passed" do
124
+ result = send(:parse_tab_options, "name")
125
+ assert_nil result[:li_classes]
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,47 @@
1
+ require "test_helper"
2
+
3
+ class RjsHelperTest < ActiveSupport::TestCase
4
+ include Viewaide::Helpers::RjsHelper
5
+ include Viewaide::Helpers::MessageHelper
6
+
7
+ context "inline_flash" do
8
+ setup do
9
+ @page = Object.new
10
+ @flash_hash = {:notice => "Test!"}
11
+ self.expects(:messages).with({:notice => "Test!"}).returns("string")
12
+ end
13
+
14
+ context "without keeping flash" do
15
+ setup do
16
+ @flash_hash.expects(:discard).returns(true)
17
+ end
18
+
19
+ should "default to inserting flash within div#flash-container" do
20
+ @page.expects(:insert_html).with(:top, "flash-container", "string")
21
+ inline_flash(@page, @flash_hash)
22
+ end
23
+
24
+ should "allow assignment of container id" do
25
+ @page.expects(:insert_html).with(:top, "my-custom-id", "string")
26
+ inline_flash(@page, @flash_hash, {:container => "my-custom-id"})
27
+ end
28
+
29
+ should "allow replacement of current flash container's HTML" do
30
+ @page.expects(:replace_html).with("flash-container", "string")
31
+ inline_flash(@page, @flash_hash, {:replace => true})
32
+ end
33
+ end
34
+
35
+ context "when keeping flash" do
36
+ setup do
37
+ @flash_hash.expects(:discard).never
38
+ end
39
+
40
+ should "default to inserting flash within div#flash-container" do
41
+ @page.expects(:insert_html).with(:top, "flash-container", "string")
42
+ inline_flash(@page, @flash_hash, :keep_flash => true)
43
+ end
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,54 @@
1
+ require "test_helper"
2
+
3
+ class StructureHelperTest < Viewaide::ViewTestCase
4
+
5
+ context "blockquote" do
6
+
7
+ should "default with the correct structure" do
8
+ show_view "<% blockquote do %>My quoted text<% end %>" do
9
+ assert_select "blockquote", "My quoted text"
10
+ end
11
+ end
12
+
13
+ should "default with the correct structure when an author is set" do
14
+ show_view "<% blockquote :author => 'W. Shakespeare' do %>All the world's a stage<% end %>" do
15
+ assert_select "div.quote-cited" do
16
+ assert_select "blockquote", "All the world's a stage"
17
+ assert_select "cite", "W. Shakespeare"
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ context "body" do
25
+
26
+ should "allow passing a block structure" do
27
+ show_view %(
28
+ <% body do %>body goes here<% end %>
29
+ ) do
30
+ assert_select "body", "body goes here"
31
+ end
32
+ end
33
+
34
+ should "allow passing arguments" do
35
+ show_view %(
36
+ <% body :home, 'home-index', 'logged-in', :id => 'application' do %>body goes here<% end %>
37
+ ) do
38
+ assert_select "body#application.home.home-index.logged-in", "body goes here"
39
+ end
40
+ end
41
+
42
+ should "allow multiple body definitions that set attributes" do
43
+ show_view %(
44
+ <% body :home, 'logged-in' %>
45
+ <% body :id => 'application' %>
46
+ <% body 'home-index', :id => 'application-override' do %>body goes here<% end %>
47
+ ) do
48
+ assert_select "body#application-override.home.home-index.logged-in", "body goes here"
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,112 @@
1
+ require "test_helper"
2
+
3
+ class TableHelperTest < Viewaide::ViewTestCase
4
+
5
+ context "zebra_row" do
6
+
7
+ should "default with the correct structure" do
8
+ show_view "<table><% zebra_row do %>no class<% end %><% zebra_row do %>alt class<% end %></table>" do
9
+ assert_select "tr:first-child", "no class"
10
+ assert_select "tr.alt:last-child", "alt class"
11
+ end
12
+ end
13
+
14
+ should "allow override of the cycle list" do
15
+ show_view %(
16
+ <table>
17
+ <% (colors = %w(red white blue)).each do |color| %>
18
+ <% zebra_row :cycle_list => colors do %>the color <%= color %><% end %>
19
+ <% end %>
20
+ </table>
21
+ ) do
22
+ assert_select "tr.red:first-child", "the color red"
23
+ assert_select "tr.white", "the color white"
24
+ assert_select "tr.blue:last-child", "the color blue"
25
+ end
26
+ end
27
+
28
+ should "allow option assignment" do
29
+ show_view "<% zebra_row :id => 'my-id', :class => 'custom-class' do %>user 1<% end %>" do
30
+ assert_select "tr#my-id.custom-class", "user 1"
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ context "recordset" do
37
+
38
+ should "default with the correct structure" do
39
+ show_view %(<% recordset do %>rows<% end %>) do
40
+ assert_select "table.recordset[cellspacing=0]", "rows"
41
+ end
42
+ end
43
+
44
+ should "allow headers be set" do
45
+ show_view %(<% recordset :headers => ["Header 1", "Header 2", "Header 3"] do %><tbody>rows</tbody><% end %>) do
46
+ assert_select "table.recordset[cellspacing=0]" do
47
+ assert_select "thead" do
48
+ assert_select "tr" do
49
+ assert_select "th.first", "Header 1"
50
+ assert_select "th", "Header 2"
51
+ assert_select "th.last", "Header 3"
52
+ end
53
+ end
54
+ assert_select "tbody", "rows"
55
+ end
56
+ end
57
+ end
58
+
59
+ should "allow headers to have attributes set" do
60
+ show_view %(
61
+ <% recordset :headers => [["Header 1", {:class => "mine", :id => "over"}]] do %>
62
+ <tbody>rows</tbody>
63
+ <% end %>
64
+ ) do
65
+ assert_select "table.recordset[cellspacing=0]" do
66
+ assert_select "thead" do
67
+ assert_select "tr" do
68
+ assert_select "th#over.first.mine", "Header 1"
69
+ end
70
+ end
71
+ assert_select "tbody", "rows"
72
+ end
73
+ end
74
+ end
75
+
76
+ should "allow classes be assigned in a comma-delimited manner" do
77
+ show_view %(<% recordset "my-recordset", "car-list" do %><% end %>) do
78
+ assert_select "table.recordset.my-recordset.car-list[cellspacing=0]"
79
+ end
80
+ end
81
+
82
+ should "allow additional attributes be set on the recordset" do
83
+ show_view %(<% recordset :headers => %w(One Two Three), :table => {:id => "my-id", :class => "my-recordset"} do %><% end %>) do
84
+ assert_select "table#my-id.recordset.my-recordset[cellspacing=0]" do
85
+ assert_select "thead" do
86
+ assert_select "tr" do
87
+ assert_select "th", "One"
88
+ assert_select "th", "Two"
89
+ assert_select "th", "Three"
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ should "reset cycles for zebra_rows" do
97
+ show_view %(
98
+ <% recordset do %>
99
+ <% zebra_row do %>text<% end %>
100
+ <% end %>
101
+ <% recordset do %>
102
+ <% zebra_row do %>text<% end %>
103
+ <% end %>
104
+ ) do
105
+ assert_select "table.recordset" do
106
+ assert_select "tr.alt", 0
107
+ end
108
+ end
109
+
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
4
+ require 'active_support/test_case'
5
+
6
+ require 'shoulda/rails'
7
+ require 'action_controller'
8
+ require 'action_controller/test_process'
9
+
10
+ require "viewaide"
11
+
12
+ ActionView::Base.send :include, Viewaide::Helpers
13
+ ActionController::Base.send :include, Viewaide::PartialCaching
14
+
15
+ class Viewaide::ViewTestCase < ActiveSupport::TestCase
16
+ include ActionController::Assertions::SelectorAssertions
17
+
18
+ def setup
19
+ super
20
+ @view = ActionView::Base.new
21
+ end
22
+
23
+ protected
24
+
25
+ def show_view(template)
26
+ @html_result = ActionView::InlineTemplate.new(template).render(@view, {})
27
+ @html_document = HTML::Document.new(@html_result, true, false)
28
+ yield if block_given?
29
+ end
30
+
31
+ def response_from_page_or_rjs
32
+ @html_document.root
33
+ end
34
+ end
data/viewaide.gemspec ADDED
@@ -0,0 +1,91 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{viewaide}
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Joshua Clayton"]
12
+ s.date = %q{2010-01-09}
13
+ s.description = %q{Making your views easier}
14
+ s.email = %q{joshua.clayton@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.textile"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "Manifest",
22
+ "README.textile",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/viewaide.rb",
26
+ "lib/viewaide/helpers.rb",
27
+ "lib/viewaide/helpers/date_helper.rb",
28
+ "lib/viewaide/helpers/form_helper.rb",
29
+ "lib/viewaide/helpers/grid_helper.rb",
30
+ "lib/viewaide/helpers/jquery_helper.rb",
31
+ "lib/viewaide/helpers/link_helper.rb",
32
+ "lib/viewaide/helpers/message_helper.rb",
33
+ "lib/viewaide/helpers/navigation_helper.rb",
34
+ "lib/viewaide/helpers/rjs_helper.rb",
35
+ "lib/viewaide/helpers/structure_helper.rb",
36
+ "lib/viewaide/helpers/table_helper.rb",
37
+ "lib/viewaide/rails_partial_caching.rb",
38
+ "rails/init.rb",
39
+ "tasks/viewaide_tasks.rake",
40
+ "test/date_helper_test.rb",
41
+ "test/form_helper_test.rb",
42
+ "test/grid_helper_test.rb",
43
+ "test/jquery_helper_test.rb",
44
+ "test/link_helper_test.rb",
45
+ "test/message_helper_test.rb",
46
+ "test/navigation_helper_test.rb",
47
+ "test/rjs_helper_test.rb",
48
+ "test/structure_helper_test.rb",
49
+ "test/table_helper_test.rb",
50
+ "test/test_helper.rb",
51
+ "viewaide.gemspec"
52
+ ]
53
+ s.homepage = %q{http://github.com/joshuaclayton/viewaide}
54
+ s.rdoc_options = ["--charset=UTF-8"]
55
+ s.require_paths = ["lib"]
56
+ s.rubygems_version = %q{1.3.5}
57
+ s.summary = %q{Making your views easier}
58
+ s.test_files = [
59
+ "test/date_helper_test.rb",
60
+ "test/form_helper_test.rb",
61
+ "test/grid_helper_test.rb",
62
+ "test/jquery_helper_test.rb",
63
+ "test/link_helper_test.rb",
64
+ "test/message_helper_test.rb",
65
+ "test/navigation_helper_test.rb",
66
+ "test/rjs_helper_test.rb",
67
+ "test/structure_helper_test.rb",
68
+ "test/table_helper_test.rb",
69
+ "test/test_helper.rb"
70
+ ]
71
+
72
+ if s.respond_to? :specification_version then
73
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
74
+ s.specification_version = 3
75
+
76
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
77
+ s.add_runtime_dependency(%q<actionview>, [">= 2.1.0"])
78
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.1.0"])
79
+ s.add_runtime_dependency(%q<hpricot>, [">= 0.8.1"])
80
+ else
81
+ s.add_dependency(%q<actionview>, [">= 2.1.0"])
82
+ s.add_dependency(%q<activesupport>, [">= 2.1.0"])
83
+ s.add_dependency(%q<hpricot>, [">= 0.8.1"])
84
+ end
85
+ else
86
+ s.add_dependency(%q<actionview>, [">= 2.1.0"])
87
+ s.add_dependency(%q<activesupport>, [">= 2.1.0"])
88
+ s.add_dependency(%q<hpricot>, [">= 0.8.1"])
89
+ end
90
+ end
91
+
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: viewaide
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Clayton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-09 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: actionview
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.1.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hpricot
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.8.1
44
+ version:
45
+ description: Making your views easier
46
+ email: joshua.clayton@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - README.textile
53
+ files:
54
+ - .gitignore
55
+ - MIT-LICENSE
56
+ - Manifest
57
+ - README.textile
58
+ - Rakefile
59
+ - VERSION
60
+ - lib/viewaide.rb
61
+ - lib/viewaide/helpers.rb
62
+ - lib/viewaide/helpers/date_helper.rb
63
+ - lib/viewaide/helpers/form_helper.rb
64
+ - lib/viewaide/helpers/grid_helper.rb
65
+ - lib/viewaide/helpers/jquery_helper.rb
66
+ - lib/viewaide/helpers/link_helper.rb
67
+ - lib/viewaide/helpers/message_helper.rb
68
+ - lib/viewaide/helpers/navigation_helper.rb
69
+ - lib/viewaide/helpers/rjs_helper.rb
70
+ - lib/viewaide/helpers/structure_helper.rb
71
+ - lib/viewaide/helpers/table_helper.rb
72
+ - lib/viewaide/rails_partial_caching.rb
73
+ - rails/init.rb
74
+ - tasks/viewaide_tasks.rake
75
+ - test/date_helper_test.rb
76
+ - test/form_helper_test.rb
77
+ - test/grid_helper_test.rb
78
+ - test/jquery_helper_test.rb
79
+ - test/link_helper_test.rb
80
+ - test/message_helper_test.rb
81
+ - test/navigation_helper_test.rb
82
+ - test/rjs_helper_test.rb
83
+ - test/structure_helper_test.rb
84
+ - test/table_helper_test.rb
85
+ - test/test_helper.rb
86
+ - viewaide.gemspec
87
+ has_rdoc: true
88
+ homepage: http://github.com/joshuaclayton/viewaide
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options:
93
+ - --charset=UTF-8
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ version:
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: "0"
107
+ version:
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.3.5
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Making your views easier
115
+ test_files:
116
+ - test/date_helper_test.rb
117
+ - test/form_helper_test.rb
118
+ - test/grid_helper_test.rb
119
+ - test/jquery_helper_test.rb
120
+ - test/link_helper_test.rb
121
+ - test/message_helper_test.rb
122
+ - test/navigation_helper_test.rb
123
+ - test/rjs_helper_test.rb
124
+ - test/structure_helper_test.rb
125
+ - test/table_helper_test.rb
126
+ - test/test_helper.rb