Skip to content

Commit

Permalink
fix some and remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
phoet committed Apr 3, 2018
1 parent 4440f9a commit bb37bc5
Show file tree
Hide file tree
Showing 25 changed files with 77 additions and 72 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ group :development, :test do
gem 'meta_request'
gem 'better_errors'
gem 'binding_of_caller'
gem 'rails-controller-testing'
end
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ GEM
bundler (>= 1.3.0)
railties (= 5.0.6)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1)
actionview (~> 5.x, >= 5.0.1)
activesupport (~> 5.x)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
Expand Down Expand Up @@ -382,6 +386,7 @@ DEPENDENCIES
puma (~> 3.6)
rack-cache (~> 1.2)
rails (~> 5.0.6)
rails-controller-testing
rails-observers (~> 0.1.2)
rails_12factor (~> 0.0.2)
redcarpet (~> 3.0)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Admin::ApplicationController < Admin::ResourcesController
include WhitelabelDetection

before_filter :switch_label
before_action :switch_label
end
2 changes: 1 addition & 1 deletion app/controllers/admin/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def duplicate
def publish
event = Event.find_by_slug(params[:id])
UsergroupMailer.invitation_mail(event).deliver_now!
event.update_attributes! published: true
event.update! published: true

redirect_to url_for(controller: '/admin/events', action: :edit, id: event.id), notice: 'Published!'
end
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ class Admin::UsersController < Admin::ApplicationController
def new
redirect_to url_for(controller: '/admin/users'), notice: "You can't create users via the admin, they need to signup via OAuth!"
end

def create
redirect_to url_for(controller: '/admin/users'), notice: "You can't create users via the admin, they need to signup via OAuth!"
end
end
4 changes: 2 additions & 2 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def index
format.html
format.xml { render layout: false }
format.json { render json: events.as_api_response(:ios_v1) }
format.ics { render text: icalendar(*events) }
format.ics { render plain: icalendar(*events) }
end
end

Expand All @@ -23,7 +23,7 @@ def show
render json: event.as_api_response(:ios_v1)
end
format.ics do
render text: icalendar(event)
render plain: icalendar(event)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def edit; end
def create
topic.label = Whitelabel[:label_id]
topic.user = current_user
if topic.save
if topic.update(topic_params)
if current_user.email.blank?
redirect_to(edit_user_path(current_user), notice: t('flash.add_email'))
else
Expand All @@ -31,7 +31,7 @@ def create
end

def update
if topic.save
if topic.update(topic_params)
redirect_to(topic_path(topic), notice: t('flash.topic_updated'))
else
redirect_to(edit_topic_path, alert: topic.errors.full_messages.join(', '))
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ def edit; end
def calendar
respond_to do |format|
format.ics do
render text: icalendar(*user.participations)
render plain: icalendar(*user.participations)
end
end
end

def update
if current_user.update_attributes user_params
redirect_to :back, notice: t('user.saved_successful')
if current_user.update user_params
redirect_back(notice: t('user.saved_successful'), fallback_location: root_url)
else
redirect_to :back, alert: current_user.errors.full_messages.join(' ')
redirect_back(alert: current_user.errors.full_messages.join(' '), fallback_location: root_url)
end
end

Expand Down
6 changes: 1 addition & 5 deletions app/extensions/typus/authentication/custom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ module Custom

def authenticate
@admin_user = FakeUser.new
def @admin_user.can?(*args)
action, type, _ = args
return false if action == 'create' && type == 'User'
return true
end

authenticate_admin_user!
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def disabled?
end

def disable!
update_attributes! start_at: Time.now, end_at: Time.now
update! start_at: Time.now, end_at: Time.now
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class User < ActiveRecord::Base

scope :organizers, -> { where(nickname: Whitelabel[:organizers]) }
scope :ordered, -> { order('updated_at DESC') }
scope :peers, -> { ordered.joins(participants: :event).where('events.label' => Whitelabel[:label_id]).uniq }
scope :peers, -> { ordered.joins(participants: :event).where('events.label' => Whitelabel[:label_id]).distinct }
scope :main, -> { where(nickname: Whitelabel[:twitter]) }

def participates?(event)
Expand Down
3 changes: 0 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,5 @@ class Application < Rails::Application
g.fixture_replacement :factory_girl, :dir => "spec/support/factories"
g.stylesheet_engine = :sass
end

# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
end
end
4 changes: 2 additions & 2 deletions spec/controllers/admin/events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
event = create(:event)

expect {
get :publish, id: event.id
get :publish, params: { id: event.id }
}.to change {
ActionMailer::Base.deliveries.size
}.by(1)
Expand All @@ -51,7 +51,7 @@
}
).and_return(OpenStruct.new(code: '200'))

get :send_ios_push_notification, id: event.id
get :send_ios_push_notification, params: { id: event.id }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/highlights_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let(:highlight) { create(:highlight) }

it 'duplicates the last event' do
get :disable, id: highlight
get :disable, params: { id: highlight }
expect(assigns[:highlight]).to be_disabled
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/admin/topics_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
context 'GET :add_to_next_event' do
it 'attaches a proposal to the next event' do
event = create(:event)
get :add_to_next_event, id: @proposal
get :add_to_next_event, params: { id: @proposal }

expect(assigns[:topic].event).to eql(event)
expect(assigns[:topic].event.users).to include(@proposal.user)
expect(response).to be_a_redirect
end

it 'does redirects back if there is no relevant event' do
get :add_to_next_event, id: @proposal
get :add_to_next_event, params: { id: @proposal }

expect(response).to redirect_to(controller: '/admin/topics', action: :index)
end
Expand Down
8 changes: 5 additions & 3 deletions spec/controllers/admin/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
end

context 'POST :create' do
it 'hides this page' do
post :create, {user: {}}
let(:data) { { user: attributes_for(:user) } }

expect(response).to have_http_status(422)
it 'hides this page' do
expect {
post :create, params: data
}.not_to change(User, :count)
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
it 'renders json' do
allow(controller).to receive_messages(events: [event])

get :index, format: :json
get :index, params: { format: :json }
expect(response.headers['Content-Type']).to eql('application/json; charset=utf-8')
expect(JSON.parse(response.body)).to have(1).elements
end
Expand All @@ -26,7 +26,7 @@
it 'renders xml' do
allow(controller).to receive_messages(events: [event])

get :index, format: :xml
get :index, params: { format: :xml }
expect(response.headers['Content-Type']).to eql('application/xml; charset=utf-8')
expect(response.body).to match(/rss/)
end
Expand All @@ -37,15 +37,15 @@
let!(:event) { create(:full_event) }

it 'assigns the event and renders the template' do
get :show, id: event.id
get :show, params: { id: event.id }
expect(controller.event).to eql(event)
expect(response).to render_template(:show)
end

context 'json' do
it 'renders json' do
allow(controller).to receive_messages(event: event)
get :show, id: event, format: :json
get :show, params: { id: event, format: :json }
expect(response.headers['Content-Type']).to eql('application/json; charset=utf-8')
json = JSON.parse(response.body)

Expand Down Expand Up @@ -113,7 +113,7 @@
context 'ics' do
it 'renders ical' do
allow(controller).to receive_messages(event: event)
get :show, id: event, format: :ics
get :show, params: { id: event, format: :ics }
expect(response.headers['Content-Type']).to eql('text/calendar; charset=utf-8')
expect(response.body).to match('VCALENDAR')
end
Expand Down
14 changes: 7 additions & 7 deletions spec/controllers/likes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let!(:data) { { like: attributes_for(:like), topic_id: topic.id } }

it 'authenticates the action' do
post(:create, data)
post(:create, params: data)
expect(response).to redirect_to(root_path)
end

Expand All @@ -19,7 +19,7 @@

it 'creates a like for logged-in user' do
expect {
post(:create, data)
post(:create, params: data)
}.to change(Like, :count).by(1)
expect(controller.like.user).to eql(user)
end
Expand All @@ -28,14 +28,14 @@
allow_any_instance_of(Topic).to receive_messages(already_liked?: true)

expect {
post(:create, data)
post(:create, params: data)
}.to change(Like, :count).by(0)
end

it 'validetes likes' do
allow_any_instance_of(Like).to receive_messages(save: false)

post(:create, data)
post(:create, params: data)
expect(flash[:alert]).to be_blank
end
end
Expand All @@ -46,7 +46,7 @@
let!(:topic) { create(:topic) }

it 'authenticates the action' do
delete(:destroy, topic_id: topic.id, id: like.id)
delete(:destroy, params: { topic_id: topic.id, id: like.id })
expect(response).to redirect_to(root_path)
end

Expand All @@ -59,7 +59,7 @@
topic.likes << like

expect {
delete(:destroy, topic_id: topic.id, id: like.id)
delete(:destroy, params: { topic_id: topic.id, id: like.id })
}.to change(Like, :count).by(-1)
expect(response).to redirect_to(topic_path(topic))
end
Expand All @@ -68,7 +68,7 @@
allow_any_instance_of(Topic).to receive_messages(already_liked?: false)

expect {
delete(:destroy, topic_id: topic.id, id: like.id)
delete(:destroy, params: { topic_id: topic.id, id: like.id })
}.to change(Like, :count).by(0)
expect(flash[:alert]).to be_blank
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/locations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
let(:location) { create(:location) }

it 'should render the :show template' do
get :show, id: location
get :show, params: { id: location }
expect(response).to render_template(:show)
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/participants_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

it 'should add a prticipant for current user' do
expect {
post :create, event_id: event.to_param
post :create, params: { event_id: event.to_param }
}.to change(Participant, :count).by(1)
expect(flash[:notice]).to_not be_nil
expect(response).to redirect_to(event)
Expand All @@ -24,7 +24,7 @@

it 'should should alert a duplicate flash' do
expect {
post :create, event_id: event.to_param
post :create, params: { event_id: event.to_param }
}.to change(Participant, :count).by(0)
expect(flash[:alert]).to_not be_nil
expect(response).to redirect_to(event)
Expand All @@ -36,7 +36,7 @@

it 'should should alert a closed flash' do
expect {
post :create, event_id: event.to_param
post :create, params: { event_id: event.to_param }
}.to change(Participant, :count).by(0)
expect(flash[:alert]).to_not be_nil
expect(response).to redirect_to(event)
Expand All @@ -55,7 +55,7 @@
allow(@controller).to receive_messages(current_user: @user)

expect {
delete(:destroy, id: @participant.to_param, event_id: @event.to_param)
delete(:destroy, params: { id: @participant.to_param, event_id: @event.to_param })
}.to change(Participant, :count).by(-1)
expect(response).to redirect_to(@event)
end
Expand All @@ -64,7 +64,7 @@
allow(@controller).to receive_messages(current_user: create(:user))

expect {
delete(:destroy, id: @participant.to_param, event_id: @event.to_param)
delete(:destroy, params: { id: @participant.to_param, event_id: @event.to_param })
}.to change(Participant, :count).by(0)
expect(response).to redirect_to(@event)
end
Expand Down
Loading

0 comments on commit bb37bc5

Please sign in to comment.