Skip to content

Commit

Permalink
モデル名をExtendedTrialからCampaignに変更
Browse files Browse the repository at this point in the history
  • Loading branch information
haruna-tsujita committed Jan 26, 2022
1 parent c80d1c1 commit 9a78d96
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 94 deletions.
26 changes: 13 additions & 13 deletions app/controllers/admin/campaigns_controller.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
# frozen_string_literal: true

class Admin::ExtendedTrialsController < AdminController
before_action :set_extended_trial, only: %i[edit update]
class Admin::CampaignsController < AdminController
before_action :set_campaign, only: %i[edit update]
def new
@extended_trial = ExtendedTrial.new(start_at: Time.current.beginning_of_day)
@campaign = Campaign.new(start_at: Time.current.beginning_of_day)
end

def create
@extended_trial = ExtendedTrial.new(extended_trial_params)
if @extended_trial.save
redirect_to admin_extended_trials_path, notice: 'お試し延長を作成しました。'
@campaign = Campaign.new(campaign_params)
if @campaign.save
redirect_to admin_campaigns_path, notice: 'お試し延長を作成しました。'
else
render :new
end
end

def index
@extended_trials = ExtendedTrial.order(end_at: :desc)
@campaigns = Campaign.order(end_at: :desc)
end

def edit; end

def update
if @extended_trial.update(extended_trial_params)
redirect_to admin_extended_trials_path, notice: 'お試し延長を更新しました。'
if @campaign.update(campaign_params)
redirect_to admin_campaigns_path, notice: 'お試し延長を更新しました。'
else
render :edit
end
end

private

def set_extended_trial
@extended_trial = ExtendedTrial.find(params[:id])
def set_campaign
@campaign = Campaign.find(params[:id])
end

def extended_trial_params
params.require(:extended_trial).permit(:start_at, :end_at, :title)
def campaign_params
params.require(:campaign).permit(:start_at, :end_at, :title)
end
end
16 changes: 8 additions & 8 deletions app/models/campaign.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class ExtendedTrial < ApplicationRecord
class Campaign < ApplicationRecord
validates :start_at, presence: true
validates :end_at, presence: true
validates :title, presence: true
Expand All @@ -9,17 +9,17 @@ class ExtendedTrial < ApplicationRecord
validate :end_at_be_greater_than_start_at
end

def self.recently_extended_trial
extended_trial = ExtendedTrial.order(end_at: :desc).first
return if extended_trial.nil?
def self.recently_campaign
campaign = Campaign.order(end_at: :desc).first
return if campaign.nil?

extended_trial.start_at..extended_trial.end_at
campaign.start_at..campaign.end_at
end

def self.today_is_extended_trial?
return if recently_extended_trial.nil?
def self.today_is_campaign?
return if recently_campaign.nil?

recently_extended_trial.cover?(Time.zone.today)
recently_campaign.cover?(Time.zone.today)
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class User < ApplicationRecord
.select('users.*', :completed_at)
.where('completed_at <= ?', 2.weeks.ago.end_of_day)
}
scope :extended_trial, -> { where(created_at: ExtendedTrial.recently_extended_trial) }
scope :campaign, -> { where(created_at: Campaign.recently_campaign) }
columns_for_keyword_search(
:login_name,
:name,
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/_admin_page_tabs.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
class: "page-tabs__item-link #{current_link(/^admin-companies/)}"
li.page-tabs__item
= link_to 'お試し延長',
admin_extended_trials_path,
class: "page-tabs__item-link #{current_link(/^admin-extended_trials/)}"
admin_campaigns_path,
class: "page-tabs__item-link #{current_link(/^admin-campaigns/)}"
6 changes: 3 additions & 3 deletions app/views/admin/campaigns/_form.html.slim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
= form_with model: [:admin, @extended_trial], local: true, class: 'form', html: { name: 'extended_trial' } do |f|
= render 'errors', object: @extended_trial
= form_with model: [:admin, @campaign], local: true, class: 'form', html: { name: 'campaign' } do |f|
= render 'errors', object: @campaign
.form__items
.form__items-inner
.form-item
Expand All @@ -17,4 +17,4 @@
button.a-button.is-lg.is-warning.is-block
| 内容を保存
li.form-actions__item.is-sub
= link_to 'キャンセル', admin_extended_trials_path, class: 'a-button is-md is-secondary is-block'
= link_to 'キャンセル', admin_campaigns_path, class: 'a-button is-md is-secondary is-block'
4 changes: 2 additions & 2 deletions app/views/admin/campaigns/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ header.page-header
.page-header-actions
.page-header-actions__items
.page-header-actions__item
= link_to admin_extended_trials_path, class: 'a-button is-md is-secondary is-block' do
= link_to admin_campaigns_path, class: 'a-button is-md is-secondary is-block' do
| お試し延長編集

.page-tools
= render 'admin/admin_page_tabs'

.page-body
.container
= render 'form', extended_trial: @extended_trial
= render 'form', campaign: @campaign
18 changes: 9 additions & 9 deletions app/views/admin/campaigns/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ header.page-header
.page-header-actions
.page-header-actions__items
.page-header-actions__item
= link_to new_admin_extended_trial_path, class: 'a-button is-md is-secondary is-block' do
= link_to new_admin_campaign_path, class: 'a-button is-md is-secondary is-block' do
i.fa.fa-plus
| お試し期間延長 作成

Expand All @@ -32,20 +32,20 @@ header.page-header
th.admin-table__label
| 操作
tbody.admin-table__items
- @extended_trials.each do |extended_trial|
tr.admin-table__item(id="extended_trial_#{extended_trial.id}")
- @campaigns.each do |campaign|
tr.admin-table__item(id="campaign_#{campaign.id}")
td.admin-table__item-value
- if (extended_trial.end_at..nil).cover? Time.zone.now
- if (campaign.end_at..nil).cover? Time.zone.now
| 終了
td.admin-table__item-value
= extended_trial.title
= campaign.title
td.admin-table__item-value
| #{l extended_trial.start_at}
| #{l campaign.start_at}
td.admin-table__item-value
| #{l extended_trial.end_at}
| #{l campaign.end_at}
td.admin-table__item-value.is-text-align-center
ul.is-inline-buttons
li
- if (nil..extended_trial.end_at).cover? Time.zone.now
= link_to edit_admin_extended_trial_path(extended_trial), class: 'a-button is-sm is-secondary is-icon' do
- if (nil..campaign.end_at).cover? Time.zone.now
= link_to edit_admin_campaign_path(campaign), class: 'a-button is-sm is-secondary is-icon' do
i.fas.fa-pen
4 changes: 2 additions & 2 deletions app/views/admin/campaigns/new.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ header.page-header
.page-header-actions
.page-header-actions__items
.page-header-actions__item
= link_to admin_extended_trials_path, class: 'a-button is-md is-secondary is-block' do
= link_to admin_campaigns_path, class: 'a-button is-md is-secondary is-block' do
| お試し延長一覧

.page-tools
= render 'admin/admin_page_tabs'

.page-body
.container
= render 'form', extended_trial: @extended_trial
= render 'form', campaign: @campaign
2 changes: 1 addition & 1 deletion app/views/admin/users/_nav.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
nav.tab-nav.is-in-tab
.container.is-padding-horizontal-0-sm-down
ul.tab-nav__items
- %w[all student_and_trainee inactive retired graduate adviser mentor trainee year_end_party extended_trial].each do |target|
- %w[all student_and_trainee inactive retired graduate adviser mentor trainee year_end_party campaign].each do |target|
li.tab-nav__item
= link_to t("target.#{target}"), admin_users_path(target: target), class: (@target == target ? ['is-active'] : []) << 'tab-nav__item-link'
2 changes: 1 addition & 1 deletion app/views/card/_notice.html.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.form-notice
p
| クレジットカード登録日を含む
= ExtendedTrial.today_is_extended_trial? ? '7日間' : '3日間'
= Campaign.today_is_campaign? ? '7日間' : '3日間'
| はお試し期間です。お試し期間の間に退会をすれば課金されることはありません
- if current_user
| (#{link_to '退会はこちらから', new_retirement_path})。
Expand Down
2 changes: 1 addition & 1 deletion app/views/home/_welcome_message.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
| この度はフィヨルドブートキャンプに入会いただきありがとうございます。
br
| 入会から
= ExtendedTrial.today_is_extended_trial? ? '7日間(168時間)' : '3日間(72時間)'
= Campaign.today_is_campaign? ? '7日間(168時間)' : '3日間(72時間)'
/ Issue3910の段階では、ユーザーに対して「現在お試し延長が適用中か?」という情報は持たせていないので、単純にサイトがキャンペーン中かどうかで分岐しています。
/ 上記の理由は、お試しの日数が3日間から◯日間に増えるという部分が適用外となっているからです。
/ そのため、ユーザーにとってお試し延長が適用されている期間であっても、キャンペーン自体の期間が終了すると、表示が3日間に戻る仕様になっています。
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/new.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
.a-card
header.auth-form__header
h1.auth-form__title = title
= '現在、お試し期間の延長が適用されています' if ExtendedTrial.today_is_extended_trial?
= '現在、お試し期間の延長が適用されています' if Campaign.today_is_campaign?
.auth-form__body
= render 'form', from: :new, url: users_path, user: @user
footer.auth-form__footer
Expand Down
2 changes: 1 addition & 1 deletion app/views/welcome/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

= render 'welcome/main_visual'
.welcome-sections
= render 'welcome/campaign' if ExtendedTrial.today_is_extended_trial?
= render 'welcome/campaign' if Campaign.today_is_campaign?
= render 'welcome/about'
= render 'welcome/pricing'
= render 'welcome/tutorials'
Expand Down
20 changes: 10 additions & 10 deletions app/views/welcome/pricing.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
h2.welcome-small-sections__title
= image_tag 'pjord-face.svg',
class: 'welcome-small-sections__title-icon'
= ExtendedTrial.today_is_extended_trial? ? 'お試し延長中につき、7日間' : '3日間'
= Campaign.today_is_campaign? ? 'お試し延長中につき、7日間' : '3日間'
| のお試し期間
.welcome-section__description
p
| 月額29,800円は決して安い金額ではありません。
| 自分は本当にフィヨルドブートキャンプを使うべきかを判断するために
= ExtendedTrial.today_is_extended_trial? ? '7日間' : '3日間'
= Campaign.today_is_campaign? ? '7日間' : '3日間'
| のお試し期間を用意しています。
| その
= ExtendedTrial.today_is_extended_trial? ? '7日間' : '3日間'
= Campaign.today_is_campaign? ? '7日間' : '3日間'
| 、がっつりフィヨルドブートキャンプを見たり使ったりして判断してください。
| お試し期間の間に退会をしないと料金が請求されてしまうのでご注意ください。
.welcome-small-section
Expand All @@ -49,20 +49,20 @@
.welcome-section__description
p
| 厳密にはお試し期間は
= ExtendedTrial.today_is_extended_trial? ? '168時間(7日間)' : '72時間(3日間)'
= Campaign.today_is_campaign? ? '168時間(7日間)' : '72時間(3日間)'
| になります。
| 例えば7月20日10時10分10秒にフィヨルドブートキャンプを利用開始したとすると、
| そこから
= ExtendedTrial.today_is_extended_trial? ? '7日後の7月27日' : '3日後の7月23日'
= Campaign.today_is_campaign? ? '7日後の7月27日' : '3日後の7月23日'
| 10時10分9秒がお試し期間終了のタイミングになります。
| その後7月
= ExtendedTrial.today_is_extended_trial? ? '27' : '23'
= Campaign.today_is_campaign? ? '27' : '23'
| 日10時10分10秒に最初の1ヶ月分の料金が引き落とされます。
table.welcome-trial-period-table.is-hidden-sm-down
tr
th 7月20日10時10分10秒
th.trial_end = ExtendedTrial.today_is_extended_trial? ? '7月27日10時10分9秒' : '7月23日10時10分9秒'
th = ExtendedTrial.today_is_extended_trial? ? '7月27日10時10分10秒' : '7月23日10時10分10秒'
th.trial_end = Campaign.today_is_campaign? ? '7月27日10時10分9秒' : '7月23日10時10分9秒'
th = Campaign.today_is_campaign? ? '7月27日10時10分10秒' : '7月23日10時10分10秒'
tr
td お試し期間
td.trial_end
Expand All @@ -76,11 +76,11 @@
th 7月20日10時10分10秒
td お試し期間
tr
th.trial_end = ExtendedTrial.today_is_extended_trial? ? '7月27日10時10分9秒' : '7月23日10時10分9秒'
th.trial_end = Campaign.today_is_campaign? ? '7月27日10時10分9秒' : '7月23日10時10分9秒'
td.trial_end
| お試し期間終了時刻
br
| 無料退会期限
tr
th = ExtendedTrial.today_is_extended_trial? ? '7月27日10時10分10秒' : '7月23日10時10分10秒'
th = Campaign.today_is_campaign? ? '7月27日10時10分10秒' : '7月23日10時10分10秒'
td 初回引き落とし
6 changes: 3 additions & 3 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ja:
event: イベント
memo: メモ
reference_book: 参考書籍
extended_trial: お試し延長
campaign: お試し延長
attributes:
user:
login_name: アカウント
Expand Down Expand Up @@ -179,7 +179,7 @@ ja:
must_read: 必読
cover: 表紙画像
description: 説明
extended_trial:
campaign:
start_at: 開始日時
end_at: 終了日時
title: タイトル
Expand Down Expand Up @@ -235,7 +235,7 @@ ja:
self_assigned_no_replied: 未返信
unchecked_no_replied: 未返信
unchecked_all: 全て
extended_trial: お試し延長
campaign: お試し延長
watch:
all: すべて
true: コメントあり
Expand Down
2 changes: 1 addition & 1 deletion config/routes/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
end
resources :categories, except: %i(show)
resources :courses, except: %i(show destroy)
resources :extended_trials, only: %i(new create index edit update)
resources :campaigns, only: %i(new create index edit update)
end
end
2 changes: 1 addition & 1 deletion db/migrate/20220121035938_create_extended_trials.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class CreateExtendedTrials < ActiveRecord::Migration[6.1]
def change
create_table :extended_trials do |t|
create_table :campaigns do |t|
t.datetime :start_at, null: false
t.datetime :end_at, null: false
t.string :title, null: false
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
t.index ["user_id"], name: "index_events_on_user_id"
end

create_table "extended_trials", force: :cascade do |t|
create_table "campaigns", force: :cascade do |t|
t.datetime "start_at", null: false
t.datetime "end_at", null: false
t.string "title", null: false
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/campaigns.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

extended_trial1:
campaign1:
start_at: <%= Time.zone.today %>
end_at: <%= Time.zone.today + 3.days %>
title: 'GW特別キャンペーン'

extended_trial2:
campaign2:
start_at: <%= Time.zone.today - 1.months %>
end_at: <%= Time.zone.today - 1.months + 7.days %>
title: 'GWスペシャルキャンペーン'
18 changes: 9 additions & 9 deletions test/models/campaign_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

require 'test_helper'

class ExtendedTrialTest < ActiveSupport::TestCase
test 'recently extended_trial' do
later_extended_trial = extended_trials(:extended_trial2)
earlier_extended_trial = extended_trials(:extended_trial1)
class CampaignTest < ActiveSupport::TestCase
test 'recently campaign' do
later_campaign = campaigns(:campaign2)
earlier_campaign = campaigns(:campaign1)

assert_equal ExtendedTrial.recently_extended_trial, earlier_extended_trial.start_at..earlier_extended_trial.end_at
assert_not_equal ExtendedTrial.recently_extended_trial, later_extended_trial.start_at..later_extended_trial.end_at
assert_equal Campaign.recently_campaign, earlier_campaign.start_at..earlier_campaign.end_at
assert_not_equal Campaign.recently_campaign, later_campaign.start_at..later_campaign.end_at
end

test 'today is extended_trial?' do
extended_trial = extended_trials(:extended_trial1)
assert_equal ExtendedTrial.today_is_extended_trial?, (extended_trial.start_at..extended_trial.end_at).cover?(Time.zone.today)
test 'today is campaign?' do
campaign = campaigns(:campaign1)
assert_equal Campaign.today_is_campaign?, (campaign.start_at..campaign.end_at).cover?(Time.zone.today)
end
end
Loading

0 comments on commit 9a78d96

Please sign in to comment.