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

128 lines
3.0 KiB
Ruby
Raw Normal View History

2014-07-27 01:50:22 +02:00
require 'test_helper'
2017-11-11 12:44:09 +01:00
# Organisations life cycle tests
class OrgasControllerTest < ActionDispatch::IntegrationTest
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
2017-11-11 12:44:09 +01:00
get orgas_url, params: {
orga: {
region: regions(:region_one)
}
}
2014-07-27 01:50:22 +02:00
assert_response :success
end
test 'should get new' do
2017-11-11 12:44:09 +01:00
get new_orga_url
assert_response :success
end
2020-01-01 22:44:07 +01:00
test 'should preview orga creation' do
assert_no_difference 'Orga.count' do
post preview_orgas_url, params: { orga: {
kind_id: @orga.kind_id, name: @orga.name,
city: @orga.city, region_id: @orga.region.id,
description: @orga.description,
url: @orga.url, contact: @orga.contact, tag_list: 'helo world'
} }
assert_empty assigns(:orga).errors
end
assert_response :success
end
test 'should create orga' do
assert_difference 'Orga.count' do
2020-01-01 22:44:07 +01:00
post orgas_url, params: { orga: {
kind_id: @orga.kind_id, name: @orga.name,
city: @orga.city, region_id: @orga.region.id,
description: @orga.description,
url: @orga.url, feed: @orga.feed,
contact: @orga.contact, submitter: @orga.contact
} }
end
assert_redirected_to assigns(:orga)
end
test 'should create minimalist orga' do
assert_difference 'Orga.count' do
2020-01-01 22:44:07 +01:00
post orgas_url, params: { orga: {
kind_id: @orga.kind_id,
name: @orga.name,
region_id: @orga.region.id,
description: @orga.description,
url: @orga.url
} }
end
assert_redirected_to assigns(:orga)
end
test 'should create orga without content' do
assert_difference 'Orga.count' do
2020-01-01 22:44:07 +01:00
post orgas_url, params: { orga: {
kind_id: @orga.kind_id,
name: @orga.name,
region_id: @orga.region.id,
url: @orga.url
} }
end
assert_redirected_to assigns(:orga)
end
test 'should not create orga' do
assert_no_difference 'Orga.count' do
2017-11-11 12:44:09 +01:00
post orgas_url, params: {
orga: { url: @orga.url }
}
end
end
test 'should get show' do
2017-11-11 12:44:09 +01:00
get orga_url(@orga.id)
2014-07-27 01:50:22 +02:00
assert_response :success
end
2015-05-25 11:42:53 +02:00
2020-01-01 22:44:07 +01:00
test 'should preview' do
assert_no_difference 'Orga.count' do
patch preview_orga_url(@orga), params: {
secret: @orga.secret, orga: { name: @orga.name }
}
assert_empty assigns(:orga).errors
end
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 name: 'My Title'
2017-11-11 12:44:09 +01:00
patch orga_url(@orga), params: {
secret: @orga.secret,
orga: { name: @orga.name }
}
2015-05-25 11:42:53 +02:00
2017-11-11 12:44:09 +01:00
assert_redirected_to orga_url(@orga)
2015-05-25 11:42:53 +02:00
end
test 'should not update orga' do
2020-01-01 22:44:07 +01:00
patch orga_url(@orga), params: { orga: { name: nil } }
2015-05-25 11:42:53 +02:00
2017-11-11 12:44:09 +01:00
assert_redirected_to :new_user_session
2015-05-25 11:42:53 +02:00
end
test 'should not update orga without proper secret' do
2020-01-01 22:44:07 +01:00
patch orga_url(@orga), params: { orga: { name: 'hello world' } }
2015-05-25 11:42:53 +02:00
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