Skip to content

Commit

Permalink
Fix codeclimate suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
taitus committed Dec 12, 2017
1 parent e1eaf1a commit c6cc64d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 53 deletions.
15 changes: 7 additions & 8 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,21 @@ def find_holder_id_by_name(name)
array_position = Position.where("positions.holder_id IN (?)", holder_ids)
end

def emun_status(array_status)
def enum_status(array_status)
@status = array_status.map { |status| Event.statuses[status] }.join(' , ') if array_status.present?
end

def search_params(params)
person = params[:search_person]
title = params[:search_title]
lobby_activity = params[:lobby_activity]
status = emun_status(params[:status])
role = current_user.role
status = enum_status(params[:status])

params_searches = {}
params_searches[:title] = title unless title.blank?
params_searches[:lobby_activity] = "1" unless lobby_activity.blank?
params_searches[:status] = emun_status(params[:status]) if status.present?
params_searches[:position_id] = find_holder_id_by_name(params[:search_person]) if person.present?
params_searches[:organization_id] = current_user.organization_id if role == "lobby"
params_searches[:lobby_activity] = "1" unless params[:lobby_activity].blank?
params_searches[:status] = status if status.present?
params_searches[:position_id] = find_holder_id_by_name(person) if person.present?
params_searches[:organization_id] = current_user.organization_id if current_user.role == "lobby"
params_searches
end

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/admin/events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def calculate_email(event)
end
end

def event_status_search_options (selected)
rev= {}
def event_status_search_options(selected)
rev = {}
t("backend.status").each_with_index { |(k, v)| rev[v] = k }
options_for_select(rev, selected)
end
Expand Down
14 changes: 7 additions & 7 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def self.searches(params)
else
events = all
end
events
events
end

searchable do
Expand Down Expand Up @@ -154,6 +154,12 @@ def user_name
user.full_name
end

def self.filter(attributes)
attributes.slice(*SUPPORTED_FILTERS).reduce(all) do |scope, (key, value)|
value.present? ? scope.send(key, value) : scope
end
end

private

def participants_uniqueness
Expand Down Expand Up @@ -183,10 +189,4 @@ def role_validate_scheduled
errors.add(:base, "Fecha del evento no puede estar en blanco")
end

def self.filter(attributes)
attributes.slice(*SUPPORTED_FILTERS).reduce(all) do |scope, (key, value)|
value.present? ? scope.send(key, value) : scope
end
end

end
47 changes: 19 additions & 28 deletions spec/features/admin/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@
end

scenario 'visit index event page' do
event = create(:event, title: 'New event for lobbies', position: @position , organization_id: @organization.id)
event = create(:event, title: 'New event for lobbies', position: @position, organization_id: @organization.id)
visit events_path

expect(page).to have_content event.title
Expand Down Expand Up @@ -798,8 +798,10 @@
describe "Edit" do

scenario "Edit buttons enabled for events on_request" do
event_requested = create(:event, title: 'Event on request', position: @position, status: 0, organization: @organization)
event_accepted = create(:event, title: 'Event accepted', position: @position, status: 1, organization: @organization)
event_requested = create(:event, title: 'Event on request', position: @position, status: 0,
organization: @organization)
event_accepted = create(:event, title: 'Event accepted', position: @position, status: 1,
organization: @organization)

visit events_path

Expand All @@ -808,8 +810,10 @@
end

scenario "Edit buttons enabled for events on_request on show view" do
event_requested = create(:event, title: 'Event on request', position: @position, status: 0, organization: @organization)
event_accepted = create(:event, title: 'Event accepted', position: @position, status: 1, organization: @organization)
event_requested = create(:event, title: 'Event on request', position: @position,
status: 0, organization: @organization)
event_accepted = create(:event, title: 'Event accepted', position: @position,
status: 1, organization: @organization)

visit event_path(event_requested)

Expand All @@ -821,7 +825,8 @@
end

scenario "User can edit events", :js do
event_requested = create(:event, title: 'Event on request', position: @position, status: 0, organization: @organization)
event_requested = create(:event, title: 'Event on request', position: @position,
status: 0, organization: @organization)

visit event_path(event_requested)

Expand All @@ -847,14 +852,16 @@
end

scenario "User can cancel events only once!" do
event_requested = create(:event, title: 'Event on request', position: @position, status: 0, canceled_at: Time.zone.today, organization: @organization)
event_requested = create(:event, title: 'Event on request', position: @position, status: 0,
canceled_at: Time.zone.today, organization: @organization)
visit edit_event_path(event_requested)

expect(page).not_to have_selector "#event_cancel_true"
end

scenario 'Lobby user can see on page the name of the organization' do
event = create(:event, organization_name: "Organization name", position: @position, organization: @organization)
event = create(:event, organization_name: "Organization name", position: @position,
organization: @organization)

visit edit_event_path(event)

Expand All @@ -863,7 +870,8 @@

scenario 'Lobby user can see lobby contact info' do
event = create(:event, organization_name: "Organization name", lobby_contact_firstname: 'lobbyname',
lobby_contact_lastname: 'lobbylastname', lobby_contact_phone: '600123123', lobby_contact_email: 'lobbyemail@email.com', organization: @organization)
lobby_contact_lastname: 'lobbylastname', lobby_contact_phone: '600123123',
lobby_contact_email: 'lobbyemail@email.com', organization: @organization)

visit edit_event_path(event)

Expand All @@ -877,25 +885,8 @@

scenario 'Lobby user can update lobby contact info', :js do
event = create(:event, organization_name: "Organization name", lobby_contact_firstname: 'lobbyname',
lobby_contact_lastname: 'lobbylastname', lobby_contact_phone: '600123123', lobby_contact_email: 'lobbyemail@email.com', organization: @organization)
visit edit_event_path(event)

fill_in :event_lobby_contact_firstname, with: 'new lobbyname'
fill_in :event_lobby_contact_lastname, with: 'new lobylastname'
fill_in :event_lobby_contact_phone, with: '900878787'
fill_in :event_lobby_contact_email, with: 'new_loby@email.com'
click_button 'Guardar'

event.reload
expect(event.lobby_contact_firstname).to eq 'new lobbyname'
expect(event.lobby_contact_lastname).to eq 'new lobylastname'
expect(event.lobby_contact_phone).to eq '900878787'
expect(event.lobby_contact_email).to eq 'new_loby@email.com'
end

scenario 'Lobby user can update lobby contact info', :js do
event = create(:event, organization_name: "Organization name", lobby_contact_firstname: 'lobbyname',
lobby_contact_lastname: 'lobbylastname', lobby_contact_phone: '600123123', lobby_contact_email: 'lobbyemail@email.com', organization: @organization)
lobby_contact_lastname: 'lobbylastname', lobby_contact_phone: '600123123',
lobby_contact_email: 'lobbyemail@email.com', organization: @organization)
visit edit_event_path(event)

fill_in :event_lobby_contact_firstname, with: 'new lobbyname'
Expand Down
17 changes: 9 additions & 8 deletions spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,29 +163,30 @@

describe ".searches" do
let!(:holder) { create(:holder, :with_position, first_name: "John", last_name: "Doe") }
let!(:event) { create(:event, position: holder.current_position, title: "Some amazing title", lobby_activity: false , status: "accepted") }
let!(:event) { create(:event, position: holder.current_position, title: "Some amazing title",
lobby_activity: false ,status: "accepted") }

it "Should return events by given holder name" do
params= Hash.new
params[:title] = "Some amazing title"
params = {}
params[:person] = "John"
expect(Event.searches(params)).to eq([event])
end

it "Should return events by given title name" do
params= Hash.new
params[:title] = "Some amazing title"
params = {}
params[:person] = "Doe"
expect(Event.searches(params)).to eq([event])
end

it "Should return events by given status" do
params= Hash.new
params = {}
params[:title] = "Some amazing title"
params[:status] = 1 #accepted
params[:status] = 1 # accepted
expect(Event.searches(params)).to eq([event])
end

it "Should return events by different status" do
params= Hash.new
params = {}
params[:title] = "Some amazing title"
params[:status] = 2
expect(Event.searches(params)).not_to eq([event])
Expand Down

0 comments on commit c6cc64d

Please sign in to comment.