Skip to content

道場を非表示にする仕組みの追加 #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class HomeController < ApplicationController
def show
@dojo_count = Dojo.count
@regions_and_dojos = Dojo.group_by_region
@dojo_count = Dojo.active.count
@regions_and_dojos = Dojo.group_by_region_on_active
end
end
2 changes: 1 addition & 1 deletion app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class StatsController < ApplicationController
def show
@url = request.url
@dojo_count = Dojo.count
@regions_and_dojos = Dojo.group_by_region
@regions_and_dojos = Dojo.group_by_region_on_active

# TODO: 次の静的なDojoの開催数もデータベース上で集計できるようにする
# https://github.com/coderdojo-japan/coderdojo.jp/issues/190
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def full_url(page_url)
def full_description(description)
description = kata_description if @obj && @obj.permalink == "kata"
if description.empty?
"CoderDojo は子どものためのプログラミング道場です。2011年にアイルランドで始まり、全国では#{Dojo::NUM_OF_JAPAN_DOJOS}ヶ所以上、世界では#{Dojo::NUM_OF_COUNTRIES}ヶ国・#{Dojo::NUM_OF_WHOLE_DOJOS}ヶ所で開催されています。" # Default description
"CoderDojo は子どものためのプログラミング道場です。2011年にアイルランドで始まり、全国では#{Dojo.active.count}ヶ所以上、世界では#{Dojo::NUM_OF_COUNTRIES}ヶ国・#{Dojo::NUM_OF_WHOLE_DOJOS}ヶ所で開催されています。" # Default description
else
description
end
Expand Down
6 changes: 5 additions & 1 deletion app/models/dojo.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class Dojo < ApplicationRecord
NUM_OF_COUNTRIES = "85"
NUM_OF_WHOLE_DOJOS = "1,600"
NUM_OF_JAPAN_DOJOS = Dojo.count.to_s
YAML_FILE = Rails.root.join('db', 'dojos.yaml')

belongs_to :prefecture
Expand All @@ -12,6 +11,7 @@ class Dojo < ApplicationRecord
before_save { self.email = self.email.downcase }

scope :default_order, -> { order(prefecture_id: :asc, order: :asc) }
scope :active, -> { where(is_active: true) }

validates :name, presence: true, length: { maximum: 50 }
validates :email, presence: false
Expand All @@ -35,6 +35,10 @@ def group_by_region
eager_load(:prefecture).default_order.group_by { |dojo| dojo.prefecture.region }
end

def group_by_region_on_active
active.group_by_region
end

def aggregatable_annual_count(period)
Hash[
joins(:dojo_event_services)
Expand Down
3 changes: 3 additions & 0 deletions db/dojos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@
description: 埼玉県所沢市小手指にて毎月開催
tags:
- Scratch
is_active: false
- id: 11
order: '112097'
created_at: '2015-05-13'
Expand Down Expand Up @@ -409,6 +410,7 @@
description: 千葉県野田市で不定期開催
tags:
- Scratch
is_active: false
- id: 23
order: '122173'
created_at: '2014-09-22'
Expand Down Expand Up @@ -1104,6 +1106,7 @@
tags:
- Scratch
- ラズベリーパイ
is_active: false
- id: 46
order: '271403'
created_at: '2016-03-22'
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20180604070534_add_is_active_to_dojos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIsActiveToDojos < ActiveRecord::Migration[5.1]
def change
add_column :dojos, :is_active, :boolean, null: false, default: true
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180316062512) do
ActiveRecord::Schema.define(version: 20180604070534) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -36,6 +36,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "prefecture_id"
t.boolean "is_active", default: true, null: false
end

create_table "event_histories", id: :serial, force: :cascade do |t|
Expand Down
1 change: 1 addition & 0 deletions lib/tasks/dojos.rake
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace :dojos do
d.created_at = d.new_record? ? Time.zone.now : dojo['created_at'] || d.created_at
d.updated_at = Time.zone.now
d.prefecture_id = dojo['prefecture_id']
d.is_active = dojo['is_active'].nil? ? true : dojo['is_active']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/rails/rails/blob/375a4143cf5caeb6159b338be824903edfd62836/activemodel/lib/active_model/type/boolean.rb#L17

'false'をtypoしたらtrueが入りそうですけど、RubyのtruthyとTypeCastの仕様だし仕方ないですかね。

Copy link
Member

@yasulab yasulab Jun 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こういう gem あったら使えたりするのかなぁ🤔💭

cf. https://twitter.com/darkdimius/status/1002049138366730240

It's public now: @stripe is building a typechecker for #Ruby with emphasis on scalability and user-friendliness. Currently presenting it at #RubyKaigi with @nelhage and @ptarjan. Try it: https://sorbet.run/ . See it at Tachibana room at #RubyKaigi2018


d.save!
end
Expand Down
1 change: 1 addition & 0 deletions spec/models/dojo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
it { should respond_to(:tags) }

it { should be_valid }
it { expect(Dojo.new.is_active?).to be(true) }

describe "when name is not present" do
before { @dojo.name = " " }
Expand Down