-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
29 changed files
with
265 additions
and
14 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
37 changes: 37 additions & 0 deletions
37
app/controllers/web/admin/activity_lines/lider/ya_lider/participations_controller.rb
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,37 @@ | ||
class Web::Admin::ActivityLines::Lider::YaLider::ParticipationsController < Web::Admin::ActivityLines::Lider::YaLider::ApplicationController | ||
before_filter :choose_users, only: [ :new, :edit ] | ||
|
||
def new | ||
@participation_form = ::ActivityLines::Lider::YaLider::ParticipationForm.new_with_model | ||
end | ||
|
||
def create | ||
@participation_form = ::ActivityLines::Lider::YaLider::ParticipationForm.new_with_model | ||
if @participation_form.submit params[:activity_lines_lider_ya_lider_participation] | ||
redirect_to admin_activity_lines_lider_ya_lider_path @participation_form.model.ya_lider | ||
else | ||
choose_users | ||
render action: :new | ||
end | ||
end | ||
|
||
def edit | ||
@participation_form = ::ActivityLines::Lider::YaLider::ParticipationForm.find_with_model params[:id] | ||
end | ||
|
||
def update | ||
@participation_form = ::ActivityLines::Lider::YaLider::ParticipationForm.find_with_model params[:id] | ||
if @participation_form.submit params[:activity_lines_lider_ya_lider_participation] | ||
redirect_to admin_activity_lines_lider_ya_lider_path @participation_form.model.ya_lider | ||
else | ||
choose_users | ||
render action: :edit | ||
end | ||
end | ||
|
||
def destroy | ||
@participation = ::ActivityLines::Lider::YaLider::Participation.find params[:id] | ||
@participation.remove | ||
redirect_to admin_activity_lines_lider_ya_lider_path @participation.ya_lider | ||
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,6 @@ | ||
class ActivityLines::Lider::YaLider::ParticipantForm < ApplicationReform | ||
properties :contest_year, :user_id, :state | ||
|
||
validates :contest_year, presence: true | ||
validates :user_id, presence: true | ||
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 |
---|---|---|
@@ -1,3 +1,20 @@ | ||
class ActivityLines::Lider::YaLider::Participant < ActiveRecord::Base | ||
belongs_to :user | ||
|
||
state_machine :state, initial: :unviewed do | ||
state :unviewed | ||
state :active | ||
state :won | ||
state :lost | ||
state :removed | ||
state :declined | ||
|
||
event :remove do | ||
transition all => :removed | ||
end | ||
|
||
event :restore do | ||
transition removed: :active | ||
end | ||
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
18 changes: 18 additions & 0 deletions
18
app/views/web/admin/activity_lines/lider/ya_lider/participantions/_form.html.haml
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 @@ | ||
- model_class = ActivityLines::Lider::YaLider::Participant | ||
- current_title = page_title(action, model_class.model_name.human) | ||
- title current_title, :admin | ||
.page-header | ||
%h1=t current_title | ||
.row | ||
.col-lg-12 | ||
= render 'layouts/web/admin/shared/messages', object: @participant_form | ||
.row | ||
.col-lg-12 | ||
= simple_form_for [:admin, @participant_form], input_html: { class: 'form-horizontal' } do |f| | ||
= f.button :submit, class: 'btn-success', value: t('helpers.links.save') | ||
-#= link_to t('helpers.links.back'), admin_activity_lines_lider_ya_lider_path(ya_lider_id), class: 'btn btn-default' | ||
= f.input :contest_year, as: :string | ||
= f.input :user_id, as: :select, collection: users_cache_hash(@users), input_html: { class: :select2 }, label: false | ||
= f.input :state_event, as: :state_event | ||
= f.button :submit, class: 'btn-success', value: t('helpers.links.save') | ||
-#= link_to t('helpers.links.back'), admin_activity_lines_lider_ya_lider_path(ya_lider_id), class: 'btn btn-default' |
24 changes: 24 additions & 0 deletions
24
app/views/web/admin/activity_lines/lider/ya_lider/participantions/_list.html.haml
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,24 @@ | ||
= paginate activity_lines_lider_ya_liders, theme: 'twitter-bootstrap-3' | ||
- model_class = ActivityLines::Lider::YaLider | ||
%table.table.table-striped.table-condensed | ||
%thead | ||
%tr | ||
%th= model_class.human_attribute_name(:id) | ||
%th= model_class.human_attribute_name(:contest_number) | ||
%th= model_class.human_attribute_name(:contest_year) | ||
- if searching? | ||
%th= model_class.human_attribute_name(:state) | ||
%th=t 'helpers.links.actions' | ||
%tbody | ||
- activity_lines_lider_ya_liders.each do |ya_lider| | ||
%tr{ class: state_color(ya_lider) } | ||
%td{ width: '67px' } | ||
= link_to ya_lider.id, admin_activity_lines_lider_ya_lider_path(ya_lider) | ||
%td= ya_lider.contest_number | ||
%td= ya_lider.contest_year | ||
- if searching? | ||
%td= ya_lider.human_state_name | ||
%td.actions | ||
= link_to fa_icon(:pencil), edit_admin_activity_lines_lider_ya_lider_path(ya_lider), class: 'btn btn-warning btn-xs' | ||
= link_to fa_icon(:remove), admin_activity_lines_lider_ya_lider_path(ya_lider), method: :delete, class: 'btn btn-xs btn-danger' | ||
= paginate activity_lines_lider_ya_liders, theme: 'twitter-bootstrap-3' |
1 change: 1 addition & 0 deletions
1
app/views/web/admin/activity_lines/lider/ya_lider/participantions/edit.html.haml
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 @@ | ||
= render partial: 'form', locals: { action: :update } |
1 change: 1 addition & 0 deletions
1
app/views/web/admin/activity_lines/lider/ya_lider/participantions/index.html.haml
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 @@ | ||
= render 'web/admin/default/index', items: @ya_liders |
1 change: 1 addition & 0 deletions
1
app/views/web/admin/activity_lines/lider/ya_lider/participantions/new.html.haml
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 @@ | ||
= render partial: 'form', locals: { action: :create } |
5 changes: 5 additions & 0 deletions
5
app/views/web/admin/activity_lines/lider/ya_lider/participantions/show.html.haml
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,5 @@ | ||
- title @ya_lider.full_title | ||
.panel-info | ||
.panel-heading | ||
%h4 | ||
= @ya_lider.full_title |
17 changes: 17 additions & 0 deletions
17
app/views/web/admin/activity_lines/lider/ya_lider/participants/_form.html.haml
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,17 @@ | ||
- model_class = ActivityLines::Lider::YaLider::Participant | ||
- current_title = page_title(action, model_class.model_name.human) | ||
- title current_title, :admin | ||
.page-header | ||
%h1=t current_title | ||
.row | ||
.col-lg-12 | ||
= render 'layouts/web/admin/shared/messages', object: @participant_form | ||
.row | ||
.col-lg-12 | ||
= simple_form_for [:admin, @participant_form], input_html: { class: 'form-horizontal' } do |f| | ||
= f.button :submit, class: 'btn-success', value: t('helpers.links.save') | ||
-#= link_to t('helpers.links.back'), admin_activity_lines_lider_ya_lider_path(ya_lider_id), class: 'btn btn-default' | ||
= f.input :user_id, as: :select, collection: users_cache_hash(@users), input_html: { class: :select2 }, label: false | ||
= f.input :state_event, as: :state_event | ||
= f.button :submit, class: 'btn-success', value: t('helpers.links.save') | ||
-#= link_to t('helpers.links.back'), admin_activity_lines_lider_ya_lider_path(ya_lider_id), class: 'btn btn-default' |
24 changes: 24 additions & 0 deletions
24
app/views/web/admin/activity_lines/lider/ya_lider/participants/_list.html.haml
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,24 @@ | ||
= paginate activity_lines_lider_ya_liders, theme: 'twitter-bootstrap-3' | ||
- model_class = ActivityLines::Lider::YaLider | ||
%table.table.table-striped.table-condensed | ||
%thead | ||
%tr | ||
%th= model_class.human_attribute_name(:id) | ||
%th= model_class.human_attribute_name(:contest_number) | ||
%th= model_class.human_attribute_name(:contest_year) | ||
- if searching? | ||
%th= model_class.human_attribute_name(:state) | ||
%th=t 'helpers.links.actions' | ||
%tbody | ||
- activity_lines_lider_ya_liders.each do |ya_lider| | ||
%tr{ class: state_color(ya_lider) } | ||
%td{ width: '67px' } | ||
= link_to ya_lider.id, admin_activity_lines_lider_ya_lider_path(ya_lider) | ||
%td= ya_lider.contest_number | ||
%td= ya_lider.contest_year | ||
- if searching? | ||
%td= ya_lider.human_state_name | ||
%td.actions | ||
= link_to fa_icon(:pencil), edit_admin_activity_lines_lider_ya_lider_path(ya_lider), class: 'btn btn-warning btn-xs' | ||
= link_to fa_icon(:remove), admin_activity_lines_lider_ya_lider_path(ya_lider), method: :delete, class: 'btn btn-xs btn-danger' | ||
= paginate activity_lines_lider_ya_liders, theme: 'twitter-bootstrap-3' |
1 change: 1 addition & 0 deletions
1
app/views/web/admin/activity_lines/lider/ya_lider/participants/edit.html.haml
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 @@ | ||
= render partial: 'form', locals: { action: :update } |
1 change: 1 addition & 0 deletions
1
app/views/web/admin/activity_lines/lider/ya_lider/participants/index.html.haml
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 @@ | ||
= render 'web/admin/default/index', items: @ya_liders |
1 change: 1 addition & 0 deletions
1
app/views/web/admin/activity_lines/lider/ya_lider/participants/new.html.haml
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 @@ | ||
= render partial: 'form', locals: { action: :create } |
5 changes: 5 additions & 0 deletions
5
app/views/web/admin/activity_lines/lider/ya_lider/participants/show.html.haml
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,5 @@ | ||
- title @ya_lider.full_title | ||
.panel-info | ||
.panel-heading | ||
%h4 | ||
= @ya_lider.full_title |
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
5 changes: 5 additions & 0 deletions
5
db/migrate/20161230101429_add_state_to_activity_lines_lider_ya_lider_participants.rb
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,5 @@ | ||
class AddStateToActivityLinesLiderYaLiderParticipants < ActiveRecord::Migration | ||
def change | ||
add_column :activity_lines_lider_ya_lider_participations, :state, :text | ||
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
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
66 changes: 63 additions & 3 deletions
66
test/controllers/web/admin/activity_lines/lider/ya_lider/participants_controller_test.rb
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,67 @@ | ||
require 'test_helper' | ||
|
||
class Web::Admin::ActivityLines::Lider::YaLider::ParticipantsControllerTest < ActionController::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
setup do | ||
admin = create :admin | ||
sign_in admin | ||
create :ya_lider | ||
@participant = create :ya_lider_participant | ||
@exceptions_attributes = ['id', 'created_at', 'updated_at', 'begin_date', 'end_date'] | ||
end | ||
|
||
test 'should get new' do | ||
get :new, activity_lines_lider_ya_lider_participant: { ya_lider_id: ActivityLines::Lider::YaLider.last.id } | ||
assert_response :success, @response.body | ||
end | ||
|
||
test 'should create participant' do | ||
attributes = attributes_for :ya_lider_participant | ||
attributes[:arguments_attributes] = {} | ||
attributes[:arguments_attributes]['0'] = attributes_for :argument | ||
post :create, activity_lines_lider_ya_lider_participant: attributes | ||
participant = ActivityLines::Lider::YaLider::Participant.last | ||
assert_response :redirect, @response.body | ||
assert_redirected_to admin_activity_lines_lider_ya_liders_path | ||
participant.attributes.keys.except(*@exceptions_attributes).each do |key| | ||
assert_equal attributes[key.to_sym], participant.send(key), key | ||
end | ||
end | ||
|
||
test 'should not create participant' do | ||
attributes = { user_id: @participant.user_id } | ||
post :create, activity_lines_lider_ya_lider_participant: attributes | ||
assert_response :success | ||
end | ||
|
||
test 'should get edit by admin' do | ||
4.times { create :argument } | ||
get :edit, id: @participant | ||
assert_response :success | ||
end | ||
|
||
test 'should update participant by admin' do | ||
attributes = attributes_for :ya_lider_participant | ||
put :update, id: @participant, activity_lines_lider_ya_lider_participant: attributes | ||
assert_response :redirect | ||
assert_redirected_to admin_activity_lines_lider_ya_liders_path | ||
@participant.reload | ||
@participant.attributes.keys.except(*@exceptions_attributes).each do |key| | ||
assert_equal attributes[key.to_sym], @participant.send(key), key | ||
end | ||
end | ||
|
||
test 'should not update participant by admin' do | ||
attributes = attributes_for :ya_lider_participant | ||
attributes[:user_id] = nil | ||
count_before_save = ActivityLines::Lider::YaLider::Participant.count | ||
put :update, id: @participant, activity_lines_lider_ya_lider_participant: attributes | ||
assert_equal ActivityLines::Lider::YaLider::Participant.count, count_before_save | ||
assert_response :success | ||
end | ||
|
||
test 'should destroy participant' do | ||
delete :destroy, id: @participant | ||
@participant.reload | ||
assert @participant.removed? | ||
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
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 @@ | ||
FactoryGirl.define do | ||
factory :ya_lider_participant, class: 'ActivityLines::Lider::YaLider::Participant' do | ||
contest_year { generate :integer } | ||
user_id { User.last ? User.last.id : create(:user).id } | ||
state { ActivityLines::Lider::YaLider::Participant.state_machines[:state].states.map(&:name).first.to_s } | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
test/factories/activity_lines/lider/ya_lider/participations.rb
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,13 @@ | ||
FactoryGirl.define do | ||
factory :ya_lider_participation, class: 'ActivityLines::Lider::YaLider::Participation' do | ||
stage_id do | ||
if ActivityLines::Lider::YaLider::Stage.last | ||
ActivityLines::Lider::YaLider::Stage.last.id | ||
else | ||
create(:ya_lider_stage).id | ||
end | ||
end | ||
user_id { User.last.present? ? User.last.id : create(:user).id } | ||
state { ActivityLines::Lider::YaLider::Participation.state_machines[:state].states.map(&:name).first.to_s } | ||
end | ||
end |