From ea93a4c456048cb44b6f0a73fb1a765d5c23edaf Mon Sep 17 00:00:00 2001 From: benji Date: Tue, 3 Mar 2015 20:11:50 +0100 Subject: [PATCH] Remove ugly constraint --- Gemfile | 2 ++ Gemfile.lock | 3 +++ app/constraints/user_homepage_constraint.rb | 5 ----- config/routes.rb | 10 +++++++--- test/test_helper.rb | 3 +++ 5 files changed, 15 insertions(+), 8 deletions(-) delete mode 100644 app/constraints/user_homepage_constraint.rb diff --git a/Gemfile b/Gemfile index 8a6238b..c62e729 100644 --- a/Gemfile +++ b/Gemfile @@ -70,3 +70,5 @@ gem 'paper_trail', '~> 4.0.0.beta' gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] gem 'coveralls', require: false + +gem "codeclimate-test-reporter", group: :test, require: nil diff --git a/Gemfile.lock b/Gemfile.lock index 15c5db6..22c975d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -71,6 +71,8 @@ GEM activesupport (>= 3.0) cocaine (0.5.5) climate_control (>= 0.0.3, < 1.0) + codeclimate-test-reporter (0.4.7) + simplecov (>= 0.7.1, < 1.0.0) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -240,6 +242,7 @@ DEPENDENCIES capistrano (~> 3.1) capistrano-rails (~> 1.1) capistrano-rvm + codeclimate-test-reporter coffee-rails (~> 4.0.0) coveralls devise diff --git a/app/constraints/user_homepage_constraint.rb b/app/constraints/user_homepage_constraint.rb deleted file mode 100644 index ce78952..0000000 --- a/app/constraints/user_homepage_constraint.rb +++ /dev/null @@ -1,5 +0,0 @@ -class UserHomepageConstraint < Struct.new(:role) - def matches?(request) - role == request.env['warden'].user.koelkast? - end -end diff --git a/config/routes.rb b/config/routes.rb index 2f5a7ab..4bfcba3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,9 +5,13 @@ Rails.application.routes.draw do unauthenticated :user do root to: 'devise/sessions#new' end - authenticated :user do - root to: 'orders#overview', constraints: UserHomepageConstraint.new(true), as: 'koelkast_root' - root to: 'users#show', constraints: UserHomepageConstraint.new(false), as: 'user_root' + + authenticated :user, ->(u) { u.koelkast? } do + root to: 'orders#overview', as: :koelkast_root + end + + authenticated :user, ->(u) { !u.koelkast? } do + root to: 'users#show', as: :user_root end end diff --git a/test/test_helper.rb b/test/test_helper.rb index cbd1a50..cf9b45e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,6 @@ +require "codeclimate-test-reporter" +CodeClimate::TestReporter.start + require 'coveralls' Coveralls.wear!