forked from railsbridge/bridge_troll
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f275207
commit de10660
Showing
9 changed files
with
166 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
class Chapter < ActiveRecord::Base | ||
PERMITTED_ATTRIBUTES = [:name, :organization_id] | ||
|
||
belongs_to :organization | ||
has_many :events | ||
has_many :external_events | ||
|
||
validates_presence_of :organization | ||
|
||
def destroyable? | ||
(events_count + external_events_count) == 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div class="row"> | ||
<div class="col-md-6"> | ||
<%= simple_form_for(@chapter) do |f| %> | ||
<%= render 'shared/model_error_messages', model: @chapter %> | ||
|
||
<div class="form-group"> | ||
<%= f.label :organization_id %> | ||
<%= f.collection_select(:organization_id, Organization.order(:name), :id, :name, {prompt: true}, {class: 'form-control'}) %> | ||
</div> | ||
|
||
<%= f.input :name %> | ||
|
||
<div class="actions"> | ||
<%= f.submit class: 'btn btn-submit', data: {disable_with: 'Please wait...'} %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<%= content_for(:header_text, "Editing chapter") %> | ||
<%= render 'form' %> | ||
<%= render 'shared/actions', links: [ | ||
['Show', @chapter], | ||
['Back', chapters_path] | ||
] %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<%= content_for(:header_text, 'New chapter') %> | ||
<%= render 'form' %> | ||
<%= render 'shared/actions', links: [ | ||
['Back', chapters_path] | ||
] %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require 'rails_helper' | ||
|
||
describe ChaptersController do | ||
let(:organization) { create(:organization, name: 'SpaceBridge') } | ||
let(:user) { create(:user, admin: true) } | ||
|
||
before do | ||
sign_in user | ||
end | ||
|
||
describe '#index' do | ||
let!(:chapter) { create(:chapter) } | ||
|
||
it 'shows all the chapters' do | ||
get :index | ||
expect(assigns(:chapters)).to match_array([chapter]) | ||
end | ||
end | ||
|
||
describe '#new' do | ||
it 'shows an empty chapter' do | ||
get :new | ||
expect(response).to be_success | ||
end | ||
end | ||
|
||
describe '#create' do | ||
it 'creates a new chapter' do | ||
expect { | ||
post :create, chapter: {name: "Fabulous Chapter", organization_id: organization.id} | ||
}.to change(Chapter, :count).by(1) | ||
end | ||
end | ||
|
||
describe '#edit' do | ||
let!(:chapter) { create(:chapter) } | ||
|
||
it "shows a chapter edit form" do | ||
get :edit, id: chapter.id | ||
expect(response).to be_success | ||
end | ||
end | ||
|
||
describe '#update' do | ||
let!(:chapter) { create(:chapter) } | ||
|
||
it "changes chapter details" do | ||
expect { | ||
put :update, id: chapter.id, chapter: {name: 'Sandwich Chapter'} | ||
}.to change { chapter.reload.name } | ||
expect(response).to redirect_to(chapter_path(chapter)) | ||
end | ||
end | ||
|
||
describe "#destroy" do | ||
let!(:chapter) { create(:chapter) } | ||
|
||
it "can delete a chapter that belongs to no events" do | ||
expect { | ||
delete :destroy, {id: chapter.id} | ||
}.to change(Chapter, :count).by(-1) | ||
end | ||
|
||
it "cannot delete a chapter that belongs to a event" do | ||
create(:event, chapter: chapter) | ||
expect { | ||
delete :destroy, {id: chapter.id} | ||
}.not_to change(Chapter, :count) | ||
end | ||
end | ||
end |