mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
remove rails find_by_* helpers
This commit is contained in:
parent
cc06bcab85
commit
c13f640e81
@ -20,7 +20,7 @@ class API::CouponsController < API::ApiController
|
||||
end
|
||||
|
||||
def validate
|
||||
@coupon = Coupon.find_by_code(params[:code])
|
||||
@coupon = Coupon.find_by(code: params[:code])
|
||||
if @coupon.nil?
|
||||
render json: {status: 'rejected'}, status: :not_found
|
||||
else
|
||||
@ -60,7 +60,7 @@ class API::CouponsController < API::ApiController
|
||||
def send_to
|
||||
authorize Coupon
|
||||
|
||||
@coupon = Coupon.find_by_code(params[:coupon_code])
|
||||
@coupon = Coupon.find_by(code: params[:coupon_code])
|
||||
if @coupon.nil?
|
||||
render json: {error: "no coupon with code #{params[:coupon_code]}"}, status: :not_found
|
||||
else
|
||||
|
@ -145,7 +145,7 @@ class API::MembersController < API::ApiController
|
||||
|
||||
token = params.require(:user).permit(:auth_token)[:auth_token]
|
||||
|
||||
@account = User.find_by_auth_token(token)
|
||||
@account = User.find_by(auth_token: token)
|
||||
if @account
|
||||
@flow_worker = MembersProcessor.new(@account)
|
||||
begin
|
||||
|
@ -41,7 +41,7 @@ class API::ProjectsController < API::ApiController
|
||||
end
|
||||
|
||||
def collaborator_valid
|
||||
project_user = ProjectUser.find_by_valid_token params[:valid_token]
|
||||
project_user = ProjectUser.find_by(valid_token: params[:valid_token])
|
||||
if project_user
|
||||
project_user.update(is_valid: true, valid_token: '')
|
||||
redirect_to "/#!/projects/#{project_user.project.id}" and return
|
||||
|
@ -22,7 +22,7 @@ class API::StatisticsController < API::ApiController
|
||||
|
||||
# run additional custom aggregations, if any
|
||||
if statistic_type and start_date and end_date
|
||||
stat_index = StatisticIndex.find_by_es_type_key("#{path}")
|
||||
stat_index = StatisticIndex.find_by(es_type_key: "#{path}")
|
||||
stat_type = StatisticType.where(statistic_index_id: stat_index.id, key: statistic_type).first
|
||||
client = Elasticsearch::Model.client
|
||||
stat_type.statistic_custom_aggregations.each do |custom|
|
||||
|
@ -134,7 +134,7 @@ class Reservation < ActiveRecord::Base
|
||||
|
||||
# === Coupon ===
|
||||
unless coupon_code.nil?
|
||||
cp = Coupon.find_by_code(coupon_code)
|
||||
cp = Coupon.find_by(code: coupon_code)
|
||||
if not cp.nil? and cp.status(user.id) == 'active'
|
||||
@coupon = cp
|
||||
total = invoice.invoice_items.map(&:amount).map(&:to_i).reduce(:+)
|
||||
@ -421,7 +421,7 @@ class Reservation < ActiveRecord::Base
|
||||
total = invoice.invoice_items.map(&:amount).map(&:to_i).reduce(:+)
|
||||
|
||||
unless coupon_code.nil?
|
||||
cp = Coupon.find_by_code(coupon_code)
|
||||
cp = Coupon.find_by(code: coupon_code)
|
||||
if not cp.nil? and cp.status(user.id) == 'active'
|
||||
total = total - (total * cp.percent_off / 100.0)
|
||||
self.invoice.coupon_id = cp.id
|
||||
|
@ -25,7 +25,7 @@ class Subscription < ActiveRecord::Base
|
||||
invoice_items = []
|
||||
|
||||
unless coupon_code.nil?
|
||||
cp = Coupon.find_by_code(coupon_code)
|
||||
cp = Coupon.find_by(code: coupon_code)
|
||||
if not cp.nil? and cp.status(user.id) == 'active'
|
||||
@coupon = cp
|
||||
total = plan.amount
|
||||
@ -159,7 +159,7 @@ class Subscription < ActiveRecord::Base
|
||||
total = plan.amount
|
||||
|
||||
unless coupon_code.nil?
|
||||
cp = Coupon.find_by_code(coupon_code)
|
||||
cp = Coupon.find_by(code: coupon_code)
|
||||
if not cp.nil? and cp.status(user.id) == 'active'
|
||||
@coupon = cp
|
||||
coupon_id = cp.id
|
||||
|
@ -131,7 +131,7 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
json.machine_credits machine_credits do |mc|
|
||||
json.machine_id mc.creditable_id
|
||||
json.hours_used mc.users_credits.find_by_user_id(id).hours_used
|
||||
json.hours_used mc.users_credits.find_by(user_id: id).hours_used
|
||||
end
|
||||
json.last_sign_in_at last_sign_in_at.iso8601 if last_sign_in_at
|
||||
end
|
||||
|
@ -54,7 +54,7 @@ json.array!(@members) do |member|
|
||||
|
||||
json.machine_credits member.machine_credits do |mc|
|
||||
json.machine_id mc.creditable_id
|
||||
json.hours_used mc.users_credits.find_by_user_id(member.id).hours_used
|
||||
json.hours_used mc.users_credits.find_by(user_id: member.id).hours_used
|
||||
end if attribute_requested?(@requested_attributes, 'credits') or attribute_requested?(@requested_attributes, 'machine_credits')
|
||||
|
||||
json.tags member.tags do |t|
|
||||
|
@ -69,7 +69,7 @@ json.training_credits @member.training_credits do |tc|
|
||||
end
|
||||
json.machine_credits @member.machine_credits do |mc|
|
||||
json.machine_id mc.creditable_id
|
||||
json.hours_used mc.users_credits.find_by_user_id(@member.id).hours_used
|
||||
json.hours_used mc.users_credits.find_by(user_id: @member.id).hours_used
|
||||
end
|
||||
json.last_sign_in_at @member.last_sign_in_at.iso8601 if @member.last_sign_in_at
|
||||
json.all_projects @member.all_projects do |project|
|
||||
|
@ -10,7 +10,7 @@ json.user do
|
||||
end
|
||||
json.machine_credits @reservation.user.machine_credits do |mc|
|
||||
json.machine_id mc.creditable_id
|
||||
json.hours_used mc.users_credits.find_by_user_id(@reservation.user_id).hours_used
|
||||
json.hours_used mc.users_credits.find_by(user_id: @reservation.user_id).hours_used
|
||||
end
|
||||
end
|
||||
json.message @reservation.message
|
||||
|
@ -16,7 +16,7 @@ class ReservationReminderWorker
|
||||
already_sent = Notification.where(
|
||||
attached_object_type: Reservation.name,
|
||||
attached_object_id: r.id,
|
||||
notification_type_id: NotificationType.find_by_name('notify_member_reservation_reminder')
|
||||
notification_type_id: NotificationType.find_by(name: 'notify_member_reservation_reminder')
|
||||
).count
|
||||
unless already_sent > 0
|
||||
NotificationCenter.call type: 'notify_member_reservation_reminder',
|
||||
|
@ -28,7 +28,7 @@ class MigrateEventReducedAmountToPriceCategory < ActiveRecord::Migration
|
||||
end
|
||||
|
||||
def down
|
||||
pc = PriceCategory.find_by_name(I18n.t('price_category.reduced_fare'))
|
||||
pc = PriceCategory.find_by(name: I18n.t('price_category.reduced_fare'))
|
||||
EventPriceCategory.where(price_category_id: pc.id).each do |epc|
|
||||
epc.event.update_column(:reduced_amount, epc.amount)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
class InsertCustomAggregations < ActiveRecord::Migration
|
||||
def up
|
||||
# available reservations hours for machines
|
||||
machine = StatisticIndex.find_by_es_type_key('machine')
|
||||
machine = StatisticIndex.find_by(es_type_key: 'machine')
|
||||
machine_hours = StatisticType.find_by(key: 'hour', statistic_index_id: machine.id)
|
||||
|
||||
available_hours = StatisticCustomAggregation.new({
|
||||
@ -14,7 +14,7 @@ class InsertCustomAggregations < ActiveRecord::Migration
|
||||
available_hours.save!
|
||||
|
||||
# available training tickets
|
||||
training = StatisticIndex.find_by_es_type_key('training')
|
||||
training = StatisticIndex.find_by(es_type_key: 'training')
|
||||
training_bookings = StatisticType.find_by(key: 'booking', statistic_index_id: training.id)
|
||||
|
||||
available_tickets = StatisticCustomAggregation.new({
|
||||
@ -29,12 +29,12 @@ class InsertCustomAggregations < ActiveRecord::Migration
|
||||
|
||||
def down
|
||||
|
||||
machine = StatisticIndex.find_by_es_type_key('machine')
|
||||
machine = StatisticIndex.find_by(es_type_key: 'machine')
|
||||
machine_hours = StatisticType.find_by(key: 'hour', statistic_index_id: machine.id)
|
||||
|
||||
StatisticCustomAggregation.where(field: 'available_hours', statistic_type_id: machine_hours.id).first.destroy!
|
||||
|
||||
training = StatisticIndex.find_by_es_type_key('training')
|
||||
training = StatisticIndex.find_by(es_type_key: 'training')
|
||||
training_bookings = StatisticType.find_by(key: 'booking', statistic_index_id: training.id)
|
||||
|
||||
StatisticCustomAggregation.where(field: 'available_tickets', statistic_type_id: training_bookings.id).first.destroy!
|
||||
|
@ -2,7 +2,7 @@ namespace :fablab do
|
||||
# desc "Get all stripe plans and create in fablab app"
|
||||
# task stripe_plan: :environment do
|
||||
# Stripe::Plan.all.data.each do |plan|
|
||||
# unless Plan.find_by_stp_plan_id(plan.id)
|
||||
# unless Plan.find_by(stp_plan_id: plan.id)
|
||||
# group = Group.friendly.find(plan.id.split('-').first)
|
||||
# if group
|
||||
# Plan.create(stp_plan_id: plan.id, name: plan.name, amount: plan.amount, interval: plan.interval, group_id: group.id, skip_create_stripe_plan: true)
|
||||
|
@ -3,7 +3,7 @@ class AdminsTest < ActionDispatch::IntegrationTest
|
||||
# Called before every test method runs. Can be used
|
||||
# to set up fixture information.
|
||||
def setup
|
||||
@admin = User.find_by_username('admin')
|
||||
@admin = User.find_by(username: 'admin')
|
||||
login_as(@admin, scope: :user)
|
||||
end
|
||||
|
||||
|
@ -20,7 +20,7 @@ module Availabilities
|
||||
end
|
||||
|
||||
test 'get machine availabilities as admin' do
|
||||
m = Machine.find_by_slug('decoupeuse-vinyle')
|
||||
m = Machine.find_by(slug: 'decoupeuse-vinyle')
|
||||
|
||||
get "/api/availabilities/machines/#{m.id}"
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
class Availabilities::AsUserTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
user = User.find_by_username('kdumas')
|
||||
user = User.find_by(username: 'kdumas')
|
||||
login_as(user, scope: :user)
|
||||
end
|
||||
|
||||
test 'get machine availabilities as user' do
|
||||
m = Machine.find_by_slug('decoupeuse-vinyle')
|
||||
m = Machine.find_by(slug: 'decoupeuse-vinyle')
|
||||
|
||||
get "/api/availabilities/machines/#{m.id}"
|
||||
|
||||
|
@ -64,7 +64,7 @@ class EventsTest < ActionDispatch::IntegrationTest
|
||||
post '/api/reservations',
|
||||
{
|
||||
reservation: {
|
||||
user_id: User.find_by_username('pdurand').id,
|
||||
user_id: User.find_by(username: 'pdurand').id,
|
||||
reservable_id: e.id,
|
||||
reservable_type: 'Event',
|
||||
nb_reserve_places: 2,
|
||||
@ -159,7 +159,7 @@ class EventsTest < ActionDispatch::IntegrationTest
|
||||
post '/api/reservations',
|
||||
{
|
||||
reservation: {
|
||||
user_id: User.find_by_username('lseguin').id,
|
||||
user_id: User.find_by(username: 'lseguin').id,
|
||||
reservable_id: e.id,
|
||||
reservable_type: 'Event',
|
||||
nb_reserve_places: 4,
|
||||
|
@ -3,12 +3,12 @@ module Subscriptions
|
||||
|
||||
|
||||
setup do
|
||||
@admin = User.find_by_username('admin')
|
||||
@admin = User.find_by(username: 'admin')
|
||||
login_as(@admin, scope: :user)
|
||||
end
|
||||
|
||||
test "admin successfully takes a subscription for a user" do
|
||||
user = User.find_by_username('jdupond')
|
||||
user = User.find_by(username: 'jdupond')
|
||||
plan = Plan.find_by(group_id: user.group.id, type: 'Plan', base_name: 'Mensuel')
|
||||
|
||||
VCR.use_cassette("subscriptions_admin_create_success") do
|
||||
@ -40,7 +40,7 @@ module Subscriptions
|
||||
assert_equal user.subscription.plan.training_credit_nb, plan.training_credit_nb, 'trainings credits were not allocated'
|
||||
|
||||
# Check that the user benefit from prices of his plan
|
||||
printer = Machine.find_by_slug('imprimante-3d')
|
||||
printer = Machine.find_by(slug: 'imprimante-3d')
|
||||
assert_equal 15, (printer.prices.find_by(group_id: user.group_id, plan_id: user.subscription.plan_id).amount / 100), 'machine hourly price does not match'
|
||||
|
||||
# Check notification was sent to the user
|
||||
|
@ -2,7 +2,7 @@ class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
|
||||
|
||||
|
||||
setup do
|
||||
@user = User.find_by_username('jdupond')
|
||||
@user = User.find_by(username: 'jdupond')
|
||||
login_as(@user, scope: :user)
|
||||
end
|
||||
|
||||
@ -38,7 +38,7 @@ class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
|
||||
assert_equal @user.subscription.plan.training_credit_nb, plan.training_credit_nb, 'trainings credits were not allocated'
|
||||
|
||||
# Check that the user benefit from prices of his plan
|
||||
printer = Machine.find_by_slug('imprimante-3d')
|
||||
printer = Machine.find_by(slug: 'imprimante-3d')
|
||||
assert_equal 15, (printer.prices.find_by(group_id: @user.group_id, plan_id: @user.subscription.plan_id).amount / 100), 'machine hourly price does not match'
|
||||
|
||||
# Check notifications were sent for every admins
|
||||
@ -118,7 +118,7 @@ class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
|
||||
assert_equal @vlonchamp.subscription.plan.training_credit_nb, plan.training_credit_nb, 'trainings credits were not allocated'
|
||||
|
||||
# Check that the user benefit from prices of his plan
|
||||
printer = Machine.find_by_slug('imprimante-3d')
|
||||
printer = Machine.find_by(slug: 'imprimante-3d')
|
||||
assert_equal 10, (printer.prices.find_by(group_id: @vlonchamp.group_id, plan_id: @vlonchamp.subscription.plan_id).amount / 100), 'machine hourly price does not match'
|
||||
|
||||
# Check notifications were sent for every admins
|
||||
|
@ -1,13 +1,13 @@
|
||||
class Subscriptions::RenewAsAdminTest < ActionDispatch::IntegrationTest
|
||||
|
||||
setup do
|
||||
@admin = User.find_by_username('admin')
|
||||
@admin = User.find_by(username: 'admin')
|
||||
login_as(@admin, scope: :user)
|
||||
end
|
||||
|
||||
test 'admin successfully renew a subscription before it has ended' do
|
||||
|
||||
user = User.find_by_username('kdumas')
|
||||
user = User.find_by(username: 'kdumas')
|
||||
plan = Plan.find_by(base_name: 'Mensuel tarif réduit')
|
||||
|
||||
VCR.use_cassette("subscriptions_admin_renew_success") do
|
||||
@ -38,7 +38,7 @@ class Subscriptions::RenewAsAdminTest < ActionDispatch::IntegrationTest
|
||||
assert_equal user.subscription.plan.training_credit_nb, plan.training_credit_nb, 'trainings credits were not allocated'
|
||||
|
||||
# Check that the user benefit from prices of his plan
|
||||
printer = Machine.find_by_slug('imprimante-3d')
|
||||
printer = Machine.find_by(slug: 'imprimante-3d')
|
||||
assert_equal 10, (printer.prices.find_by(group_id: user.group_id, plan_id: user.subscription.plan_id).amount / 100), 'machine hourly price does not match'
|
||||
|
||||
# Check notification was sent to the user
|
||||
|
@ -2,7 +2,7 @@ class Subscriptions::RenewAsUserTest < ActionDispatch::IntegrationTest
|
||||
|
||||
|
||||
setup do
|
||||
@user = User.find_by_username('lseguin')
|
||||
@user = User.find_by(username: 'lseguin')
|
||||
login_as(@user, scope: :user)
|
||||
end
|
||||
|
||||
|
@ -24,7 +24,7 @@ class WalletsTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'admin can get wallet by user id' do
|
||||
@admin = User.find_by_username('admin')
|
||||
@admin = User.find_by(username: 'admin')
|
||||
login_as(@admin, scope: :user)
|
||||
@user1 = User.first
|
||||
get "/api/wallet/by_user/#{@user1.id}"
|
||||
|
@ -7,7 +7,7 @@ class CouponTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'expired coupon must return the proper status' do
|
||||
c = Coupon.find_by_code('XMAS10')
|
||||
c = Coupon.find_by(code: 'XMAS10')
|
||||
assert c.status == 'expired'
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user