agenda-libre-ruby/test/controllers/orgas_controller_test.rb

82 lines
1.8 KiB
Ruby
Raw Normal View History

2014-07-27 01:50:22 +02:00
require 'test_helper'
# Free Software groups life cycle
2015-02-15 17:10:17 +01:00
class OrgasControllerTest < ActionController::TestCase
2016-09-19 21:58:50 +02:00
include Devise::Test::ControllerHelpers
2014-07-27 01:50:22 +02:00
setup do
2015-02-15 17:10:17 +01:00
@orga = orgas :one
2014-07-27 01:50:22 +02:00
end
test 'should get index' do
2014-07-27 01:50:22 +02:00
get :index
assert_response :success
end
test 'should get new' do
sign_in users(:one)
get :new
assert_response :success
end
test 'should create orga' do
sign_in users(:one)
assert_difference 'Orga.count' do
post :create, orga: {
kind_id: @orga.kind_id,
name: @orga.name,
city: @orga.city,
region_id: @orga.region.id,
url: @orga.url,
feed: @orga.feed,
contact: @orga.contact,
submitter: @orga.contact,
tags: @orga.tags
}
assert_empty assigns(:orga).errors.messages
end
assert_redirected_to :root
end
test 'should not create orga' do
sign_in users(:one)
assert_no_difference 'Orga.count' do
post :create, orga: { url: @orga.url }
assert_not_empty assigns(:orga).errors.messages
end
end
test 'should get show' do
2015-02-15 17:10:17 +01:00
get :show, id: @orga
2014-07-27 01:50:22 +02:00
assert_response :success
end
2015-05-25 11:42:53 +02:00
test 'should update orga' do
# Necessary to have the proper paper_trail version
@orga.update_attributes name: 'My Title'
2016-02-13 17:24:23 +01:00
patch :update, id: @orga, secret: @orga.secret, orga: { name: @orga.name }
2015-05-25 11:42:53 +02:00
assert_empty assigns(:orga).errors.messages
assert_redirected_to assigns(:orga)
end
test 'should not update orga' do
sign_in users(:one)
patch :update, id: @orga, orga: { name: nil }
assert_not_empty assigns(:orga).errors.messages
end
test 'should not update orga without proper secret' do
2016-02-13 17:24:23 +01:00
patch :update, id: @orga, orga: {
2015-05-25 11:42:53 +02:00
name: 'hello world'
}
2016-02-13 17:24:23 +01:00
assert_redirected_to :new_user_session
2015-05-25 11:42:53 +02:00
end
2014-07-27 01:50:22 +02:00
end