Skip to content

Commit

Permalink
Fix some rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
Senen committed Nov 23, 2017
1 parent 1ec2566 commit fb6a21d
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 46 deletions.
25 changes: 12 additions & 13 deletions app/controllers/admin/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@ def new
@organization.user = User.new
end


private

def organization_params
params.require(:organization)
.permit(:reference, :identifier, :name, :first_surname, :second_surname, :phones, :email,
:web, :address_type, :address, :number, :gateway, :stairs, :floor, :door,
:postal_code, :town, :province, :description, :registered_lobbies, :category_id,
:fiscal_year, :range_fund, :subvention, :contract, :denied_public_data, :denied_public_events, interest_ids: [],
legal_representant_attributes: [:id, :identifier, :name, :first_surname, :second_surname, :phones, :email],
user_attributes: [:id, :first_name, :last_name, :role, :email, :active, :phones, :password, :password_confirmation],
represented_entities_attributes: [:id, :identifier, :name, :first_surname, :second_surname, :from, :fiscal_year, :range_fund, :subvention, :contract],
organization_interests_attributes: [:interest_ids],
agents_attributes: [:id, :identifier, :name, :first_surname, :second_surname, :from, :to, :public_assignments])
end
def organization_params
params.require(:organization)
.permit(:reference, :identifier, :name, :first_surname, :second_surname, :phones, :email,
:web, :address_type, :address, :number, :gateway, :stairs, :floor, :door,
:postal_code, :town, :province, :description, :registered_lobbies, :category_id,
:fiscal_year, :range_fund, :subvention, :contract, :denied_public_data, :denied_public_events, interest_ids: [],
legal_representant_attributes: [:id, :identifier, :name, :first_surname, :second_surname, :phones, :email],
user_attributes: [:id, :first_name, :last_name, :role, :email, :active, :phones, :password, :password_confirmation],
represented_entities_attributes: [:id, :identifier, :name, :first_surname, :second_surname, :from, :fiscal_year, :range_fund, :subvention, :contract],
organization_interests_attributes: [:interest_ids],
agents_attributes: [:id, :identifier, :name, :first_surname, :second_surname, :from, :to, :public_assignments])
end

end

Expand Down
2 changes: 1 addition & 1 deletion app/models/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ class Agent < ActiveRecord::Base

belongs_to :organization

validates_presence_of :name, :identifier, :from
validates :name, :identifier, :from, presence: true

end
2 changes: 1 addition & 1 deletion app/models/area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Area < ActiveRecord::Base

has_ancestry

validates_presence_of :title
validates :title, presence: true

before_create :set_defaults
after_save :update_children
Expand Down
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Event < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: [:slugged, :finders]

validates_presence_of :title, :position, :scheduled
validates :title, :position, :scheduled, presence: true
validate :participants_uniqueness, :position_not_in_participants

belongs_to :user
Expand Down
2 changes: 1 addition & 1 deletion app/models/legal_representant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ class LegalRepresentant < ActiveRecord::Base

belongs_to :organization

validates_presence_of :identifier, :name, :first_surname, :email
validates :identifier, :name, :first_surname, :email, presence: true

end
4 changes: 2 additions & 2 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class Organization < ActiveRecord::Base
enum entity_type: [:association, :federation, :lobby]

validates :inscription_reference, uniqueness: true, allow_blank: true, allow_nil: true
validates_presence_of :name, :user
validates_inclusion_of :denied_public_data, :denied_public_events, in: [false]
validates :name, :user, presence: true
validates :denied_public_data, :denied_public_events, inclusion: { in: [false] }

has_many :represented_entities, dependent: :destroy
has_many :agents, dependent: :destroy
Expand Down
2 changes: 1 addition & 1 deletion app/models/position.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Position < ActiveRecord::Base
has_many :titular_events, class_name: "Event", dependent: :destroy
has_many :participants_events, through: :participants

validates_presence_of :title, :area
validates :title, :area, presence: true

scope :current, -> { where(to: nil) }
scope :previous, -> { where.not(to: nil) }
Expand Down
2 changes: 1 addition & 1 deletion app/models/represented_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ class RepresentedEntity < ActiveRecord::Base

belongs_to :organization

validates_presence_of :identifier, :name, :fiscal_year, :from
validates :identifier, :name, :fiscal_year, :from, presence: true

end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class User < ActiveRecord::Base
has_many :holders, through: :manages
belongs_to :organization

validates_presence_of :first_name, :last_name, :email
validates :first_name, :last_name, :email, presence: true
validate :manages_uniqueness

accepts_nested_attributes_for :manages, reject_if: :all_blank, allow_destroy: true
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
entity_type :federation
end

trait :person do
trait :person do
name { Faker::Name.name }
first_surname { Faker::Name.last_name }
second_surname { Faker::Name.last_name }
Expand Down
32 changes: 14 additions & 18 deletions spec/features/admin/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

describe "Legal Representant" do

scenario 'Try create organization with invalid legal representant and display error', js: true do
scenario 'Try create organization with invalid legal representant and display error', :js do
visit new_admin_organization_path

fill_in :organization_name, with: "organization name"
Expand All @@ -94,7 +94,7 @@
expect(page).to have_content "Por favor corrija los siguientes errores antes de continuar"
end

scenario 'Create organization with valid legal representant', js: true do
scenario 'Create organization with valid legal representant', :js do
visit new_admin_organization_path

fill_in :organization_name, with: "organization name"
Expand All @@ -113,15 +113,15 @@
expect(page).to have_content "Registro creado correctamente"
end

scenario 'Only add one legal representant', js: true do
scenario 'Only add one legal representant', :js do
visit new_admin_organization_path

click_on "Añadir legal representant"

expect(page).not_to have_content "Añadir legal representant"
end

scenario 'Display remove button after add one legal representant', js: true do
scenario 'Display remove button after add one legal representant', :js do
visit new_admin_organization_path

expect(page).not_to have_selector "#new_legal_representant .remove_fields"
Expand All @@ -134,7 +134,7 @@

describe "Represented Entities" do

scenario 'Try create organization with invalid respresented entities and display error', js: true do
scenario 'Try create organization with invalid respresented entities and display error', :js do
visit new_admin_organization_path

fill_in :organization_name, with: "organization name"
Expand All @@ -155,11 +155,10 @@

click_button "Guardar"


expect(page).to have_content "Por favor corrija los siguientes errores antes de continuar"
end

scenario 'Create organization with valid represented entities', js: true do
scenario 'Create organization with valid represented entities', :js do
visit new_admin_organization_path

fill_in :organization_name, with: "organization name"
Expand All @@ -180,19 +179,18 @@

click_button "Guardar"


expect(page).to have_content "Registro creado correctamente"
end

scenario 'Can adding more than one represented entity', js: true do
scenario 'Can adding more than one represented entity', :js do
visit new_admin_organization_path

click_on "Añadir Entidades a las que se representa"

expect(page).to have_content "Añadir Entidades a las que se representa"
end

scenario 'Display remove button after add represented entity', js: true do
scenario 'Display remove button after add represented entity', :js do
visit new_admin_organization_path

expect(page).not_to have_selector "#new_represented_entity .remove_fields"
Expand All @@ -201,7 +199,7 @@
expect(page).to have_selector "#new_represented_entity .remove_fields"
end

scenario 'Display remove button after add more than one represented entity', js: true do
scenario 'Display remove button after add more than one represented entity', :js do
visit new_admin_organization_path

expect(page).not_to have_selector "#new_represented_entity .remove_fields"
Expand All @@ -214,7 +212,7 @@

describe "Agents" do

scenario 'Try create organization with invalid agent and display error', js: true do
scenario 'Try create organization with invalid agent and display error', :js do
visit new_admin_organization_path

fill_in :organization_name, with: "organization name"
Expand All @@ -234,11 +232,10 @@

click_button "Guardar"


expect(page).to have_content "Por favor corrija los siguientes errores antes de continuar"
end

scenario 'Create organization with valid agents', js: true do
scenario 'Create organization with valid agents', :js do
visit new_admin_organization_path

fill_in :organization_name, with: "organization name"
Expand All @@ -258,19 +255,18 @@

click_button "Guardar"


expect(page).to have_content "Registro creado correctamente"
end

scenario 'Can adding more than one agent', js: true do
scenario 'Can adding more than one agent', :js do
visit new_admin_organization_path

click_on "Añadir Agentes"

expect(page).to have_content "Añadir Agentes"
end

scenario 'Display remove button after add agent', js: true do
scenario 'Display remove button after add agent', :js do
visit new_admin_organization_path

expect(page).not_to have_selector "#new_agent .remove_fields"
Expand All @@ -279,7 +275,7 @@
expect(page).to have_selector "#new_agent .remove_fields"
end

scenario 'Display remove button after add more than one agent', js: true do
scenario 'Display remove button after add more than one agent', :js do
visit new_admin_organization_path

expect(page).not_to have_selector "#new_agent .remove_fields"
Expand Down
8 changes: 4 additions & 4 deletions spec/features/organizations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
end

scenario "Should filter by given keywords over organizations name and show result" do
organization = create(:organization, name: "Fulanito", first_surname: "Mengano", second_surname: "de Tal")
organization = organization = create(:organization, name: "Fulanito", first_surname: "Mengano", second_surname: "de Tal")
Organization.reindex

visit organizations_path
Expand All @@ -112,7 +112,7 @@
end

scenario "Should reset search form when user clicks reset form button" do
organization = create(:organization, name: "Fulanito", first_surname: "Mengano", second_surname: "de Tal")
create(:organization, name: "Fulanito", first_surname: "Mengano", second_surname: "de Tal")
Organization.reindex

visit organizations_path
Expand All @@ -125,7 +125,7 @@
end

scenario "Should show number of results by given keywords" do
organization = create(:organization, name: "Hola", first_surname: "", second_surname: "")
create(:organization, name: "Hola", first_surname: "", second_surname: "")
Organization.reindex

visit organizations_path
Expand All @@ -136,7 +136,7 @@
end

scenario "Should show number of results by given keywords", :js do
organization = create(:organization, name: "Hola", first_surname: "", second_surname: "")
create(:organization, name: "Hola", first_surname: "", second_surname: "")
Organization.reindex

visit organizations_path
Expand Down
1 change: 0 additions & 1 deletion spec/models/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@
expect(agent).not_to be_valid
end


end

0 comments on commit fb6a21d

Please sign in to comment.