Skip to content

Commit 785b904

Browse files
committed
Make functional tests less whiny. Fix broken test
1 parent 7da4ea5 commit 785b904

File tree

3 files changed

+120
-119
lines changed

3 files changed

+120
-119
lines changed
Lines changed: 117 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,123 @@
11
require 'test_helper'
22

33
module Cms
4-
class HtmlBlocksControllerTest < ActionController::TestCase
5-
include Cms::ControllerTestHelper
6-
7-
def setup
8-
given_a_site_exists
9-
login_as_cms_admin
10-
given_there_is_a_content_type(Cms::HtmlBlock)
11-
@block = create(:html_block, :name => "Test", :content => "I worked.", :publish_on_save => true)
12-
end
13-
14-
def test_new
15-
get :new
16-
assert_response :success
17-
assert_select "h1", "Add New Text"
18-
end
4+
class HtmlBlocksControllerTest < ActionController::TestCase
5+
include Cms::ControllerTestHelper
6+
7+
def setup
8+
given_a_site_exists
9+
login_as_cms_admin
10+
given_there_is_a_content_type(Cms::HtmlBlock)
11+
@block = create(:html_block, :name => "Test", :content => "I worked.", :publish_on_save => true)
12+
end
13+
14+
def test_new
15+
get :new
16+
assert_response :success
17+
assert_select "h1", "Add New Text"
18+
end
19+
20+
def test_add_to_page
21+
@page = create(:page, :path => "/test", :section => root_section)
22+
get :new, :html_block => {:connect_to_page_id => @page.id, :connect_to_container => "test"}
23+
assert_response :success
24+
assert_select "input[name=?][value=?]", "html_block[connect_to_page_id]", @page.id.to_s
25+
assert_select "input[name=?][value=?]", "html_block[connect_to_container]", "test"
26+
end
27+
28+
def test_creating_a_block_that_should_be_connected_to_a_page
29+
@page = create(:page, :path => "/test", :section => root_section)
30+
html_block_count = HtmlBlock.count
31+
32+
post :create, :html_block => FactoryGirl.attributes_for(:html_block).merge(
33+
:connect_to_page_id => @page.id, :connect_to_container => "test")
34+
35+
assert_incremented html_block_count, HtmlBlock.count
36+
assert_equal "test", @page.reload.connectors.first.container
37+
assert_redirected_to @page.path
38+
end
39+
40+
def test_search
41+
get :index, :search => {:term => 'test'}
42+
assert_response :success
43+
assert_select "td", "Test"
44+
45+
get :index, :search => {:term => 'worked', :include_body => true}
46+
assert_response :success
47+
assert_select "td", "Test"
48+
49+
get :index, :search => {:term => 'invalid'}
50+
assert_response :success
51+
assert_select "td", {:count => 0, :text => "Test"}
52+
end
53+
54+
def test_edit
55+
get :edit, :id => @block.id
56+
assert_response :success
57+
assert_select "input[id=?][value=?]", "html_block_name", "Test"
58+
end
59+
60+
61+
def test_update
62+
html_block_count = HtmlBlock.count
63+
html_block_version_count = HtmlBlock::Version.count
64+
65+
put :update, :id => @block.id, :html_block => {:name => "Test V2"}
66+
reset(:block)
67+
68+
assert_redirected_to @block
69+
assert_equal html_block_count, HtmlBlock.count
70+
assert_incremented html_block_version_count, HtmlBlock::Version.count
71+
assert_equal "Test V2", @block.draft.name
72+
assert_equal "Html Block 'Test V2' was updated", flash[:notice]
73+
end
74+
75+
def test_versions
76+
get :versions, :id => @block.id
77+
assert_response :success
78+
assert_equal @block, assigns(:block)
79+
end
80+
81+
def test_revert_to
82+
@block.update_attributes(:name => "Test V2", :publish_on_save => false)
83+
reset(:block)
84+
85+
put :revert_to, :id => @block.id, :version => "1"
86+
reset(:block)
87+
88+
assert_equal 3, @block.draft.version
89+
assert_equal "Test", @block.reload.name
90+
assert_equal "Html Block 'Test' was reverted to version 1", flash[:notice]
91+
assert_redirected_to @block
92+
end
93+
94+
def test_revert_to_with_invalid_version_parameter
95+
@block.update_attributes(:name => "Test V2", :publish_on_save => true)
96+
reset(:block)
97+
98+
html_block_version_count = HtmlBlock::Version.count
99+
100+
put :revert_to, :id => @block.id, :version => 99
101+
reset(:block)
102+
103+
assert_equal html_block_version_count, HtmlBlock::Version.count
104+
assert_equal "Html Block 'Test V2' could not be reverted to version 99", flash[:error]
105+
assert_redirected_to @block
106+
end
107+
108+
def test_usages
109+
@page = create(:page, :section => root_section, :name => "Included")
110+
@page2 = create(:page, :section => root_section, :path => "/other_path", :name => "Excluded")
111+
@block = create(:html_block, :connect_to_page_id => @page.id, :connect_to_container => "main")
112+
@page.publish! # usages are only relevant when page is published
113+
114+
get :usages, :id => @block.id
115+
116+
assert_response :success
117+
assert_select "h1", "Pages Using Text '#{@block.name}'"
118+
assert_select "td.page_name", "Included"
119+
assert_select "td.page_name", {:count => 0, :text => "Excluded"}
120+
end
19121

20-
def test_add_to_page
21-
@page = create(:page, :path => "/test", :section => root_section)
22-
get :new, :html_block => {:connect_to_page_id => @page.id, :connect_to_container => "test"}
23-
assert_response :success
24-
assert_select "input[name=?][value=?]", "html_block[connect_to_page_id]", @page.id.to_s
25-
assert_select "input[name=?][value=?]", "html_block[connect_to_container]", "test"
26-
end
27-
28-
def test_creating_a_block_that_should_be_connected_to_a_page
29-
@page = create(:page, :path => "/test", :section => root_section)
30-
html_block_count = HtmlBlock.count
31-
32-
post :create, :html_block => FactoryGirl.attributes_for(:html_block).merge(
33-
:connect_to_page_id => @page.id, :connect_to_container => "test")
34-
35-
assert_incremented html_block_count, HtmlBlock.count
36-
assert_equal "test", @page.reload.connectors.first.container
37-
assert_redirected_to @page.path
38-
end
39-
40-
def test_search
41-
get :index, :search => {:term => 'test'}
42-
assert_response :success
43-
assert_select "td", "Test"
44-
45-
get :index, :search => {:term => 'worked', :include_body => true }
46-
assert_response :success
47-
assert_select "td", "Test"
48-
49-
get :index, :search => {:term => 'invalid'}
50-
assert_response :success
51-
assert_select "td", {:count=>0, :text=>"Test"}
52-
end
53-
54-
def test_edit
55-
get :edit, :id => @block.id
56-
assert_response :success
57-
assert_select "input[id=?][value=?]", "html_block_name", "Test"
58-
end
59-
60-
61-
def test_update
62-
html_block_count = HtmlBlock.count
63-
html_block_version_count = HtmlBlock::Version.count
64-
65-
put :update, :id => @block.id, :html_block => {:name => "Test V2"}
66-
reset(:block)
67-
68-
assert_redirected_to @block
69-
assert_equal html_block_count, HtmlBlock.count
70-
assert_incremented html_block_version_count, HtmlBlock::Version.count
71-
assert_equal "Test V2", @block.draft.name
72-
assert_equal "Html Block 'Test V2' was updated", flash[:notice]
73-
end
74-
75-
def test_versions
76-
get :versions, :id => @block.id
77-
assert_response :success
78-
assert_equal @block, assigns(:block)
79-
end
80-
81-
def test_revert_to
82-
@block.update_attributes(:name => "Test V2", :publish_on_save =>false)
83-
reset(:block)
84-
85-
put :revert_to, :id => @block.id, :version => "1"
86-
reset(:block)
87-
88-
assert_equal 3, @block.draft.version
89-
assert_equal "Test", @block.reload.name
90-
assert_equal "Html Block 'Test' was reverted to version 1", flash[:notice]
91-
assert_redirected_to @block
92-
end
93-
94-
def test_revert_to_with_invalid_version_parameter
95-
@block.update_attributes(:name => "Test V2", :publish_on_save => true)
96-
reset(:block)
97-
98-
html_block_version_count = HtmlBlock::Version.count
99-
100-
put :revert_to, :id => @block.id, :version => 99
101-
reset(:block)
102-
103-
assert_equal html_block_version_count, HtmlBlock::Version.count
104-
assert_equal "Html Block 'Test V2' could not be reverted to version 99", flash[:error]
105-
assert_redirected_to @block
106-
end
107-
108-
def test_usages
109-
@page = create(:page, :section => root_section, :name => "Included")
110-
@page2 = create(:page, :section => root_section, :path => "/other_path", :name => "Excluded")
111-
@block = create(:html_block, :connect_to_page_id => @page.id, :connect_to_container => "main")
112-
@page.publish! # usages are only relevant when page is published
113-
114-
get :usages, :id => @block.id
115-
116-
assert_response :success
117-
assert_select "h1", "Pages Using Text '#{@block.name}'"
118-
assert_select "td.page_name", "Included"
119-
assert_select "td.page_name", {:count => 0, :text => "Excluded"}
120-
assert_select "h3", "Content Types"
121122
end
122-
123-
end
124123
end

test/test_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
require 'factories/factories'
2424
require 'factories/attachable_factories'
2525

26+
# Silence warnings (hopefully) primarily from HTML parsing in functional tests.
27+
$VERBOSE = nil
28+
2629
require 'support/engine_controller_hacks'
2730

2831
class ActiveSupport::TestCase

todo_ui_Revamp.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Things that need to be updated in the CSS for the new UI.
2121

2222
* Selecting a row in content tables have no visual indicator.
2323
* New button looks bad when you hover over it.
24-
* When viewing a page, the draft button is on the right (rather than left) [Bad Merge?]
2524
* Flash messages still don't look right.
2625
* Select boxes are not styled.
2726
* RTE drop down isn't styled correctly

0 commit comments

Comments
 (0)