Skip to content

Commit

Permalink
session/applicants has benn saved character version.
Browse files Browse the repository at this point in the history
  • Loading branch information
sakomoko committed Sep 24, 2012
1 parent 25b316f commit ce426fa
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/controllers/session/applicants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ def new
def create
@applicant = @session.applicants.new params[:session_applicant] do |m|
m.character = current_user.characters.where(world: @world).find(params[:session_applicant][:character_id])
m.version = m.character.version
end
authorize! :create, @applicant
@applicant.save!
@applicant.save
end

def edit
Expand Down
5 changes: 3 additions & 2 deletions app/models/session/applicant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ class Session::Applicant

field :status, type: Symbol, default: :entry
field :comment, type: String
field :version, type: Integer

validates_presence_of :character_id
validates_presence_of :character_id, :version
validates_inclusion_of :status, in: [:entry, :approved]

attr_accessible :comment
attr_accessible :comment, :character_id, :status, as: :admin
attr_accessible :comment, :character_id, :status, :version, as: :admin

scope :approved, where(status: :approved)

Expand Down
2 changes: 1 addition & 1 deletion app/views/sessions/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
%h3#entry-modal-label
= t '.entry-session'
.modal-body
#applicant-error
.modal-footer
%button(class="btn" data-dismiss="modal" aria-hidden="true")Close
%button(id="entry-button" class="btn btn-primary")Entry
Expand Down Expand Up @@ -93,7 +94,6 @@
- else
#applicants.tab-pane
- if !@session.fix_applicant? && can?(:create, @applicant)
#applicant-error
= link_to t('buttons.entry-session'), new_world_session_applicant_path(@session.world, @session), role: "button", class: "btn btn-success btn-block", "data-toggle" => "modal", "data-target" => "#entry-modal"
#applicants-container
= render @session.applicants
Expand Down
4 changes: 4 additions & 0 deletions spec/models/session/applicant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@
describe "fields" do
it { should have_field(:status).of_type(Symbol).with_default_value_of(:entry) }
it { should have_field(:comment).of_type(String) }
it { should have_field(:version).of_type(Integer) }
end

describe "validations" do
it { should validate_presence_of(:character_id) }
it { should validate_presence_of(:version) }
it { should validate_inclusion_of(:status).to_allow([:entry, :approved]) }
end

describe "mass assignments" do
it { should allow_mass_assignment_of :comment }
it { should_not allow_mass_assignment_of(:character_id) }
it { should_not allow_mass_assignment_of(:status) }
it { should_not allow_mass_assignment_of(:version) }

it { should allow_mass_assignment_of(:comment).as(:admin) }
it { should allow_mass_assignment_of(:status).as(:admin) }
it { should allow_mass_assignment_of(:character_id).as(:admin) }
it { should allow_mass_assignment_of(:version).as(:admin) }
end

end

0 comments on commit ce426fa

Please sign in to comment.