Upgrade to Pro — share decks privately, control downloads, hide ads and more …

yawaraka zouzei

uvb_76
December 14, 2019

yawaraka zouzei

uvb_76

December 14, 2019
Tweet

More Decks by uvb_76

Other Decks in Programming

Transcript

  1. %#Ͱ੫཰Λදݱ͍ͨ͠ "id" "kind" "rate" "started_at" "expired_at" "created_at" "updated_at" 1 0

    0.08 "2014-03-31 15:00:00" "2019-09-30 14:59:59.999999" "2019-07-16 09:44:39.516075" "2019-07-16 09:44:39.516075" 2 0 0.1 "2019-09-30 15:00:00" NULL "2019-07-16 09:44:39.519505" "2019-07-16 09:44:39.519505" 3 1 0.08 "2019-09-30 15:00:00" NULL "2019-07-16 09:44:39.521575" "2019-07-16 09:44:39.521575" UBYFTςʔϒϧര஀ ࠓճ͸ͪ͜ΒΛ࠾༻
  2. ࣮૷ class Tax < ApplicationRecord enum kind: { ordinary: 0,

    reduced: 1 } class << self def ordinary_rate(time = Time.current) # 10%ͷ੫཰༻ ordinary.where('started_at <= ?', time).order(started_at: :desc).first.rate end def reduced_rate(time = Time.current) # 8%(ܰݮ੫཰)༻ reduced.where('started_at <= ?', time).order(started_at: :desc).first.rate end end end
  3. 34QFDͰςετ࣌ࠁΛม͑Δ # spec/support/traveling.rb RSpec.configure do |config| config.include ActiveSupport::Testing::TimeHelpers config.around(:each, :travel_to)

    do |example| travel_to(example.metadata[:travel_to]) do example.run end end end IUUQTSFMJTIBQQDPNSTQFDSTQFD DPSFWEPDTIPPLTBSPVOE
  4. ࢖͍ํ ྫ context '૿੫લͷͱ͖', travel_to: '2019/09/30 23:59:59' do # ੫཰8%Ͱ͋Δ͜ͱΛ֬ೝ͢ΔςετΛ͜͜ʹ͔͘

    end wϒϩοΫͷதͰAUSBWFM@UPA͕ޮ͍ͯศར w !LBKJTIB͞ΜͷΞΠσΞͰ͢ɻ͋Γ͕ͱ͏͍͟͝·͢ɻ