2019-07-12 23:40:44 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SitesControllerTest < ActionDispatch::IntegrationTest
|
|
|
|
setup do
|
|
|
|
@rol = create :rol
|
|
|
|
@site = @rol.site
|
|
|
|
@usuarie = @rol.usuarie
|
|
|
|
|
|
|
|
@authorization = {
|
|
|
|
Authorization: ActionController::HttpAuthentication::Basic
|
|
|
|
.encode_credentials(@usuarie.email, @usuarie.password)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
teardown do
|
|
|
|
@site.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'se pueden ver' do
|
|
|
|
get sites_url, headers: @authorization
|
|
|
|
|
|
|
|
assert_match @site.name, response.body
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'se puede ver el formulario de creación' do
|
|
|
|
get new_site_url, headers: @authorization
|
|
|
|
|
|
|
|
assert_match(/<form.*id="new_site"/, response.body)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'se pueden crear' do
|
|
|
|
name = SecureRandom.hex
|
|
|
|
|
|
|
|
post sites_url, headers: @authorization, params: {
|
|
|
|
site: {
|
2019-07-17 22:18:48 +00:00
|
|
|
name: name,
|
2019-07-19 22:37:53 +00:00
|
|
|
design_id: create(:design).id,
|
2019-07-25 18:51:32 +00:00
|
|
|
licencia_id: create(:licencia).id,
|
|
|
|
deploys_attributes: {
|
|
|
|
'0' => {
|
|
|
|
type: 'DeployLocal'
|
|
|
|
}
|
|
|
|
}
|
2019-07-12 23:40:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-25 18:51:32 +00:00
|
|
|
site = Site.find_by_name(name)
|
|
|
|
|
|
|
|
assert site
|
|
|
|
assert_equal @usuarie.email, site.roles.first.usuarie.email
|
|
|
|
assert_equal 'usuarie', site.roles.first.rol
|
|
|
|
|
|
|
|
site.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'no se pueden crear con cualquier deploy' do
|
|
|
|
name = SecureRandom.hex
|
|
|
|
|
|
|
|
assert_raise ActiveRecord::SubclassNotFound do
|
|
|
|
post sites_url, headers: @authorization, params: {
|
|
|
|
site: {
|
|
|
|
name: name,
|
|
|
|
design_id: create(:design).id,
|
|
|
|
licencia_id: create(:licencia).id,
|
|
|
|
deploys_attributes: {
|
|
|
|
'0' => {
|
|
|
|
type: 'DeployNoExiste'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-12 23:40:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|