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

102 lines
2.1 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
test 'should create orga' do
assert_difference 'Orga.count' do
2017-11-11 12:44:09 +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
2017-11-11 12:44:09 +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 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
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
2017-11-11 12:44:09 +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
2017-11-11 12:44:09 +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