Skip to content

Commit

Permalink
Merge pull request #1743 from jdalphon/testing
Browse files Browse the repository at this point in the history
Increasing test coverage
  • Loading branch information
NatTuck committed Aug 20, 2014
2 parents f94b3ae + 991bea1 commit 7d56fd2
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 82 deletions.
22 changes: 0 additions & 22 deletions app/helpers/media_objects_helper.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,4 @@
module MediaObjectsHelper
def media_object_edit_menu_helper(make_link = false)
url = case
when !@media_object.data_set_id.nil?
project_url @media_object.project
when !@media_object.visualization.nil?
visualization_url @media_object.visualization
when !@media_object.tutorial.nil?
tutorial_url @media_object.tutorial
when !@media_object.news_id.nil?
news_url @media_object.news
when !@media_object.user_id.nil?
user_url @media_object.owner
when !@media_object.project_id.nil?
project_url @media_object.data_set.project
else
'/'
end

render 'shared/edit_menu', type: 'media_object', typeName: 'Media Object',
obj: @media_object, make_link: make_link, escape_link: url
end

def media_object_thumbnail_helper(mo, size = nil, download = false)
if size.nil?
img_size = '32x32'
Expand Down
7 changes: 0 additions & 7 deletions app/helpers/news_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
module NewsHelper
def news_edit_menu_helper(make_link = false)
render 'shared/edit_menu', type: 'news', typeName: 'News', obj: @news, make_link: make_link, escape_link: '/news'
end

def news_edit_helper(field, can_edit = false, make_link = true, url = '#')
render 'shared/edit_info', type: 'news', field: field, value: @news[field], row_id: @news.id, can_edit: can_edit, make_link: make_link, href: url
end
end
9 changes: 0 additions & 9 deletions app/helpers/tutorials_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
module TutorialsHelper
def tutorial_edit_menu_helper(make_link = false)
render 'shared/edit_menu', type: 'tutorial', typeName: 'Tutorial', obj: @tutorial,
make_link: make_link, escape_link: tutorials_url
end

def tutorial_edit_helper(field, can_edit = false, make_link = true, url = '#')
render 'shared/edit_info', type: 'tutorial', field: field, value: @tutorial[field],
row_id: @tutorial.id, can_edit: can_edit, make_link: make_link, href: url
end
end
11 changes: 0 additions & 11 deletions app/helpers/visualizations_helper.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
module VisualizationsHelper
def visualization_edit_menu_helper(make_link = false)
render 'shared/edit_menu', type: 'visualization', typeName: 'Visualization', obj: @visualization,
make_link: make_link, escape_link: visualizations_url
end

def visualization_edit_helper(field, can_edit = false, make_link = true, url = '#')
render 'shared/edit_info', type: 'visualization', field: field, value: @visualization[field],
row_id: @visualization.id, can_edit: can_edit, make_link: make_link, href: url
end

def visualization_content_helper(can_edit = false)
render 'shared/newcontent', type: 'visualization', field: 'content',
content: @visualization.content, row_id: @visualization.id,
has_content: !@visualization.content.blank?, can_edit: can_edit
end
end
50 changes: 35 additions & 15 deletions test/fixtures/news.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,49 @@
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one:
title: I'm a news guy
content: I am content for news
summary: This contains content
hidden: false

unpublished_news:
title: Unpublished News
content: Some content
hidden: true
user: nixon
id: 2

# column: value
#
#two: {}
# column: value
rename_this_news:
title: To be renamed
content: Some content
hidden: false
user: nixon

delete_this_news:
title: To be deleted
content: Some content
hidden: false
user: nixon

update_this_news:
title: To be updated
content: Some ontent
hidden: false
user: nixon

media_test:
title: I'm another news guy media
content: I am content for news
title: To get media
content: Some content
summary: This contains content
hidden: false
user: nixon

news_three:
title: I'm another news guy
content: I am content for news
title: Functional test 3
content: Some content
summary: This contains content
hidden: false
user: nixon

one:
title: Functional test 1
content: Some content
summary: This contains content
hidden: false
user: nixon
id: 2
84 changes: 66 additions & 18 deletions test/integration/post_news_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
class PostNewsTest < ActionDispatch::IntegrationTest
include CapyHelper

self.use_transactional_fixtures = false

setup do
@unpublished = news(:unpublished_news)
@to_rename = news(:rename_this_news)
@to_delete = news(:delete_this_news)
@to_update = news(:update_this_news)
Capybara.current_driver = :webkit
Capybara.default_wait_time = 15
end
Expand All @@ -14,38 +20,80 @@ class PostNewsTest < ActionDispatch::IntegrationTest

test 'add a news item' do
login('[email protected]', '12345')
assert find('.navbar').has_content?('Richard N.')

click_on 'News'
assert page.has_no_content?('The Quick Brown Fox')

find('#news_title').set('The Quick Green Fox')
assert page.has_no_content?('New news item #1'), 'News item should not exist'

find('#news_title').set('New news item #1')
click_on 'Add News Item'
assert page.has_content?('News entry was successfully created.')
assert page.has_content?('The Quick Green Fox')

find('.menu_edit_link').click
click_on('Edit Title')
find('#news_title').set('The Quick Brown Fox')
all('.btn-success').first.click

sleep 1
logout
visit '/'
login('[email protected]', '12345')
click_on 'News'
assert page.has_no_content?('New news item #1'), 'News was not published, should not be shown.'

find('#hide_news_checkbox').click
end

sleep 1
test 'publish news' do
login('[email protected]', '12345')
click_on 'News'
assert page.has_no_content?('Unpublished News'), 'News was not published, should not be shown.'

visit '/news'
logout
visit '/'
login('[email protected]', '12345')
visit news_path(@unpublished)
assert page.has_content?('Unpublished News'), 'Not on the news page'

assert page.has_content?('The Quick Brown Fox'), 'News Was Added'
find('#hide_news_checkbox').click
sleep 1

logout

visit '/'
login('[email protected]', '12345')
click_on 'News'
assert page.has_content?('Unpublished News'), 'News was published, should be shown.'
end

test 'rename news' do
login('[email protected]', '12345')
visit news_path(@to_rename)
assert page.has_content?('To be renamed'), 'Not on the right page'

find('.menu_edit_link').click
find('.menu_rename').click
find('#news_title').set 'Changed'
find('.fa-floppy-o').click

assert page.has_content?('News was successfully updated.'), 'Failed to update title'
assert page.has_content?('Changed'), 'Title should be changed'
end

test 'delete news' do
login('[email protected]', '12345')
visit news_path(@to_delete)
assert page.has_content?('To be deleted'), 'Not on the right page'

find('.menu_edit_link').click
find('.menu_delete').click
page.driver.browser.accept_js_confirms

assert page.has_no_content?('To be deleted'), 'News was not deleted'
end

test 'add summary to news' do
login('[email protected]', '12345')
visit news_path(@to_update)
assert page.has_content?('To be updated'), 'Not on the right page'

find('.menu_edit_link').click
find('.summary_edit').click
find('#news_summary').set 'Updated to have a summary'
find('.fa-floppy-o').click

assert page.has_no_content?('Add News Item')
assert page.has_content?('The Quick Brown Fox')
assert page.has_content?('News was successfully updated.'), 'Failed to update summary'
assert page.has_content?('Updated to have a summary'), 'Title should be changed'
end
end

0 comments on commit 7d56fd2

Please sign in to comment.