mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
suggested changes
This commit is contained in:
parent
ac85bad9b3
commit
3fb316482c
10 changed files with 176 additions and 110 deletions
|
|
@ -83,6 +83,7 @@ class Ability
|
|||
conference.registration_open? && !conference.registration_limit_exceeded? || conference.program.speakers.confirmed.include?(user)
|
||||
end
|
||||
|
||||
can :index, Organization
|
||||
can :index, Ticket
|
||||
can :manage, TicketPurchase, user_id: user.id
|
||||
can [:new, :create], Payment, user_id: user.id
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class Organization < ActiveRecord::Base
|
||||
has_many :conferences
|
||||
has_many :conferences, dependent: :destroy
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
.page-header
|
||||
%h1 Organizations
|
||||
.btn-group.pull-right
|
||||
= link_to 'Add Organization', new_admin_organization_path, class: 'btn btn-success pull-right'
|
||||
= link_to 'Create Organization', new_admin_organization_path, class: 'btn btn-success pull-right'
|
||||
%p.text-muted
|
||||
Manage organizations in OSEM
|
||||
.row
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ Osem::Application.routes.draw do
|
|||
get '/revision_history/:id/revert_object' => 'versions#revert_object', as: 'revision_history_revert_object'
|
||||
get '/revision_history/:id/revert_attribute' => 'versions#revert_attribute', as: 'revision_history_revert_attribute'
|
||||
end
|
||||
resources :organizations
|
||||
resources :organizations, only: [:index]
|
||||
resources :conferences, only: [:index, :show] do
|
||||
resource :program, only: [] do
|
||||
resources :proposals, except: :destroy do
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
class CreateOrganizations < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :organizations do |t|
|
||||
t.string :name
|
||||
t.string :name, null: false
|
||||
t.text :description
|
||||
t.string :picture
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,14 +8,15 @@ class MoveConferencesToOrganizations < ActiveRecord::Migration
|
|||
end
|
||||
|
||||
def change
|
||||
add_reference :conferences, :organization, index: true
|
||||
add_foreign_key :conferences, :organizations, dependent: :delete
|
||||
add_reference :conferences, :organization, index: true, foreign_key: true
|
||||
|
||||
TempConference.reset_column_information
|
||||
organization = TempOrganization.create(name: 'organization', description: 'Default organization to migrate old conferences to the new version of OSEM')
|
||||
TempConference.all.each do |conference|
|
||||
conference.organization_id = organization.id
|
||||
conference.save!
|
||||
if TempConference.count != 0
|
||||
organization = TempOrganization.create(name: 'organization', description: 'Default organization')
|
||||
TempConference.all.each do |conference|
|
||||
conference.organization_id = organization.id
|
||||
conference.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@ ActiveRecord::Schema.define(version: 20170531094819) do
|
|||
end
|
||||
|
||||
create_table "organizations", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "name", null: false
|
||||
t.text "description"
|
||||
t.string "picture"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,13 +2,170 @@ require 'spec_helper'
|
|||
|
||||
describe Admin::OrganizationsController do
|
||||
let(:admin) { create(:admin) }
|
||||
let(:organization) { create(:organization) }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
describe 'GET #index' do
|
||||
context 'logged in as user with no role' do
|
||||
before :each do
|
||||
sign_in admin
|
||||
get :index
|
||||
sign_in user
|
||||
end
|
||||
|
||||
it { expect(response).to render_template('index') }
|
||||
describe 'GET #new' do
|
||||
before :each do
|
||||
get :new
|
||||
end
|
||||
|
||||
it 'redirects to root' do
|
||||
expect(flash[:alert]).to eq('You are not authorized to access this area!')
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
before :each do
|
||||
get :index
|
||||
end
|
||||
|
||||
it 'redirects to root' do
|
||||
expect(flash[:alert]).to eq('You are not authorized to access this area!')
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
it 'does not create new organization' do
|
||||
expected = expect do
|
||||
post :create, organization: attributes_for(:organization)
|
||||
end
|
||||
expected.to_not change { Organization.count }
|
||||
end
|
||||
|
||||
it 'redirects to root' do
|
||||
post :create, organization: attributes_for(:organization)
|
||||
|
||||
expect(flash[:alert]).to eq('You are not authorized to access this area!')
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH #update' do
|
||||
it 'does not update and redirects to root' do
|
||||
old_name = organization.name
|
||||
patch :update, id: organization.id, organization: attributes_for(:organization, name: 'new name')
|
||||
|
||||
organization.reload
|
||||
expect(organization.name).to eq(old_name)
|
||||
expect(flash[:alert]).to eq('You are not authorized to access this area!')
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
context 'for a valid organization' do
|
||||
it 'does not destroy a resource' do
|
||||
expected = expect do
|
||||
delete :destroy, id: organization.id
|
||||
end
|
||||
expected.to_not change { Organization.count }
|
||||
end
|
||||
|
||||
it 'redirects to root' do
|
||||
delete :destroy, id: organization.id
|
||||
|
||||
expect(flash[:alert]).to eq('You are not authorized to access this area!')
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'logged in as admin' do
|
||||
before :each do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
before do
|
||||
get :new
|
||||
end
|
||||
it { expect(response).to render_template('new') }
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
before do
|
||||
get :index
|
||||
end
|
||||
it { expect(response).to render_template('index') }
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
context 'with valid attributes' do
|
||||
it 'creates new organization' do
|
||||
expected = expect do
|
||||
post :create, organization: attributes_for(:organization)
|
||||
end
|
||||
expected.to change { Organization.count }.by(1)
|
||||
end
|
||||
|
||||
it 'redirects to index' do
|
||||
post :create, organization: attributes_for(:organization)
|
||||
|
||||
expect(flash[:notice]).to eq('Organization successfully created')
|
||||
expect(response).to redirect_to(admin_organizations_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with invalid attributes' do
|
||||
it 'does not create new organization' do
|
||||
expected = expect do
|
||||
post :create, organization: attributes_for(:organization, name: '')
|
||||
end
|
||||
expected.to_not change { Organization.count }
|
||||
end
|
||||
|
||||
it 'redirects to new' do
|
||||
post :create, organization: attributes_for(:organization, name: '')
|
||||
|
||||
expect(flash[:error]).to eq("Name can't be blank")
|
||||
expect(response).to redirect_to(new_admin_organization_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH #update' do
|
||||
it 'saves and redirects to index when the attributes are valid' do
|
||||
patch :update, id: organization.id, organization: attributes_for(:organization, name: 'changed name')
|
||||
|
||||
organization.reload
|
||||
expect(organization.name).to eq('changed name')
|
||||
expect(flash[:notice]).to eq('Organization successfully updated')
|
||||
expect(response).to redirect_to(admin_organizations_path)
|
||||
end
|
||||
|
||||
it 'redirects to edit when attributes are invalid' do
|
||||
patch :update, id: organization.id, organization: attributes_for(:organization, name: '')
|
||||
|
||||
expect(flash[:error]).to eq("Name can't be blank")
|
||||
expect(response).to redirect_to(edit_admin_organization_path(organization))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
context 'for a valid organization' do
|
||||
it 'should successfully destroy a resource' do
|
||||
expected = expect do
|
||||
delete :destroy, id: organization.id
|
||||
end
|
||||
expected.to change { Organization.count }.by(-1)
|
||||
end
|
||||
|
||||
it 'redirects to index' do
|
||||
delete :destroy, id: organization.id
|
||||
|
||||
expect(flash[:notice]).to eq('Organization successfully destroyed')
|
||||
expect(response).to redirect_to(admin_organizations_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,103 +2,14 @@ require 'spec_helper'
|
|||
|
||||
describe OrganizationsController do
|
||||
let!(:organization) { create(:organization) }
|
||||
let!(:admin) { create(:admin, is_admin: true) }
|
||||
|
||||
describe 'GET #new' do
|
||||
before :each do
|
||||
sign_in admin
|
||||
get :new
|
||||
end
|
||||
|
||||
it { expect(response).to render_template('new') }
|
||||
end
|
||||
let!(:user) { create(:user) }
|
||||
|
||||
describe 'GET #index' do
|
||||
before :each do
|
||||
sign_in admin
|
||||
sign_in user
|
||||
get :index
|
||||
end
|
||||
|
||||
it { expect(response).to render_template('index') }
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
before :each do
|
||||
sign_in admin
|
||||
end
|
||||
context 'with valid attributes' do
|
||||
it 'creates new organization' do
|
||||
expected = expect do
|
||||
post :create, organization: attributes_for(:organization)
|
||||
end
|
||||
expected.to change { Organization.count }.by(1)
|
||||
end
|
||||
|
||||
it 'redirects to index' do
|
||||
post :create, organization: attributes_for(:organization)
|
||||
|
||||
expect(flash[:notice]).to eq('Organization successfully created')
|
||||
expect(response).to redirect_to(organizations_path)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with invalid attributes' do
|
||||
it 'does not create new organization' do
|
||||
expected = expect do
|
||||
post :create, organization: attributes_for(:organization, name: '')
|
||||
end
|
||||
expected.to_not change { Organization.count }
|
||||
end
|
||||
|
||||
it 'redirects to new' do
|
||||
post :create, organization: attributes_for(:organization, name: '')
|
||||
|
||||
expect(flash[:error]).to eq("Name can't be blank")
|
||||
expect(response).to redirect_to(new_organization_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH #update' do
|
||||
before :each do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
it 'saves and redirects to index when the attributes are valid' do
|
||||
patch :update, id: organization.id, organization: attributes_for(:organization, name: 'changed name')
|
||||
|
||||
expect(organization.name).to eq('changed name')
|
||||
expect(flash).to eq('Organization successfully updated')
|
||||
expect(response).to redirect_to(organizations_path)
|
||||
end
|
||||
|
||||
it 'redirects to edit when attributes are invalid' do
|
||||
patch :update, id: organization.id, organization: attributes_for(:organization, name: '')
|
||||
|
||||
expect(flash[:error]).to eq("Name can't be blank")
|
||||
expect(response).to redirect_to(edit_organization_path(organization))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
before :each do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
context 'for a valid organization' do
|
||||
it 'should successfully destroy a resource' do
|
||||
expected = expect do
|
||||
delete :destroy, id: organization.id
|
||||
end
|
||||
expected.to change { Organization.count }.by(-1)
|
||||
end
|
||||
|
||||
it 'redirects to index' do
|
||||
delete :destroy, id: organization.id
|
||||
|
||||
expect(flash[:notice]).to eq('Organization successfully destroyed')
|
||||
expect(response).to redirect_to(organizations_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,10 +4,6 @@ describe Organization do
|
|||
let(:organization) { create(:organization) }
|
||||
|
||||
describe 'validation' do
|
||||
it 'has a valid factory' do
|
||||
expect(build(:organization)).to be_valid
|
||||
end
|
||||
|
||||
it 'is not valid without a name' do
|
||||
should validate_presence_of(:name)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue