Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/cofig_user' into cofig_user
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinesalib committed Apr 20, 2020
2 parents 569a61a + feac38f commit 4e998bd
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 18 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ group :development, :test do
gem 'factory_bot_rails'
gem 'rspec-rails', '~> 3.7'
gem 'rails-controller-testing'
gem 'shoulda-matchers'
gem 'simplecov'
gem 'rspec_junit_formatter'
end
Expand Down
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ GEM
sentry-raven (2.13.0)
faraday (>= 0.7.6, < 1.0)
shellany (0.0.1)
shoulda-matchers (4.1.2)
activesupport (>= 4.2.0)
sidekiq (5.2.7)
connection_pool (~> 2.2, >= 2.2.2)
rack (>= 1.5.0)
Expand Down Expand Up @@ -422,6 +424,7 @@ DEPENDENCIES
rubocop (~> 0.62.0)
sass-rails (~> 5.0)
sentry-raven
shoulda-matchers
sidekiq (= 5.2.7)
simplecov
spring
Expand All @@ -438,4 +441,4 @@ RUBY VERSION
ruby 2.6.3p62

BUNDLED WITH
2.0.2
2.1.4
15 changes: 10 additions & 5 deletions app/controllers/ngo_area/ngos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ def new

def create
@ngo = Ngo.create(params_ngo)

redirect_to ngo_area_ngos_path
if @ngo.save
redirect_to ngo_area_ngos_path
else
render :new
end
end

def edit
Expand All @@ -19,9 +22,11 @@ def edit

def update
@ngo = Ngo.find(params[:id])
@ngo.update params_ngo

redirect_to ngo_area_ngos_path
if @ngo.update(params_ngo)
redirect_to ngo_area_ngos_path
else
render :edit
end
end

private
Expand Down
6 changes: 6 additions & 0 deletions app/models/ngo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ class Ngo < ApplicationRecord
has_one_attached :image

validates :fantasy_name, presence: true
validates :zipcode, presence: true
validates :address_number, presence: true
validates :address, presence: true
validates :neighborhood, presence: true
validates :city, presence: true
validates :state, presence: true

scope :active, -> { where(active: true) }

Expand Down
31 changes: 20 additions & 11 deletions app/views/ngo_area/ngos/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<div class="col-lg-6">
<%= form_error_tag(@ngo) %>

<div class="col-lg-6" >
<div class="form-group">
<%= label_tag(:social_name, 'Razão Social') %>
<%= f.text_field :social_name, class: 'form-control' %>
</div>
<div class="form-group">
<div class="form-group <%= form_group_error_class(@ngo, :fantasy_name)%>">
<%= label_tag(:fantasy_name, 'Nome Fantasia') %>
<%= f.text_field :fantasy_name, class: 'form-control' %>
<%= field_error_tag(@ngo, :fantasy_name) %>
</div>
<div class="form-group">
<%= label_tag(:email, 'E-mail') %>
Expand Down Expand Up @@ -63,29 +66,35 @@
</div>
<div class="col-lg-6">
<h1>Endereço</h1>
<div class="form-group">
<div class="form-group <%= form_group_error_class(@ngo, :zipcode)%>">
<%= label_tag(:zipcode, 'CEP') %>
<%= f.number_field :zipcode, class: 'form-control' %>
<%= field_error_tag(@ngo, :zipcode) %>
</div>
<div class="form-group">
<div class="form-group <%= form_group_error_class(@ngo, :address_number)%>">
<%= label_tag(:address_number, 'Número ') %>
<%= f.number_field :address_number, class: 'form-control' %>
<%= field_error_tag(@ngo, :address_number) %>
</div>
<div class="form-group">
<div class="form-group <%= form_group_error_class(@ngo, :address)%>">
<%= label_tag(:address, 'Endereço') %>
<%= f.text_field :address, class: 'form-control', :readonly => true %>
<%= f.text_field :address, class: 'form-control' %>
<%= field_error_tag(@ngo, :address) %>
</div>
<div class="form-group">
<div class="form-group <%= form_group_error_class(@ngo, :neighborhood)%>">
<%= label_tag(:neighborhood, 'Bairro') %>
<%= f.text_field :neighborhood, class: 'form-control', :readonly => true %>
<%= f.text_field :neighborhood, class: 'form-control' %>
<%= field_error_tag(@ngo, :neighborhood) %>
</div>
<div class="form-group">
<div class="form-group <%= form_group_error_class(@ngo, :city)%>">
<%= label_tag(:city, 'Cidade') %>
<%= f.text_field :city, class: 'form-control', :readonly => true %>
<%= field_error_tag(@ngo, :city) %>
</div>
<div class="form-group">
<div class="form-group <%= form_group_error_class(@ngo, :state)%>">
<%= label_tag(:state, 'Estado') %>
<%= f.text_field :state, class: 'form-control', :readonly => true %>
<%= field_error_tag(@ngo, :state) %>
</div>
<h1>Conta bancária</h1>
<div class="form-group">
Expand Down Expand Up @@ -116,4 +125,4 @@
</div>
</div>

<%= javascript_include_tag "ngo_area/ngos/form" %>
<%= javascript_include_tag "ngo_area/ngos/form" %>
8 changes: 7 additions & 1 deletion spec/factories/ngo.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
FactoryBot.define do
factory :ngo do
fantasy_name { Faker::Name.name }
zipcode { Faker::Address.zip_code }
address_number { Faker::Address.building_number }
address { Faker::Address.street_name }
neighborhood { Faker::Address.community }
city { Faker::Address.city }
state { Faker::Address.state_abbr }
end
end
end
10 changes: 10 additions & 0 deletions spec/models/ngo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
user
end

describe 'validations' do
it { is_expected.to validate_presence_of(:fantasy_name) }
it { is_expected.to validate_presence_of(:zipcode) }
it { is_expected.to validate_presence_of(:address_number) }
it { is_expected.to validate_presence_of(:address) }
it { is_expected.to validate_presence_of(:neighborhood) }
it { is_expected.to validate_presence_of(:city) }
it { is_expected.to validate_presence_of(:state) }
end

describe '.from_user' do
context 'when user is not admin' do
it 'returns just one ngo' do
Expand Down
7 changes: 7 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,11 @@ def login_user_capybara(trait)
I18n.default_locale = :en
stub_const("#{ApplicationController}::DEFAULT_LOCALE", 'en')
end

Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
end

0 comments on commit 4e998bd

Please sign in to comment.