repo_name
stringlengths 6
97
| path
stringlengths 3
341
| text
stringlengths 8
1.02M
|
|---|---|---|
mitixx/abilitysheet
|
app/decorators/sheet_decorator.rb
|
# frozen_string_literal: true
class SheetDecorator < Draper::Decorator
delegate_all
def normal
Static::POWER[object.n_ability].first
end
def hard
Static::POWER[object.h_ability].first
end
def exh
Static::EXH_POWER[object.exh_ability].first
end
def updated_at
return '' unless object.updated_at
object.updated_at.strftime('%Y/%m/%d %H:%M')
end
end
|
mitixx/abilitysheet
|
db/migrate/20191103084533_create_socials.rb
|
<filename>db/migrate/20191103084533_create_socials.rb
class CreateSocials < ActiveRecord::Migration[6.0]
def change
create_table :socials do |t|
t.string :provider
t.json :raw
t.string :secret
t.string :token
t.string :uid
t.bigint :user_id
t.timestamps
t.index %i[user_id provider], unique: true
end
end
end
|
mitixx/abilitysheet
|
app/jobs/ist_sync_job.rb
|
<gh_stars>10-100
# frozen_string_literal: true
class IstSyncJob < ApplicationJob
queue_as :ist
def perform(user)
puts %(#{Time.zone.now} #{user.djname}[#{user.iidxid}] => ist sync start)
user.update_ist
puts %(#{Time.zone.now} #{user.djname}[#{user.iidxid}] => ist sync done)
end
end
|
mitixx/abilitysheet
|
app/decorators/score_decorator.rb
|
# frozen_string_literal: true
class ScoreDecorator < Draper::Decorator
delegate_all
def updated_at
return '' unless object.updated_at
object.updated_at.to_date.strftime
end
end
|
mitixx/abilitysheet
|
spec/models/user_follow_methods_spec.rb
|
<gh_stars>10-100
# frozen_string_literal: true
# == Schema Information
#
# Table name: follows
#
# id :integer not null, primary key
# user_id :integer
# target_user_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
describe User::FollowMethods, type: :model do
describe '#follow' do
before do
(1..12).each do |i|
create(:user, id: i, iidxid: format('0000-%04d', i), username: format('test%d', i))
end
end
context 'ライバル機能を使っていないユーザ同士' do
let(:user) { User.find_by(id: 1) }
let(:target) { User.find_by(id: 2) }
context 'ライバルに登録' do
before { user.follow(target.iidxid) }
it '自身のライバルに追加されている' do
expect(user.follow_users).to include(target)
end
it '相手の逆ライバルに追加されている' do
target.reload
expect(target.follower_users).to include(user)
end
end
describe '既にライバル登録済みのユーザをライバルにしようとする' do
before { user.follow(target.iidxid) }
it 'falseを返す' do
expect(user.follow(target.iidxid)).to eq false
end
it 'ライバル数,逆ライバル数は1のままである' do
target.reload
expect(user.follow_users.count).to eq 1
expect(target.follower_users.count).to eq 1
end
end
end
context '自身がライバルの機能を使っていて,相手は使っていない' do
let(:user) { User.find_by(id: 1) }
let(:target) { User.find_by(id: 2) }
let(:sub) { User.find_by(id: 3) }
before do
user.follow(sub.iidxid)
user.follow(target.iidxid)
end
it '自身のライバルに追加されている' do
expect(user.follow_users).to include(target)
end
it '相手の逆ライバルに追加されている' do
target.reload
expect(target.follower_users).to include(user)
end
end
end
describe '#unfollow' do
before do
(1..12).each { |i| create(:user, id: i, iidxid: format('0000-%04d', i), username: format('test%d', i)) }
end
let(:user) { User.find_by(id: 1) }
let(:target) { User.find_by(id: 2) }
describe 'ライバルに登録し,削除する' do
before do
user.follow(target.iidxid)
user.unfollow(target.iidxid)
end
it 'ユーザのライバルは0である' do
expect(user.follow_users.count).to eq 0
end
it 'ターゲットの逆ライバルは0である' do
target.reload
expect(target.follower_users.count).to eq 0
end
end
describe '登録していないユーザを削除しようとする' do
it 'falseを返す' do
expect(user.unfollow(target.iidxid)).to eq false
end
it 'ユーザのライバルは0である' do
expect(user.follow_users.count).to eq 0
end
it 'ターゲットの逆ライバルは0である' do
target.reload
expect(target.follower_users.count).to eq 0
end
end
end
describe '#following?' do
before do
(1..2).each { |i| create(:user, id: i, iidxid: format('0000-%04d', i), username: format('test%d', i)) }
end
it 'フォローしていればtrueを返す' do
User.find(1).follow(User.find(2).iidxid)
expect(User.find(1).following?(2)).to eq true
end
it 'フォローしていればいなければfalseを返す' do
expect(User.find(1).following?(2)).to eq false
end
end
describe '#change_follow' do
before do
(1..2).each { |i| create(:user, id: i, iidxid: format('0000-%04d', i), username: format('test%d', i)) }
end
it 'フォローしていればアンフォローする' do
User.find(1).follow(User.find(2).iidxid)
User.find(1).change_follow(User.find(2))
expect(User.find(1).following?(2)).to eq false
end
it 'フォローしていなければフォローする' do
User.find(1).unfollow(User.find(2).iidxid)
User.find(1).change_follow(User.find(2))
expect(User.find(1).following?(2)).to eq true
end
end
describe 'association' do
before do
(1..2).each { |i| create(:user, id: i, iidxid: format('0000-%04d', i), username: format('test%d', i)) }
User.find(1).follow(User.find(2).iidxid)
User.find(2).follow(User.find(1).iidxid)
end
it 'フォロワーが消えたらフォロー関係が解消されること' do
expect(User.find(1).following?(2)).to eq true
User.find(2).destroy
expect(User.find(1).following?(2)).to eq false
end
it 'フォロワーが消えたらフォロー数が減ること' do
expect(User.find(1).follows.size).to eq 1
User.find(2).destroy
expect(User.find(1).follows.size).to eq 0
end
it 'フォロワーが消えたらフォロワー数が減ること' do
expect(User.find(1).followers.size).to eq 1
User.find(2).destroy
expect(User.find(1).followers.size).to eq 0
end
end
end
|
mitixx/abilitysheet
|
app/models/concerns/user/list.rb
|
<reponame>mitixx/abilitysheet<gh_stars>10-100
# frozen_string_literal: true
module User::List
extend ActiveSupport::Concern
included do
class << self
def users_list(type, options = {})
__send__(type, options)
end
def recent200
query = <<~QUERY
SELECT
users.id, users.djname, users.iidxid, users.pref, users.grade,
scores.updated_at, scores.state, sheets.title
FROM users, scores, sheets
WHERE users.id = scores.user_id
AND scores.state != 7
AND sheets.id = scores.sheet_id
ORDER BY scores.updated_at DESC
LIMIT 6400
QUERY
query.chomp.tr("\n", ' ')
users = ActiveRecord::Base.connection.execute(query.chomp.tr("\n", ' ')).to_a
recent_users = []
ret = {}
users.each do |user|
break if recent_users.size >= 200
next if recent_users.include?(user['id'])
recent_users.push(user['id'])
user['updated_at'] = user['updated_at'].to_date
ret[user['id']] = user
end
ret
end
private
def rivals(users)
scores_map = {}
users.each { |user| scores_map[user.id] = user.scores.last_updated }
scores_map
end
end
end
end
|
mitixx/abilitysheet
|
app/models/message.rb
|
<filename>app/models/message.rb
# frozen_string_literal: true
# == Schema Information
#
# Table name: messages
#
# id :bigint(8) not null, primary key
# body :string
# email :string
# ip :inet not null
# user_id :bigint(8)
# state :boolean default(FALSE)
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_messages_on_user_id (user_id)
#
class Message < ApplicationRecord
belongs_to :user
end
|
mitixx/abilitysheet
|
app/models/score.rb
|
<reponame>mitixx/abilitysheet<filename>app/models/score.rb<gh_stars>10-100
# frozen_string_literal: true
# == Schema Information
#
# Table name: scores
#
# id :bigint(8) not null, primary key
# state :integer default(7), not null
# score :integer
# bp :integer
# sheet_id :bigint(8) not null
# user_id :bigint(8) not null
# version :integer not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_scores_on_sheet_id (sheet_id)
# index_scores_on_updated_at (updated_at)
# index_scores_on_user_id (user_id)
# index_scores_on_user_id_and_version_and_updated_at (user_id,version,updated_at)
# index_scores_on_version_and_sheet_id_and_user_id (version,sheet_id,user_id) UNIQUE
#
class Score < ApplicationRecord
belongs_to :sheet
belongs_to :user
delegate :title, to: :sheet
include Score::Api
validates :sheet_id, uniqueness: { scope: %i[version user_id] }
validates :state, numericality: { only_integer: true }, inclusion: { in: 0..7, message: 'のパラメタが異常です。' }, presence: true
scope :is_not_noplay, (-> { where.not(state: 7) })
scope :is_active, (-> { where(sheet_id: Sheet.active.pluck(:id)) })
scope :is_current_version, (-> { where(version: Abilitysheet::Application.config.iidx_version) })
def self.remain(type)
state = type == :hard ? 2 : 4
Sheet.active.size - where(state: 0..state).size
end
def self.remain_string(type)
hash = { clear: '☆12ノマゲ参考表(未クリア', hard: '☆12ハード参考表(未難' }
hash[type] + "#{remain(type)})"
end
def update_with_logs(score_params)
score_params.stringify_keys! unless score_params.instance_of?(ActionController::Parameters)
# 何も変更がない状態は反映しない
duplicate = check_duplicate(score_params)
return false if duplicate
ActiveRecord::Base.transaction do
user.logs.attributes(score_params, user)
update!(score_params)
end
end
def self.last_updated(version = Abilitysheet::Application.config.iidx_version)
order(updated_at: :desc).where.not(state: 7).where(version: version).first
end
def lamp_string
Static::LAMP[state]
end
def active?
sheet.active
end
class << self
def stat_info(scores)
hash = Static::LAMP.map { |e| [e, 0] }.to_h
count = 0
scores.each do |s|
next unless s.active?
hash[s.lamp_string] += 1
count += 1
end
hash
end
def list_name
[
'FULL COMBO',
'EXH CLEAR',
'HARD CLEAR',
'CLEAR',
'EASY CLEAR',
'ASSIST CLEAR',
'FAILED',
'NO PLAY'
]
end
def convert_color(scores)
hash = {}
scores.each { |s| hash.store(s.sheet_id, Static::COLOR[s.state]) }
hash
end
def select_state
list_name.map.with_index(0) { |e, i| [e, i] }.to_h
end
end
private
def check_duplicate(score_params)
score_params.each do |k, v|
next if k == 'updated_at'
v = v.to_i unless v.instance_of?(NilClass)
return false if k == 'state' && try(k).nil? && v.to_i == 7
return false if try(k) != v
end
true
end
end
|
mitixx/abilitysheet
|
spec/support/sheets_helper.rb
|
<gh_stars>10-100
# frozen_string_literal: true
module SheetsHelper
def sync_sheet
redis = Redis.new
ret = JSON.parse(redis.get('sheets'))
Sheet.insert_all!(ret['sheets'])
end
end
|
mitixx/abilitysheet
|
spec/systems/admin/users_spec.rb
|
<reponame>mitixx/abilitysheet
# frozen_string_literal: true
feature '管理用メッセージページ', type: :system do
background do
user = create(:user, id: 1, role: role)
login(User.find(user.id))
visit admin_users_path
end
describe '#index' do
context '管理者でない' do
let(:role) { User::Role::ADMIN - 1 }
scenario 'トップページにリダイレクトされる' do
expect(page.current_path).to eq '/'
end
end
context '管理者' do
let(:role) { User::Role::ADMIN }
scenario '表示できる' do
expect(page.current_path).to eq '/admin/users'
end
end
end
describe '#lock', js: true do
let!(:user2) { create(:user, id: 3, iidxid: '4847-4938', username: 'delete') }
background do
visit admin_users_path
end
context '管理者' do
let(:role) { User::Role::ADMIN }
it 'ロックできる' do
expect(user2.access_locked?).to be_falsey
click_on '無効化', match: :first
expect(page).to have_content '有効化'
expect(user2.reload.access_locked?).to be_truthy
end
end
end
describe '#unlock', js: true do
let!(:user2) { create(:user, id: 3, iidxid: '4847-4938', username: 'delete') }
background do
user2.lock_access!
visit admin_users_path
end
context '管理者' do
let(:role) { User::Role::ADMIN }
it 'アンロックできる' do
expect(user2.access_locked?).to be_truthy
click_on '有効化', match: :first
expect(page).to have_content '無効化'
expect(user2.reload.access_locked?).to be_falsey
end
end
end
end
|
mitixx/abilitysheet
|
app/controllers/helps_controller.rb
|
<filename>app/controllers/helps_controller.rb<gh_stars>10-100
# frozen_string_literal: true
class HelpsController < ApplicationController
def ist; end
def support; end
def oauth; end
end
|
mitixx/abilitysheet
|
app/models/concerns/user/role.rb
|
<reponame>mitixx/abilitysheet
# frozen_string_literal: true
module User::Role
extend ActiveSupport::Concern
OWNER = 100
ADMIN = 75
MEMBER = 50
SPECIAL = 25
GENERAL = 0
included do
def owner?
OWNER <= role
end
def admin?
ADMIN <= role
end
def member?
MEMBER <= role
end
def special?
SPECIAL == role || OWNER == role
end
end
end
|
mitixx/abilitysheet
|
app/controllers/admin/dashboards_controller.rb
|
# frozen_string_literal: true
class Admin::DashboardsController < ApplicationController
before_action :authenticate_user!
before_action :owner_user!
def index
@email = User.where.not(email: '').count
@message = Message.where(state: false).count
@user = User.where(current_sign_in_at: Date.today..Date.today + 1).count
end
end
|
mitixx/abilitysheet
|
app/models/sheet.rb
|
# frozen_string_literal: true
# == Schema Information
#
# Table name: sheets
#
# id :bigint(8) not null, primary key
# title :string
# n_ability :integer
# h_ability :integer
# version :integer
# active :boolean default(TRUE), not null
# textage :string
# created_at :datetime not null
# updated_at :datetime not null
# exh_ability :integer
#
require 'scrape/exh_collector'
class Sheet < ApplicationRecord
has_many :scores
has_many :logs
has_one :ability
delegate :e, to: :ability
delegate :c, to: :ability
delegate :h, to: :ability
delegate :exh, to: :ability
delegate :fc, to: :ability
delegate :aaa, to: :ability
include Sheet::Api
scope :active, (-> { where(active: true) })
after_create :create_ability
def create_ability
d = 99.99
Ability.create(
sheet_id: id,
fc: d, exh: d, h: d, c: d, e: d, aaa: d
)
end
def n_ability_name
Static::POWER.find { |_, index| n_ability == index }[0]
end
def h_ability_name
Static::POWER.find { |_, index| h_ability == index }[0]
end
def exh_ability_name
Static::EXH_POWER.find { |_, index| exh_ability == index }[0]
end
def self.apply_exh
Scrape::ExhCollector.new.get_sheet.each do |title, ability|
sheet = Sheet.find_by(title: title)
next unless sheet
sheet.update(exh_ability: find_exh_ability_from_string(ability)[1])
end
end
def self.find_exh_ability_from_string(ability_string)
Static::EXH_POWER.find { |power| power[0] == ability_string } || [nil, -1]
end
def self.find_exh_ability_from_integer(ability_integer)
Static::EXH_POWER.find { |power| power[1] == ability_integer } || [nil, -1]
end
end
|
mitixx/abilitysheet
|
lib/slack/user_dispatcher.rb
|
<gh_stars>10-100
# frozen_string_literal: true
module Slack
class UserDispatcher
def self.new_register_notify(id)
user = User.find(id)
body = {
username: 'User Dispatcher',
attachments: [
{
color: :good,
title: '新規登録通知',
pretext: '_new register_',
text: "現在の登録者数: #{User.count}人\n新規登録者: [#{user.iidxid}] #{user.djname} <#{User::Static::PREF[user.pref]}, #{User::Static::GRADE[user.grade]}>",
mrkdwn_in: %w[pretext]
}
]
}
Net::HTTP.post_form(Abilitysheet::Application::SLACK_URI, payload: body.to_json)
end
def self.delete_user_notify(id)
user = User.find(id)
body = {
username: 'User Dispatcher',
attachments: [
{
color: :danger,
title: '削除通知',
pretext: '_delete user_',
text: "現在の登録者数: #{User.count - 1}人\n削除者: [#{user.iidxid}] #{user.djname} <#{User::Static::PREF[user.pref]}, #{User::Static::GRADE[user.grade]}>\n#{user.username}: #{user.email}",
mrkdwn_in: %w[pretext]
}
]
}
Net::HTTP.post_form(Abilitysheet::Application::SLACK_URI, payload: body.to_json)
end
end
end
|
mitixx/abilitysheet
|
lib/tasks/sidekiq.rake
|
# frozen_string_literal: true
namespace :sidekiq do
desc 'Start sidekiq'
task start: :environment do
system "bundle exec sidekiq -C #{Rails.root.join('config', 'sidekiq.yml')}"
end
task :sidekiqctl, %i[name deadline_timeout] => :environment do |_t, args|
system "bundle exec sidekiqctl #{args[:name]} #{Rails.root.join('tmp', 'pids', 'sidekiq.pid')} #{args[:deadline_timeout]}"
end
desc 'Quiet sends USR1 to sidekiq'
task quiet: :environment do
Rake::Task['sidekiq:sidekiqctl'].invoke('quiet')
end
desc 'Stop sends TERM to sidekiq'
task stop: :environment do
Rake::Task['sidekiq:sidekiqctl'].invoke('stop', '10')
end
task before: :environment do
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
end
task start: :before
task sidekiqctl: :before
end
|
mitixx/abilitysheet
|
spec/systems/navbar/display_navbar_spec.rb
|
# frozen_string_literal: true
feature 'Navbarの閲覧可能コンテンツ', type: :system, js: true do
context 'ログインしていない場合' do
background do
visit root_path
end
scenario '管理項目が表示されていない' do
expect(page).to have_no_css('.admin-parent')
end
scenario 'ライバル欄が存在しない' do
expect(page).to have_no_content('ライバル')
end
end
context 'Role::GENERALでログインしている場合' do
background do
user = create(:user, role: User::Role::GENERAL)
login(user)
visit root_path
end
scenario '管理項目が表示されていない' do
expect(page).to have_no_css('.admin-parent')
end
scenario 'ライバル欄が存在する' do
expect(page).to have_content('ライバル')
end
end
context 'Role::OWNERでログインしている場合' do
background do
user = create(:user, role: User::Role::OWNER)
login(user)
visit root_path
end
scenario '管理項目が表示されている' do
expect(page).to have_css('.admin-parent')
end
scenario 'ライバル欄が存在する' do
expect(page).to have_content('ライバル')
end
end
end
|
mitixx/abilitysheet
|
spec/factories/logs.rb
|
# frozen_string_literal: true
# == Schema Information
#
# Table name: logs
#
# id :bigint(8) not null, primary key
# user_id :bigint(8)
# sheet_id :bigint(8)
# pre_state :integer
# new_state :integer
# pre_score :integer
# new_score :integer
# pre_bp :integer
# new_bp :integer
# version :integer
# created_date :date
#
# Indexes
#
# index_logs_on_created_date_and_user_id_and_sheet_id (created_date,user_id,sheet_id) UNIQUE
# index_logs_on_sheet_id (sheet_id)
# index_logs_on_user_id (user_id)
#
FactoryBot.define do
factory :log do
version { Abilitysheet::Application.config.iidx_version }
created_date { Date.today }
end
end
|
mitixx/abilitysheet
|
spec/systems/users/recent_spec.rb
|
<filename>spec/systems/users/recent_spec.rb<gh_stars>10-100
# frozen_string_literal: true
feature '最近更新したユーザ200人一覧', type: :system, js: true do
let(:iidxid) { '0000-0000' }
background do
create(:user, id: 1, iidxid: iidxid)
create(:sheet, id: 1)
create(:score, user_id: 1, sheet_id: 1, state: 5)
visit users_path
end
scenario 'プロフィールページへのリンクが存在する' do
expect(page).to have_link('TEST')
end
context 'IIDXID検索時' do
scenario '該当件数が0であること返す' do
fill_in 'query', with: '0000-0001'
click_button '検索'
expect(page).to have_content('No data available in table')
end
scenario '完全一致で該当するユーザを返す' do
fill_in 'query', with: iidxid
click_button '検索'
expect(page).to have_content('Showing 1 to 1 of 1 entries')
end
end
end
|
mitixx/abilitysheet
|
config/schedule.rb
|
require 'dotenv'
Dotenv.overload
env :PATH, ENV['PATH']
set :output, ENV['CRON_LOG_FILE']
set :enviroment, ENV['RAILS_ENV'] || :production
set :job_template, "/bin/zsh -l -c ':job'"
# 毎日5時にDBのバックアップを取る
every 1.day, at: '5:00 am' do
rake 'db:data:s3_backup'
end
|
mitixx/abilitysheet
|
app/models/concerns/user/api.rb
|
<filename>app/models/concerns/user/api.rb
# frozen_string_literal: true
module User::Api
extend ActiveSupport::Concern
included do
def graph(start_month, end_month)
categories = logs.create_between(start_month, end_month).map { |b| b[0].to_s.slice(0, 7) }
column = logs.column(start_month, end_month)
spline = logs.spline(start_month, end_month)
{
categories: categories,
pie: scores.is_active.is_current_version.pie,
column: column,
column_max: column.flatten.max,
spline: spline,
spline_max: spline.flatten.max
}
end
def schema
image_url = avatar.attached? ? Rails.application.routes.url_helpers.rails_blob_path(avatar, disposition: :inline, only_path: true) : nil
{
id: id,
iidxid: iidxid,
role: role,
djname: djname,
grade: grade,
pref: pref,
image_url: image_url,
created_at: created_at,
follows: follow_users.pluck(:iidxid),
followers: follower_users.pluck(:iidxid)
}
end
end
end
|
mitixx/abilitysheet
|
app/controllers/admin/sheets_controller.rb
|
# frozen_string_literal: true
class Admin::SheetsController < ApplicationController
before_action :authenticate_user!
before_action :member_user!
before_action :load_sheet, except: %i[index new create]
def index
@q = Sheet.search(params[:q])
@q.sorts = ['id desc'] if @q.sorts.empty?
@sheets = @q.result.page(params[:page])
end
def new
render :show_modal_form
end
def create
@sheet = Sheet.create(sheet_params)
render :reload
end
def show; end
def edit
render :show_modal_form
end
def update
@sheet.update(sheet_params)
render :reload
end
def destroy
@sheet.destroy
render :reload
end
def inactive
@sheet.update!(active: false)
render :reload
end
def active
@sheet.update!(active: true)
render :reload
end
private
def sheet_params
params.require(:sheet).permit(
:title, :n_ability, :h_ability, :exh_ability, :version, :textage
)
end
def load_sheet
return unless params[:id]
@sheet = Sheet.find_by(id: params[:id])
end
end
|
mitixx/abilitysheet
|
app/controllers/api/api_controller.rb
|
<reponame>mitixx/abilitysheet<filename>app/controllers/api/api_controller.rb
# frozen_string_literal: true
class UnauthorizedError < RuntimeError; end
class Forbidden < RuntimeError; end
class BadRequest < RuntimeError; end
class ServiceUnavailable < RuntimeError; end
class Api::ApiController < ActionController::API
rescue_from ServiceUnavailable, with: :render_503
rescue_from ActionController::RoutingError, ActiveRecord::RecordNotFound, with: :render_404
rescue_from Forbidden, with: :render_403
rescue_from UnauthorizedError, with: :render_401
rescue_from BadRequest, JSON::ParserError, TypeError, ArgumentError, with: :render_400
after_action :add_response_header_user_id
def authenticate!
raise UnauthorizedError unless current_user
end
def authenticate_member!
raise UnauthorizedError unless current_user
raise UnauthorizedError if current_user.role < User::Role::MEMBER
end
def authenticate_slack!
return if params[:token] == ENV['MANAGEMENT_SLACK_TOKEN']
raise Forbidden
end
private
def render_503
handle_error(503, 'Service Unavailable')
end
def render_404
handle_error(404, 'Not Found')
end
def render_403
handle_error(403, 'Forbidden')
end
def render_401
handle_error(401, 'Unauthorized')
end
def render_400
handle_error(400, 'Bad Request')
end
def handle_error(status, message)
render json: { error: message }, status: status
end
def add_response_header_user_id
response.set_header('X-User-Id', current_user&.iidxid.to_s)
end
end
|
mitixx/abilitysheet
|
db/migrate/20141115070915_create_logs.rb
|
<reponame>mitixx/abilitysheet<filename>db/migrate/20141115070915_create_logs.rb
class CreateLogs < ActiveRecord::Migration[5.1]
def change
create_table :logs do |t|
t.integer :user_id
t.integer :sheet_id
t.integer :pre_state
t.integer :new_state
t.integer :pre_score
t.integer :new_score
t.integer :pre_bp
t.integer :new_bp
t.integer :version
t.date :created_date
end
add_index :logs, :user_id
add_index :logs, :sheet_id
add_index :logs, %i(created_date user_id sheet_id), unique: true
end
end
|
mitixx/abilitysheet
|
spec/decorators/user_decorator_spec.rb
|
# frozen_string_literal: true
describe UserDecorator do
let(:instance) { described_class.new(user) }
let(:user) { create(:user, created_at: Time.new(2017, 3, 3)) }
describe '#pref' do
it 'returns pref of its pref' do
expect(instance.pref).to eq('海外')
end
end
describe '#grade' do
it 'returns dan grade of its grade' do
expect(instance.grade).to eq(User::Static::GRADE[Abilitysheet::Application.config.iidx_grade])
end
end
describe '#belongs' do
it 'returns belongs of its pref' do
expect(instance.belongs).to eq('海外')
end
end
describe '#dan' do
it 'returns dan of its grade' do
expect(instance.dan).to eq(User::Static::GRADE[Abilitysheet::Application.config.iidx_grade])
end
end
describe '#dan_color' do
it 'returns dan color of its grade' do
expect(instance.dan_color).to eq(User::Static::GRADE_COLOR[Abilitysheet::Application.config.iidx_grade])
end
end
describe '#joined_on' do
it 'returns joined on format' do
expect(instance.joined_on).to eq('Joined on 2017/03/03')
end
end
end
|
mitixx/abilitysheet
|
app/helpers/select_helper.rb
|
<reponame>mitixx/abilitysheet<gh_stars>10-100
# frozen_string_literal: true
module SelectHelper
def check_boxes_prefs
User::Static::PREF.map do |pref|
User.new(pref: User::Static::PREF.index(pref))
end
end
def check_boxes_n_abilities
Static::POWER.map do |_, index|
Sheet.new(n_ability: index)
end
end
def check_boxes_h_abilities
Static::POWER.map do |_, index|
Sheet.new(h_ability: index)
end
end
def check_boxes_exh_abilities
Static::EXH_POWER.map do |_, index|
Sheet.new(exh_ability: index)
end
end
end
|
mitixx/abilitysheet
|
spec/support/session_helper.rb
|
<reponame>mitixx/abilitysheet
# frozen_string_literal: true
module SessionHelpers
def login(user, run_callbacks: false)
login_as(user, scope: :user, run_callbacks: run_callbacks)
end
end
|
mitixx/abilitysheet
|
app/controllers/admin/socials_controller.rb
|
# frozen_string_literal: true
class Admin::SocialsController < ApplicationController
before_action :authenticate_user!
before_action :admin_user!
def index
@q = Social.ransack(params[:q])
@q.sorts = ['id desc'] if @q.sorts.empty?
@socials = @q.result.page(params[:page])
end
def show
@social = Social.find(params[:id])
end
end
|
mitixx/abilitysheet
|
spec/requests/sheets_spec.rb
|
# frozen_string_literal: true
describe Api::V1::SheetsController, type: :request do
include_context 'api'
describe 'GET /api/v1/sheets' do
before { create(:sheet, id: 1, active: true) }
let(:url) { '/api/v1/sheets' }
let(:method) { 'get' }
let(:result) do
{
sheets: [{
id: 1,
title: 'MyString',
n_clear: 1,
hard: 1,
exh: 1,
n_clear_string: '個人差S+',
hard_string: '個人差S+',
exh_string: '難度11',
version: 1
}]
}
end
it_behaves_like '200 Success'
end
describe 'GET /api/v1/sheets/list' do
before { @sheet = create(:sheet, id: 1) }
let(:url) { '/api/v1/sheets/list' }
let(:method) { 'get' }
let(:result) do
{
sheets: [
{
id: 1,
title: 'MyString',
n_ability: 1,
h_ability: 1,
exh_ability: 1,
version: 1,
active: false,
textage: 'MyString',
created_at: JSON.parse(@sheet.to_json)['created_at'],
updated_at: JSON.parse(@sheet.to_json)['updated_at']
}
]
}
end
it_behaves_like '200 Success'
end
end
|
mitixx/abilitysheet
|
lib/twitter_dispatcher.rb
|
# frozen_string_literal: true
class TwitterDispatcher
def initialize
tokens = ENV['TWITTER_TOKENS'].split(',')
@client = Twitter::REST::Client.new do |config|
config.consumer_key = tokens[0]
config.consumer_secret = tokens[1]
config.access_token = tokens[2]
config.access_token_secret = tokens[3]
end
end
def tweet(text)
@client.update(text)
end
end
|
mitixx/abilitysheet
|
lib/irt/sync.rb
|
<filename>lib/irt/sync.rb
# frozen_string_literal: true
require 'twitter_dispatcher'
module Irt
class Sync
def self.run
hash = fetch
Ability.sync(hash)
twitter = TwitterDispatcher.new
twitter.tweet('地力値表を更新しました')
end
def self.fetch
# token = ENV['IRT_TOKEN']
uri = URI.parse(ENV['RECOMMEND_SERVER'])
res = Net::HTTP.get(uri)
JSON.parse(res)['result']
end
end
end
|
mitixx/abilitysheet
|
lib/tasks/auto_generate_diagram.rake
|
# frozen_string_literal: true
if Rails.env.development?
RailsERD.load_tasks
namespace :erd do
task :load_models do
say 'Loading application environment...'
Rake::Task[:environment].invoke
say 'Loading code in search of Active Record models...'
Zeitwerk::Loader.eager_load_all
end
end
end
|
mitixx/abilitysheet
|
app/mailers/notice_mail.rb
|
# frozen_string_literal: true
class NoticeMail < ActionMailer::Base
default from: '<EMAIL>'
def new_register(user_id)
@user = User.find_by(id: user_id)
@count = User.select(:id).count
mail to: '<EMAIL>'
mail subject: '新規登録者'
end
def form_deal(email, subject, body)
@body = "#{body}\r\n"
@body += "---------------------------------------------------\r\n"
@body += '※ このメールアドレスには返信ができません。'
mail to: email
mail subject: subject
end
end
|
mitixx/abilitysheet
|
app/controllers/google_controller.rb
|
<gh_stars>10-100
# frozen_string_literal: true
class GoogleController < ApplicationController
before_action :authenticate_user!
def destroy
current_user.socials.find_by(provider: 'google_oauth2').destroy!
redirect_to edit_user_registration_path
end
end
|
mitixx/abilitysheet
|
app/controllers/users/registrations_controller.rb
|
<reponame>mitixx/abilitysheet<filename>app/controllers/users/registrations_controller.rb
# frozen_string_literal: true
require 'slack/user_dispatcher'
require 'ist_client'
class Users::RegistrationsController < Devise::RegistrationsController
def create
pre_user = User.select(:id).count
super
after_user = User.select(:id).count
sync_score if pre_user < after_user
end
def destroy
Slack::UserDispatcher.delete_user_notify(current_user.id)
super
end
private
def sync_score
iidxid = request.env['rack.request.form_hash']['user']['iidxid']
user = User.find_by(iidxid: iidxid)
return unless user
Slack::UserDispatcher.new_register_notify(user.id)
user.check_ist_user
IstSyncJob.perform_later(user)
rescue IstClient::NotFoundUser
end
end
|
mitixx/abilitysheet
|
spec/systems/rivals/rival_spec.rb
|
<reponame>mitixx/abilitysheet
# frozen_string_literal: true
feature 'ライバル情報', type: :system do
given(:user) { create(:user, id: 1) }
background do
user2 = create(:user, id: 2, djname: 'RIVAL', iidxid: '1111-1111', username: 'rival')
user.follow(user2.iidxid)
login(user)
end
scenario 'プロフィールページへのリンクが存在する', js: true do
visit list_rival_path
expect(page).to have_link('RIVAL')
end
scenario '楽曲情報が正しくロードされている' do
sync_sheet
visit clear_rival_path(user.iidxid)
expect(page).to have_selector('td[@name="music"]', count: Sheet.active.count)
click_link 'Win'
expect(page).to have_selector('td[@name="music"]', count: 0)
click_link 'Even'
expect(page).to have_selector('td[@name="music"]', count: Sheet.active.count)
click_link 'Lose'
expect(page).to have_selector('td[@name="music"]', count: 0)
click_link 'ALL'
expect(page).to have_selector('td[@name="music"]', count: Sheet.active.count)
end
end
|
mitixx/abilitysheet
|
lib/slack/message_dispatcher.rb
|
<filename>lib/slack/message_dispatcher.rb<gh_stars>10-100
# frozen_string_literal: true
module Slack
class MessageDispatcher
def self.send(id)
message = Message.find(id)
user = message.user
user_information = nil
user_information = "#{user.djname}[#{user.iidxid}]" if user
admin_messages_url = 'https://sp12.iidx.app/admin/messages'
body = {
username: 'Message Dispatcher',
attachments: [
{
color: '#439FE0',
title: "#{message.ip} #{message.email} #{user_information}",
title_link: admin_messages_url,
pretext: '_Message_',
text: message.body,
mrkdwn_in: %w[pretext]
}
]
}
Net::HTTP.post_form(Abilitysheet::Application::SLACK_URI, payload: body.to_json)
end
end
end
|
mitixx/abilitysheet
|
lib/slack/gcs_dispatcher.rb
|
# frozen_string_literal: true
module Slack
class GcsDispatcher
def self.success(env)
body = {
icon_emoji: ':gcp_gcs:',
username: 'GCS Dispatcher',
attachments: [
{
color: :good,
title: 'backup success',
pretext: '_GCP GCS_',
text: "#{Time.zone.now} #{env} backup success!",
mrkdwn_in: %w[pretext]
}
]
}
Net::HTTP.post_form(Abilitysheet::Application::SLACK_URI, payload: body.to_json)
end
def self.failed(env, exception)
body = {
icon_emoji: ':gcp_gcs:',
username: 'GCS Dispatcher',
attachments: [
{
color: :danger,
title: 'backup failed',
pretext: '_GCP GCS_',
text: "#{Time.zone.now} #{env} backup failed...\n#{exception}",
mrkdwn_in: %w[pretext]
}
]
}
Net::HTTP.post_form(Abilitysheet::Application::SLACK_URI, payload: body.to_json)
end
end
end
|
mitixx/abilitysheet
|
spec/factories/sheets.rb
|
<gh_stars>10-100
# frozen_string_literal: true
# == Schema Information
#
# Table name: sheets
#
# id :bigint(8) not null, primary key
# title :string
# n_ability :integer
# h_ability :integer
# version :integer
# active :boolean default(TRUE), not null
# textage :string
# created_at :datetime not null
# updated_at :datetime not null
# exh_ability :integer
#
FactoryBot.define do
factory :sheet do
title { 'MyString' }
n_ability { 1 }
h_ability { 1 }
exh_ability { 1 }
version { 1 }
active { false }
textage { 'MyString' }
end
end
|
mitixx/abilitysheet
|
app/controllers/api/v1/logs_controller.rb
|
# frozen_string_literal: true
class Api::V1::LogsController < Api::V1::BaseController
before_action :load_user!
def full_calendar
start_date = "#{params[:year]}-#{params[:month]}-01".to_date
end_date = start_date + 1.month
logs = @user.logs.where(created_date: start_date..end_date)
render json: { logs: logs.preload(:sheet).map(&:schema) }
end
def cal_heatmap
logs = @user.logs.where(created_date: params[:start]..params[:stop]).map { |c| c.created_date.to_time.to_i }
render json: logs.each_with_object(Hash.new(0)) { |tm, h| h[tm] += 1 }
end
def graph
end_month = "#{params[:year]}-#{params[:month]}-01".to_date
start_month = end_month - 2.months
render json: @user.graph(start_month, end_month)
end
private
def load_user!
@user = User.find_by_iidxid!(params[:log_iidxid])
end
end
|
mitixx/abilitysheet
|
spec/factories/messages.rb
|
# frozen_string_literal: true
# == Schema Information
#
# Table name: messages
#
# id :bigint(8) not null, primary key
# body :string
# email :string
# ip :inet not null
# user_id :bigint(8)
# state :boolean default(FALSE)
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_messages_on_user_id (user_id)
#
FactoryBot.define do
factory :message do
body { 'message' }
ip { IPAddr.new('192.168.0.1') }
end
end
|
mitixx/abilitysheet
|
spec/systems/admin/dashboards_spec.rb
|
# frozen_string_literal: true
feature 'ダッシュボードの閲覧', type: :system do
background do
create(:user, id: 1, role: 100)
login(User.find(1))
visit admin_dashboards_path
end
it 'email登録人数が見れる' do
expect(page).to have_content('email登録人数')
end
it '未読メッセージが見れる' do
expect(page).to have_content('未読メッセージ')
expect(page).to have_content('0件')
end
end
|
mitixx/abilitysheet
|
db/migrate/20150105172226_create_abilities.rb
|
<filename>db/migrate/20150105172226_create_abilities.rb
class CreateAbilities < ActiveRecord::Migration[5.1]
def change
create_table :abilities do |t|
t.integer :sheet_id
t.float :fc
t.float :exh
t.float :h
t.float :c
t.float :e
t.float :aaa
t.timestamps null: false
end
add_index :abilities, :sheet_id
end
end
|
mitixx/abilitysheet
|
app/decorators/message_decorator.rb
|
# frozen_string_literal: true
class MessageDecorator < Draper::Decorator
delegate_all
def user_name
return '匿名' unless object.user_id
user = User.find_by(id: object.user_id)
"#{user.djname}[#{user.iidxid}]"
end
def created_at
object.created_at.strftime('%Y/%m/%d %H:%M')
end
def status
object.state ? '既読' : '未読'
end
end
|
mitixx/abilitysheet
|
app/decorators/mail_decorator.rb
|
# frozen_string_literal: true
class MailDecorator < Draper::Decorator
delegate_all
end
|
mitixx/abilitysheet
|
app/models/concerns/user/follow_methods.rb
|
# frozen_string_literal: true
module User::FollowMethods
extend ActiveSupport::Concern
included do
def change_follow(target_user)
following?(target_user.id) ? unfollow(target_user.iidxid) : follow(target_user.iidxid)
end
def following?(user_id)
follow_users.pluck(:id).include?(user_id)
end
def follow(iidxid)
target_user_id = User.select(:id).find_by(iidxid: iidxid).id
return false if Follow.exists?(user_id: id, target_user_id: target_user_id)
Follow.create(user_id: id, target_user_id: target_user_id)
end
def unfollow(iidxid)
target_user_id = User.select(:id).find_by(iidxid: iidxid).id
return false unless Follow.exists?(user_id: id, target_user_id: target_user_id)
Follow.find_by(user_id: id, target_user_id: target_user_id).destroy
end
end
end
|
mitixx/abilitysheet
|
spec/factories/scores.rb
|
<reponame>mitixx/abilitysheet
# frozen_string_literal: true
# == Schema Information
#
# Table name: scores
#
# id :bigint(8) not null, primary key
# state :integer default(7), not null
# score :integer
# bp :integer
# sheet_id :bigint(8) not null
# user_id :bigint(8) not null
# version :integer not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_scores_on_sheet_id (sheet_id)
# index_scores_on_updated_at (updated_at)
# index_scores_on_user_id (user_id)
# index_scores_on_user_id_and_version_and_updated_at (user_id,version,updated_at)
# index_scores_on_version_and_sheet_id_and_user_id (version,sheet_id,user_id) UNIQUE
#
FactoryBot.define do
factory :score do
version { Abilitysheet::Application.config.iidx_version }
end
end
|
mitixx/abilitysheet
|
spec/support/redis_helper.rb
|
# frozen_string_literal: true
module RedisHelper
def self.load_sheets_data
redis = Redis.new
uri = URI.parse('https://sp12.iidx.app/api/v1/sheets/list')
sheets = JSON.parse(Net::HTTP.get(uri))
redis.set('sheets', sheets.to_json)
rescue Errno::ECONNREFUSED
puts '本番サーバが稼働していません'
redis.set('sheets', '{"sheets":[]}')
end
end
|
mitixx/abilitysheet
|
spec/systems/logs/show_logs_spec.rb
|
# frozen_string_literal: true
feature 'ログの詳細画面', type: :system, js: true do
background do
@user = create(:user, id: 1, iidxid: '1234-5678', role: User::Role::GENERAL)
create(:sheet, id: 1, title: 'log spec1')
create(:sheet, id: 2, title: 'log spec2')
create(:score, sheet_id: 1, state: 6, user_id: 1)
create(:score, sheet_id: 2, state: 6, user_id: 1)
create(:log, sheet_id: 1, user_id: 1, created_date: Date.today, pre_state: 7, new_state: 6)
create(:log, sheet_id: 2, user_id: 1, created_date: Date.today, pre_state: 7, new_state: 6)
visit logs_path(@user.iidxid, Date.today.to_s)
end
scenario 'ログが存在する' do
expect(page).to have_content('log spec1')
expect(page).to have_content('log spec2')
end
context 'ログイン時' do
background { login(@user) }
context '自分のログページの場合' do
scenario 'ログ編集ボタンのリンクが存在する' do
visit logs_path(@user.iidxid, Date.today.to_s)
expect(page).to have_link('log spec1')
end
scenario '削除ボタンが存在する' do
visit logs_path(@user.iidxid, Date.today.to_s)
click_button '表示'
expect(page).to have_content('削除')
end
scenario 'ログが削除できる' do
expect(Log.where(user_id: @user.id).count).to eq 2
expect(Score.exists?(user_id: @user.id, state: 7)).to eq false
visit logs_path(@user.iidxid, Date.today.to_s)
click_button '表示'
click_link '削除', match: :first
page.driver.browser.switch_to.alert.accept
expect(page).to have_content('ログを削除し')
expect(Log.where(user_id: @user.id).count).to eq 1
expect(Score.exists?(user_id: @user.id, state: 7)).to eq true
end
scenario 'ログが0個になったら一覧に遷移する' do
visit logs_path(@user.iidxid, Date.today.to_s)
click_button '表示'
click_link '削除', match: :first
page.driver.browser.switch_to.alert.accept
expect(page).to have_content('ログを削除し')
click_button '表示'
click_link '削除', match: :first
page.driver.browser.switch_to.alert.accept
sleep 5
expect(page).to have_content('更新履歴')
end
end
context '他人のログページの場合' do
background do
@user2 = create(:user, id: 2, username: 'user2', iidxid: '2234-5678', role: User::Role::GENERAL)
create(:score, sheet_id: 1, state: 6, user_id: 2)
create(:score, sheet_id: 2, state: 6, user_id: 2)
create(:log, sheet_id: 1, user_id: 2, created_date: Date.today, pre_state: 7, new_state: 6)
create(:log, sheet_id: 2, user_id: 2, created_date: Date.today, pre_state: 7, new_state: 6)
visit logs_path(@user2.iidxid, Date.today.to_s)
end
scenario 'ログ編集ボタンのリンクが存在しない' do
expect(page).to have_no_link('log spec1')
end
context 'User::Role::GENERALの場合' do
scenario '削除ボタンが存在しない' do
expect(page).to have_no_content('削除')
end
end
context 'User::Role::OWNERの場合' do
background do
@user.update!(role: User::Role::OWNER)
visit logs_path(@user2.iidxid, Date.today.to_s)
end
scenario '削除ボタンが存在する' do
click_button '表示'
expect(page).to have_content('削除')
end
scenario 'ログが削除できる' do
expect(Log.where(user_id: @user2.id).count).to eq 2
expect(Score.exists?(user_id: @user2.id, state: 7)).to eq false
click_button '表示'
click_link '削除', match: :first
page.driver.browser.switch_to.alert.accept
expect(page).to have_content('ログを削除し')
expect(Log.where(user_id: @user2.id).count).to eq 1
expect(Score.exists?(user_id: @user2.id, state: 7)).to eq true
end
end
end
end
context '非ログイン時' do
scenario '削除ボタンが存在しない' do
expect(page).to have_no_content('削除')
end
end
end
|
mitixx/abilitysheet
|
app/models/follow.rb
|
<filename>app/models/follow.rb
# frozen_string_literal: true
# == Schema Information
#
# Table name: follows
#
# id :bigint(8) not null, primary key
# user_id :bigint(8)
# target_user_id :bigint(8)
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_follows_on_user_id_and_target_user_id (user_id,target_user_id) UNIQUE
#
class Follow < ApplicationRecord
belongs_to :from_user, class_name: 'User', foreign_key: :user_id
belongs_to :to_user, class_name: 'User', foreign_key: :target_user_id
end
|
mitixx/abilitysheet
|
app/controllers/users_controller.rb
|
<filename>app/controllers/users_controller.rb
# frozen_string_literal: true
class UsersController < ApplicationController
def index
@title = '最近更新した200人'
if params[:query]&.present?
@users = User.where(iidxid: params[:query])
@scores_map = User.users_list(:rivals, @users)
else
@users = User.recent200.deep_symbolize_keys
end
end
def show
@user = User.find_by_iidxid!(params[:id])
@title = "DJ.#{@user.djname} プロフィール"
end
end
|
mitixx/abilitysheet
|
app/models/concerns/sheet/api.rb
|
# frozen_string_literal: true
module Sheet::Api
extend ActiveSupport::Concern
included do
def schema
{
id: id,
title: title,
n_clear: n_ability,
hard: h_ability,
exh: exh_ability,
n_clear_string: Static::POWER[n_ability][0],
hard_string: Static::POWER[h_ability][0],
exh_string: Sheet.find_exh_ability_from_integer(exh_ability)[0],
version: version
}
end
end
end
|
mitixx/abilitysheet
|
spec/systems/sheets/clear_sheet_spec.rb
|
<reponame>mitixx/abilitysheet<filename>spec/systems/sheets/clear_sheet_spec.rb
# frozen_string_literal: true
feature 'ノマゲ地力表', type: :system, js: true do
given(:user) { create(:user, id: 1) }
background do
visit sheet_path(iidxid: user.iidxid, type: 'clear')
end
scenario '存在しないユーザへのアクセス' do
visit sheet_path(iidxid: '1111-1111', type: 'clear')
expect(page).to have_content('このページは存在しません')
end
context 'ログイン時' do
background { login(user) }
scenario 'ノマゲ参考表の文字が存在する' do
expect(page).to have_content('ノマゲ参考表')
end
scenario 'ハード参考表のリンクが存在する' do
expect(page).to have_link('HARD')
end
scenario '未クリアの表記が存在する', js: true do
expect(page).to have_content('未クリア')
end
context 'モバイル', iphone6: true do
background do
sync_sheet
visit sheet_path(iidxid: user.iidxid, type: 'clear')
end
xscenario 'PC版に切り替えたときのレイアウトが正しい' do
expect(page).to have_content('PCサイト版')
click_on 'PCサイト版'
expect(page).to have_content('モバイル版')
end
end
end
context '非ログイン時' do
scenario 'ノマゲ参考表の文字が存在する' do
expect(page).to have_content('ノマゲ参考表')
end
scenario 'ハード参考表のリンクが存在する' do
expect(page).to have_link('HARD')
end
scenario '未クリアの表記が存在する', js: true do
expect(page).to have_content('未クリア')
end
end
end
|
mitixx/abilitysheet
|
db/migrate/20180226135142_add_exh_tosheet.rb
|
<filename>db/migrate/20180226135142_add_exh_tosheet.rb
class AddExhTosheet < ActiveRecord::Migration[5.1]
def change
add_column :sheets, :exh_ability, :integer
end
end
|
mitixx/abilitysheet
|
spec/systems/admin/messages_spec.rb
|
# frozen_string_literal: true
feature '管理用メッセージページ', type: :system do
background do
create(:user, id: 1, role: role)
login(User.find(1))
visit admin_messages_path
end
describe '#index' do
context '管理者でない' do
let(:role) { User::Role::ADMIN - 1 }
scenario 'トップページにリダイレクトされる' do
expect(page.current_path).to eq '/'
end
end
context '管理者' do
let(:role) { User::Role::ADMIN }
scenario '表示できる' do
expect(page.current_path).to eq '/admin/messages'
end
end
end
describe '#active' do
let!(:message) { create(:message) }
background do
visit admin_messages_path
end
context '管理者' do
let(:role) { User::Role::ADMIN }
it 'stateが変わっている' do
expect(message.state).to be_falsey
click_on '未読'
expect(message.reload.state).to be_truthy
end
end
end
describe '#inactive' do
let!(:message) { create(:message, state: true) }
background do
visit admin_messages_path
end
context '管理者' do
let(:role) { User::Role::ADMIN }
it 'stateが変わっている' do
expect(message.state).to be_truthy
click_on '既読'
expect(message.reload.state).to be_falsey
end
end
end
end
|
mitixx/abilitysheet
|
app/models/ability.rb
|
# frozen_string_literal: true
# == Schema Information
#
# Table name: abilities
#
# id :bigint(8) not null, primary key
# sheet_id :bigint(8)
# fc :float
# exh :float
# h :float
# c :float
# e :float
# aaa :float
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_abilities_on_sheet_id (sheet_id)
#
class Ability < ApplicationRecord
belongs_to :sheet
def self.sync(data)
data.each do |d|
find_by(sheet_id: d['sheet_id']).update(fc: d['fc'], exh: d['exh'], h: d['h'], c: d['c'], e: d['e'])
end
end
end
|
mitixx/abilitysheet
|
spec/systems/messages_spec.rb
|
<filename>spec/systems/messages_spec.rb
# frozen_string_literal: true
feature '連絡フォーム', type: :system do
given(:user) { create(:user, id: 1) }
background do
create(:score, user_id: 1, sheet_id: 1)
visit new_message_path
end
describe 'new' do
context 'ログイン時' do
background do
login(user)
visit new_message_path
end
scenario '連絡フォームが正しく表示できる' do
expect(page).to have_content('連絡フォーム')
end
end
context '非ログイン時' do
scenario '連絡フォームが正しく表示できる' do
expect(page).to have_content('連絡フォーム')
end
end
end
describe 'create' do
let(:email) { '<EMAIL>' }
context 'ログイン時' do
background do
login(user)
visit new_message_path
end
scenario 'メッセージが送信できる' do
allow(Slack::MessageDispatcher).to receive(:send).and_return(true)
body = 'create-message-test-with-sign-in'
fill_in 'message_email', with: email
fill_in 'message_body', with: body
click_button '送信'
message = Message.find_by(body: body)
expect(message.email).to eq email
expect(message.user_id).to eq user.id
expect(message.state).to be_falsey
end
end
context '非ログイン時' do
scenario 'メッセージが送信できる' do
allow(Slack::MessageDispatcher).to receive(:send).and_return(true)
body = 'create-message-test'
fill_in 'message_email', with: email
fill_in 'message_body', with: body
click_button '送信'
message = Message.find_by(body: body)
expect(message.email).to eq email
expect(message.user_id).to eq nil
expect(message.state).to be_falsey
end
end
end
end
|
mitixx/abilitysheet
|
config/initializers/rack.rb
|
<reponame>mitixx/abilitysheet
Rack::Utils.multipart_part_limit = 0
|
mitixx/abilitysheet
|
app/controllers/api/v1/messages_controller.rb
|
<gh_stars>10-100
# frozen_string_literal: true
class Api::V1::MessagesController < Api::V1::BaseController
def index
authenticate_member!
render json: { num: Message.where(state: false).count }
end
end
|
mitixx/abilitysheet
|
spec/models/user_spec.rb
|
<reponame>mitixx/abilitysheet
# frozen_string_literal: true
# == Schema Information
#
# Table name: users
#
# id :bigint(8) not null, primary key
# email :string default(""), not null
# username :string default(""), not null
# encrypted_password :string default(""), not null
# reset_password_token :string
# reset_password_sent_at :datetime
# remember_created_at :datetime
# sign_in_count :integer default(0), not null
# current_sign_in_at :datetime
# last_sign_in_at :datetime
# current_sign_in_ip :inet
# last_sign_in_ip :inet
# iidxid :string not null
# version :integer default(22), not null
# djname :string not null
# grade :integer
# pref :integer not null
# role :integer default(0), not null
# failed_attempts :integer default(0), not null
# unlock_token :string
# locked_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_users_on_iidxid (iidxid) UNIQUE
# index_users_on_reset_password_token (reset_password_token) UNIQUE
# index_users_on_unlock_token (unlock_token) UNIQUE
# index_users_on_username (username) UNIQUE
#
describe User, type: :model do
describe '.belongs' do
it "所属を配列で返すこと[['海外', 0], ['北海道', 1]..]" do
pref = User::Static::PREF
User.belongs.each { |p| expect(pref[p[1]]).to eq p[0] }
end
end
describe '.dan' do
it "段位を配列で返すこと[['皆伝', 0], ['中伝', 1], ['十段', 2]..]" do
dan = User::Static::GRADE
User.dan.each { |d| expect(dan[d[1]]).to eq d[0] }
end
end
context 'validation' do
it 'iidxid, version, djname, pref, grade, username, passwordがあれば有効な状態であること' do
expect(create(:user)).to be_valid
end
it 'ユーザごとに重複したemailを許可しないこと' do
create(:user, email: '<EMAIL>')
user = build(:user, iidxid: '9384-2982', username: 'test2', email: '<EMAIL>')
user.valid?
expect(user.errors[:email]).to include('はすでに存在します。')
end
it 'emailがなければ無効な状態であること' do
user = User.new(email: '')
user.valid?
expect(user.errors[:email]).to include('を入力してください。')
end
it 'ユーザごとに重複したiidxidを許可しないこと' do
create(:user)
user = build(:user, username: 'test2')
user.valid?
expect(user.errors[:iidxid]).to include('はすでに存在します。')
end
it 'iidxidがなければ無効な状態であること' do
user = User.new(iidxid: nil)
user.valid?
expect(user.errors[:iidxid]).to include('を入力してください。')
end
it 'iidxidが9文字でなければ無効な状態であること' do
(1..8).each do |num|
iidxid = ''
num.times { iidxid += '1' }
user = build(:user, iidxid: iidxid)
user.valid?
expect(user.errors[:iidxid]).to include('は9文字で入力してください。')
end
end
it 'iidxidの書式が正しくなければ無効な状態であること' do
user = User.new(iidxid: '123456789')
user.valid?
expect(user.errors[:iidxid]).to include('が正しくありません。')
end
it 'djnameがなければ無効な状態であること' do
user = User.new(djname: nil)
user.valid?
expect(user.errors[:djname]).to include('を入力してください。')
end
it 'djnameが半角大文字英字でなければ無効な状態であること' do
user = User.new(djname: 'test')
user.valid?
expect(user.errors[:djname]).to include('は半角大文字英字で記入して下さい')
end
it 'djnameは6文字以内であれば有効であること' do
(1..6).each do |num|
djname = ''
num.times { djname += 'A' }
expect(build(:user, djname: djname)).to be_valid
end
end
it 'prefがなければ無効な状態であること' do
user = User.new(pref: nil)
user.valid?
expect(user.errors[:pref]).to include('を入力してください。')
end
it 'prefが0..47であれば有効な状態であること' do
(0..47).each { |pref| expect(build(:user, pref: pref)).to be_valid }
end
it 'gradeがなければ無効な状態であること' do
user = User.new(grade: nil)
user.valid?
expect(user.errors[:grade]).to include('を入力してください。')
end
it 'gradeが設定値..19であれば有効な状態であること' do
set_value = Abilitysheet::Application.config.iidx_grade
(set_value..19).each { |grade| expect(build(:user, grade: grade)).to be_valid }
end
it 'usernameがなければ無効な状態であること' do
user = User.new(username: nil)
user.valid?
expect(user.errors[:username]).to include('を入力してください。')
end
it 'usernameは3-10文字であれば有効であること' do
(3..10).each do |num|
username = ''
num.times { username += 'a' }
expect(build(:user, username: username)).to be_valid
end
end
it 'ユーザごとに重複したusernameを許可しないこと' do
create(:user)
user = build(:user, iidxid: '2345-6789')
user.valid?
expect(user.errors[:username]).to include('はすでに存在します。')
end
it 'passwordがなければ無効な状態であること' do
user = User.new(password: <PASSWORD>)
user.valid?
expect(user.errors[:password]).to include('を入力してください。')
end
it 'passwordが8文字以上でなければ無効な状態であること' do
(1..7).each do |num|
password = ''
num.times { password += 'a' }
user = build(:user, password: password)
user.valid?
expect(user.errors[:password]).to include('は8文字以上で入力してください。')
end
end
end
end
|
mitixx/abilitysheet
|
db/migrate/20141111002700_create_scores.rb
|
<filename>db/migrate/20141111002700_create_scores.rb<gh_stars>10-100
class CreateScores < ActiveRecord::Migration[5.1]
def change
create_table :scores do |t|
t.integer :state, null: false, default: 7
t.integer :score
t.integer :bp
t.integer :sheet_id, null: false
t.integer :user_id, null: false
t.integer :version, null: false
t.timestamps null: false
end
add_index :scores, :sheet_id
add_index :scores, :user_id
add_index :scores, :updated_at
add_index :scores, %i(version sheet_id user_id), unique: true
end
end
|
mitixx/abilitysheet
|
spec/systems/session/sign_up_spec.rb
|
# frozen_string_literal: true
feature 'sign up', type: :system do
background do
visit new_user_registration_path
sync_sheet
allow(Slack::UserDispatcher).to receive(:new_register_notify).and_return(true)
end
def input_sign_up_form(iidxid)
fill_in 'user_email', with: '<EMAIL>'
fill_in 'user_username', with: 'signup'
fill_in 'user_djname', with: 'SIGNUP'
fill_in 'user_iidxid', with: iidxid
fill_in 'user_password', with: '<PASSWORD>'
fill_in 'user_password_confirmation', with: '<PASSWORD>'
select '京都府', from: 'user_pref'
select '八段', from: 'user_grade'
click_button '登録'
end
scenario 'ISTに存在しないユーザの場合でも登録できる' do
expect(User.exists?(email: '<EMAIL>')).to be_falsey
expect do
perform_enqueued_jobs do
VCR.use_cassette('not_found_ist') do
input_sign_up_form('1234-5678')
end
end
end.to change { User.count }.by(1)
expect(User.exists?(email: '<EMAIL>')).to be_truthy
end
scenario 'ISTに存在するユーザなら同期して登録できる' do
expect(User.exists?(email: '<EMAIL>')).to be_falsey
iidxid = '8594-9652'
expect do
perform_enqueued_jobs do
VCR.use_cassette('ist') do
input_sign_up_form(iidxid)
end
end
end.to change { User.count }.by(1)
user = User.find_by(iidxid: iidxid)
expect(user.present?).to be_truthy
expect(user.scores.is_current_version.find_by(sheet: Sheet.find_by!(title: 'AA')).score).to eq 3045
end
end
|
mitixx/abilitysheet
|
spec/systems/session/login_spec.rb
|
# frozen_string_literal: true
feature 'ログイン処理', type: :system do
background do
create(:user, id: 1)
visit new_user_session_path
end
given(:user) { User.find_by(id: 1) }
context 'iidxidでログイン' do
scenario 'response ok' do
fill_in 'user_login', with: user.iidxid
fill_in 'user_password', with: '<PASSWORD>'
click_button 'ログイン'
within first(:xpath, 'html') do
expect(page).to have_content('マイページ')
end
end
end
context 'usernameでログイン' do
scenario 'response ok' do
fill_in 'user_login', with: user.username
fill_in 'user_password', with: '<PASSWORD>'
click_button 'ログイン'
within first(:xpath, 'html') do
expect(page).to have_content('マイページ')
end
end
end
context 'emailでログイン' do
scenario 'response ok' do
fill_in 'user_login', with: user.email
fill_in 'user_password', with: '<PASSWORD>'
click_button 'ログイン'
within first(:xpath, 'html') do
expect(page).to have_content('マイページ')
end
end
end
end
|
mitixx/abilitysheet
|
spec/systems/sheets/hard_sheet_spec.rb
|
<filename>spec/systems/sheets/hard_sheet_spec.rb
# frozen_string_literal: true
feature 'ハード地力表', type: :system, js: true do
given(:user) { create(:user, id: 1) }
background do
visit sheet_path(iidxid: user.iidxid, type: 'hard')
end
scenario '存在しないユーザへのアクセス' do
visit sheet_path(iidxid: '1111-1111', type: 'hard')
expect(page).to have_content('このページは存在しません')
end
context 'ログイン時' do
background { login(user) }
scenario 'ハード参考表の文字が存在する' do
expect(page).to have_content('ハード参考表')
end
scenario 'クリア参考表のリンクが存在する' do
expect(page).to have_link('CLEAR')
end
scenario '未難の表記が存在する', js: true do
expect(page).to have_content('未難')
end
end
context '非ログイン時' do
scenario 'ハード参考表の文字が存在する' do
expect(page).to have_content('ハード参考表')
end
scenario 'クリア参考表のリンクが存在する' do
expect(page).to have_link('CLEAR')
end
scenario '未難の表記が存在する', js: true do
expect(page).to have_content('未難')
end
end
context '楽曲更新時' do
background do
create(:sheet, id: 1, active: true, textage: 'hoge')
login(user)
visit sheet_path(iidxid: user.iidxid, type: 'hard')
end
scenario 'モーダルが降りてくる' do
click_on 'MyString'
expect(page).to have_content('MyString')
expect(page).to have_content('state')
expect(page).to have_content('bp')
expect(page).to have_content('score')
expect(page).to have_content('version')
expect(page).to have_content('updated at')
expect(page).to have_content('textage(1P)')
expect(page).to have_content('textage(2P)')
end
scenario '楽曲が更新でき,ログが作られている' do
expect(user.scores.empty?).to eq true
expect(user.logs.empty?).to eq true
select 'C', from: 'select_1'
expect(page.find('table#sheet-list-table > tbody > tr > td')).to match_style({ 'background-color' => 'rgba(175, 238, 238, 1)' })
expect(user.scores.first.state).to eq 3
expect(Log.exists?(user_id: 1, sheet_id: 1, pre_state: 7, new_state: 3)).to eq true
end
end
end
|
mitixx/abilitysheet
|
app/controllers/api/v1/abilities_controller.rb
|
# frozen_string_literal: true
class Api::V1::AbilitiesController < Api::V1::BaseController
def index
power = params[:type] == 'exh' ? Static::EXH_POWER : Static::POWER
render json: {
abilities: power.map do |elem|
{ key: elem[1], value: elem[0] }
end
}
end
def create
unless params[:api_key] == ENV.fetch('SYNC_API_KEY', '')
render json: { status: :forbidden }, status: 403
return
end
params[:sheets].each do |s|
sheet = Sheet.find_by(title: s[:title])
next unless sheet
sheet.ability.update!(
fc: s[:fc] || 99.99,
exh: s[:exh] || 99.99,
h: s[:h] || 99.99,
c: s[:c] || 99.99,
e: s[:e] || 99.99,
aaa: s[:aaa] || 99.99
)
end
render json: { status: :created }
end
end
|
mitixx/abilitysheet
|
app/controllers/users/passwords_controller.rb
|
# frozen_string_literal: true
class Users::PasswordsController < Devise::PasswordsController
def create
self.resource = resource_class.send_reset_password_instructions(resource_params)
yield resource if block_given?
if successfully_sent?(resource)
flash[:notice] = '再発行メールを送信しました、数分ほどかかります'
flash[:danger] = '届いていない場合は迷惑メールフォルダをご確認下さい'
elsif !User.exists?(email: resource.email)
flash[:danger] = '登録されていないメールアドレスです'
else
flash[:danger] = '何らかの不具合によりメールが送れませんでした.管理人に連絡下さい'
end
redirect_to root_path
end
end
|
mitixx/abilitysheet
|
app/models/concerns/static.rb
|
<reponame>mitixx/abilitysheet<gh_stars>10-100
# frozen_string_literal: true
module Static
LAMP = %w[FC EXH H C E A F N].freeze
LAMP_HASH = LAMP.map.with_index(0) { |e, i| [e, i] }.to_h
LAMP_OFFICIAL = [
'FULLCOMBO CLEAR',
'EX HARD CLEAR',
'HARD CLEAR',
'CLEAR',
'EASY CLEAR',
'ASSIST CLEAR',
'FAILED',
'NO PLAY'
].freeze
POWER = [
['地力S+', 0],
['個人差S+', 1],
['地力S', 2],
['個人差S', 3],
['地力A+', 4],
['個人差A+', 5],
['地力A', 6],
['個人差A', 7],
['地力B+', 8],
['個人差B+', 9],
['地力B', 10],
['個人差B', 11],
['地力C', 12],
['個人差C', 13],
['地力D', 14],
['個人差D', 15],
['地力E', 16],
['個人差E', 17],
['地力F', 18],
['難易度未定', 19]
].freeze
EXH_POWER = [
['難度12', 0],
['難度11', 1],
['難度10', 2],
['難度9', 3],
['難度8', 4],
['難度7', 5],
['難度6', 6],
['難度5', 7],
['難度4', 8],
['難度3', 9],
['難度2', 10],
['難度1', 11],
['難度???', 12],
['難度未定', -1]
].freeze
VERSION = [
['5', 5],
['6', 6],
['7', 7],
['8', 8],
['9', 9],
['10', 10],
['RED', 11],
['HS', 12],
['DD', 13],
['GOLD', 14],
['DJT', 15],
['EMP', 16],
['SIR', 17],
['RA', 18],
['Lin', 19],
['tri', 20],
['SPD', 21],
['PEN', 22],
['COP', 23],
['SINO', 24],
['CAN', 25],
['RO', 26],
['HV', 27],
['BIS', 28],
['CH', 29]
].freeze
COLOR = %w[
#ff8c00
#ffd900
#ff6347
#afeeee
#98fb98
#9595ff
#c0c0c0
#ffffff
].freeze
end
|
mitixx/abilitysheet
|
app/controllers/welcomes_controller.rb
|
# frozen_string_literal: true
class WelcomesController < ApplicationController
def index
@title = 'TOP'
end
end
|
mitixx/abilitysheet
|
spec/spec_helper.rb
|
# frozen_string_literal: true
require 'simplecov'
SimpleCov.start
require 'capybara/rspec'
require 'sidekiq/testing'
require 'rspec/retry'
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
# rspec retry setting
config.verbose_retry = true
config.display_try_failure_messages = true
config.around :each do |ex|
ex.run_with_retry retry: ENV['RETRY_RSPEC']
end
config.before(:each, type: :system) do |example|
if example.metadata[:js]
if ENV['NO_HEADLESS']
driven_by :selenium
else
driven_by :selenium, using: :headless_chrome, screen_size: [1920, 1080]
end
else
driven_by :rack_test
end
end
Sidekiq::Testing.inline!
end
|
mitixx/abilitysheet
|
spec/models/sheet_spec.rb
|
<reponame>mitixx/abilitysheet<gh_stars>10-100
# frozen_string_literal: true
# == Schema Information
#
# Table name: sheets
#
# id :bigint(8) not null, primary key
# title :string
# n_ability :integer
# h_ability :integer
# version :integer
# active :boolean default(TRUE), not null
# textage :string
# created_at :datetime not null
# updated_at :datetime not null
# exh_ability :integer
#
describe Sheet, type: :model do
context 'activeな楽曲がある場合' do
before do
create(:sheet, title: 'one', active: true)
create(:sheet, title: 'two', active: true)
create(:sheet, title: 'three')
end
describe '.active' do
it 'アクティブな楽曲の数を返す' do
expect(Sheet.active.count).to eq 2
end
end
end
context 'activeな楽曲がない場合' do
before do
create(:sheet, title: 'one')
end
describe '.active' do
it '正しく0を返す' do
expect(Sheet.active.count).to eq 0
end
end
end
end
|
mitixx/abilitysheet
|
app/controllers/api/v1/maintenance_controller.rb
|
# frozen_string_literal: true
class Api::V1::MaintenanceController < Api::V1::BaseController
before_action :authenticate_slack!
def change
mode = params[:text].split('メンテナンス ')[1]
mode == '開始' ? system('touch /var/tmp/abilitysheet_maintenance.txt') : system('rm /var/tmp/abilitysheet_maintenance.txt')
head :ok
end
end
|
mitixx/abilitysheet
|
config/application.rb
|
<reponame>mitixx/abilitysheet
require_relative "boot"
require_relative '../lib/rails_log_silencer'
require "rails/all"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Abilitysheet
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.1
# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
# in config/environments, which are processed later.
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
config.time_zone = 'Asia/Tokyo'
config.active_record.default_timezone = :local
config.active_storage.queues.purge = :active_storage
config.active_storage.queues.analysis = :active_storage
config.i18n.default_locale = :ja
config.generators.template_engine = :slim
config.generators.helper = false
config.generators.assets = false
# Current IIDX version
config.iidx_version = ENV['IIDX_VERSION'].to_i
# Current IIDX grade
config.iidx_grade = ENV['IIDX_GRADE'].to_i
config.add_autoload_paths_to_load_path
# test_framework
config.generators.test_framework = :rspec
SLACK_URI = URI.parse(ENV['NOTIFY_SLACK_URL']) if ENV['NOTIFY_SLACK_URL']
config.middleware.insert_before(Rails::Rack::Logger, RailsLogSilencer, %w[/api/v1/health_check])
end
end
|
mitixx/abilitysheet
|
spec/systems/recommends/recommends_spec.rb
|
# frozen_string_literal: true
feature '地力値表', type: :system, js: true do
given(:user) { create(:user, id: 1) }
background do
create(:score, user_id: 1, sheet_id: 1)
visit recommends_path
end
context 'ログイン時' do
background do
login(user)
visit recommends_path
end
scenario '地力値表が表示できる' do
expect(page).to have_content('TITLE')
end
end
context '非ログイン時' do
scenario '地力値表が表示できる' do
expect(page).to have_content('TITLE')
end
end
end
|
mitixx/abilitysheet
|
app/models/concerns/graph.rb
|
<filename>app/models/concerns/graph.rb<gh_stars>10-100
# frozen_string_literal: true
module Graph
extend ActiveSupport::Concern
included do
def self.column(start_month, end_month)
between = create_between(start_month, end_month)
category = []
fc_count = []
exh_count = []
h_count = []
c_count = []
e_count = []
between.each do |b|
category.push(b[0].strftime('%Y-%m'))
fc_count.push(lamp_where_count(0, b[0]..b[1]))
exh_count.push(lamp_where_count(1, b[0]..b[1]))
h_count.push(lamp_where_count(2, b[0]..b[1]))
c_count.push(lamp_where_count(3, b[0]..b[1]))
e_count.push(lamp_where_count(4, b[0]..b[1]))
end
[fc_count, exh_count, h_count, c_count, e_count]
end
def self.spline(start_month, end_month)
between = create_between(start_month, end_month)
st = order(:created_date).first.try(:created_date)
return [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] unless st
all_sheet = Sheet.active
fc_cnt = []
exh_cnt = []
h_cnt = []
c_cnt = []
between.each do |b|
all = all_sheet.where('created_at < ?', b[1]).count
c_cnt.push(all - lamp_where_count(0..4, st..b[1]))
h_cnt.push(all - lamp_where_count(0..2, st..b[1]))
exh_cnt.push(all - lamp_where_count(0..1, st..b[1]))
fc_cnt.push(all - lamp_where_count(0, st..b[1]))
end
[fc_cnt, exh_cnt, h_cnt, c_cnt]
end
def self.lamp_where_count(state, between)
count = 0
sheet_ids = []
where(new_state: state, created_date: between).each do |instance|
next if sheet_ids.include?(instance.sheet_id)
next if instance.new_state == instance.pre_state
sheet_ids.push(instance.sheet_id)
count += 1
end
count
end
def self.create_between(received_start, received_end)
range = []
new_start = received_start
loop do
new_end = new_start + 1.month - 1.days
range.push([new_start, new_end])
new_start += 1.month
break if new_start == received_end + 1.month
end
range
end
end
end
|
mitixx/abilitysheet
|
db/migrate/20141116172112_create_messages.rb
|
class CreateMessages < ActiveRecord::Migration[5.1]
def change
create_table :messages do |t|
t.string :body
t.string :email
t.inet :ip, null: false
t.integer :user_id
t.boolean :state, default: false
t.timestamps null: false
end
add_index :messages, :user_id
end
end
|
mitixx/abilitysheet
|
app/models/concerns/user/static.rb
|
# frozen_string_literal: true
module User::Static
PREF = %w[
海外
北海道 青森県 岩手県 宮城県
秋田県 山形県 福島県 茨城県
栃木県 群馬県 埼玉県 千葉県
東京都 神奈川県 新潟県 富山県
石川県 福井県 山梨県 長野県
岐阜県 静岡県 愛知県 三重県
滋賀県 京都府 大阪府 兵庫県
奈良県 和歌山県 鳥取県 島根県
岡山県 広島県 山口県 徳島県
香川県 愛媛県 高知県 福岡県
佐賀県 長崎県 熊本県 大分県
宮崎県 鹿児島県 沖縄県
香港 韓国 台湾 マカオ シンガポール
フィリピン アメリカ タイ インドネシア 米国
].freeze
GRADE = %w[
皆伝 中伝
十段 九段
八段 七段 六段 五段 四段 三段 二段 初段
一級 二級 三級 四級 五級 六級 七級
無段位
].freeze
GRADE_COLOR = %w[
#ffd900 #dcdddd
#ff6347 #ff6347
#afeeee #afeeee #afeeee #afeeee #afeeee #afeeee #afeeee #afeeee
#98fb98 #98fb98 #98fb98 #98fb98 #98fb98 #98fb98 #98fb98
#fbefef
].freeze
end
|
mitixx/abilitysheet
|
lib/tasks/auto_annotate_and_erd.rake
|
# frozen_string_literal: true
namespace :db do
task migrate: :environment do
Rake::Task['db:migrate'].invoke
`rails erd annotate_models` if Rails.env.development?
end
end
|
mitixx/abilitysheet
|
spec/support/api_helper.rb
|
<reponame>mitixx/abilitysheet<gh_stars>10-100
# frozen_string_literal: true
require 'json_expressions/rspec'
module ApiHelper
include Rack::Test::Methods
def domain
''
end
def default_rack_env
{ 'HTTP_HOST' => domain }
end
shared_context 'api' do
subject do
case method
when 'get'
get(url, parameters, rack_env)
when 'post'
post(url, parameters, rack_env)
when 'put'
put(url, parameters, rack_env)
when 'delete'
delete(url, parameters, rack_env)
when 'patch'
patch(url, parameters, rack_env)
end
end
let(:parameters) { '' }
let(:rack_env) { default_rack_env }
end
shared_examples_for '200 Success' do
its(:status) { is_expected.to be(200) }
its(:body) { is_expected.to match_json_expression(result) }
end
shared_examples_for '201 Created' do
its(:status) { is_expected.to be(201) }
its(:body) { is_expected.to match_json_expression(result) }
end
shared_examples_for '202 Accepted' do
its(:status) { is_expected.to be(202) }
its(:body) { is_expected.to match_json_expression(result) }
end
shared_examples_for '204 No Content' do
describe '#status' do
subject { super().status }
it { is_expected.to be(204) }
end
describe '#body' do
subject { super().body }
it { is_expected.to eq('') }
end
end
shared_examples_for '400 Bad Request' do
its(:status) { is_expected.to be(400) }
its(:body) { is_expected.to match_json_expression(error: wildcard_matcher) }
end
shared_examples_for '401 Unauthorized' do
its(:status) { is_expected.to be(401) }
its(:body) { is_expected.to match_json_expression(error: wildcard_matcher) }
end
shared_examples_for '403 Forbidden' do
its(:status) { is_expected.to be(403) }
its(:body) { is_expected.to match_json_expression(error: wildcard_matcher) }
end
shared_examples_for '404 Not Found' do
describe '#status' do
subject { super().status }
it { is_expected.to be(404) }
end
describe '#body' do
subject { super().body }
it { is_expected.to match_json_expression(error: 'Not Found') }
end
end
shared_examples_for '422 Unprocessable Entity' do
describe '#status' do
subject { super().status }
it { is_expected.to be(422) }
end
describe '#body' do
subject { super().body }
it { is_expected.to match_json_expression(message: '422 Unprocessable Entity') }
end
end
end
|
mitixx/abilitysheet
|
spec/systems/sheets/power_sheet_spec.rb
|
<reponame>mitixx/abilitysheet<gh_stars>10-100
# frozen_string_literal: true
feature '地力値表', type: :system do
given(:user) { create(:user, id: 1) }
background do
visit sheet_path(iidxid: user.iidxid, type: 'power')
end
scenario '存在しないユーザへのアクセス' do
visit sheet_path(iidxid: '1111-1111', type: 'power')
expect(page).to have_content('このページは存在しません')
end
context 'ログイン時' do
background { login(user) }
scenario 'iidx.meの文字が存在する' do
expect(page).to have_content('iidx.me')
end
end
context '非ログイン時' do
scenario 'iidx.meの文字が存在する' do
expect(page).to have_content('iidx.me')
end
end
end
|
mitixx/abilitysheet
|
db/migrate/20150112192519_create_sheets.rb
|
<filename>db/migrate/20150112192519_create_sheets.rb<gh_stars>10-100
class CreateSheets < ActiveRecord::Migration[5.1]
def change
create_table :sheets do |t|
t.string :title
t.integer :n_ability
t.integer :h_ability
t.integer :version
t.boolean :active, null: false, default: true
t.string :textage
t.timestamps null: false
end
end
end
|
mitixx/abilitysheet
|
app/controllers/logs_controller.rb
|
<gh_stars>10-100
# frozen_string_literal: true
require 'ist_client'
class LogsController < ApplicationController
before_action :load_user, only: %i[sheet list show]
before_action :authenticate_user!, only: %i[edit update ist destroy]
def edit
@log = current_user.logs.find(params[:id])
render :show_modal
end
def update
log = current_user.logs.find(params[:id])
log.update(log_params) if params['log']['created_date'].to_date
render :reload
end
def sheet
@color = Static::COLOR
@title = 'クリア推移表'
@sheets = ClearingTransitionTableService.new(@user).execute
end
def list
per_num = 10
logs = @user.logs.order(created_date: :desc).select(:created_date).distinct
@logs = logs.page(params[:page]).per(per_num)
@total_pages = (logs.count / per_num.to_f).ceil
end
def ist
current_user.check_ist_user
IstSyncJob.perform_later(current_user)
flash[:notice] = %(同期処理を承りました。逐次反映を行います。)
flash[:danger] = %(反映されていない場合はISTに該当IIDXIDが存在しないと思われます。(登録しているけど一度もIST側でスコアを送っていないなど))
render :reload
rescue IstClient::NotFoundUser
flash[:danger] = %(IST側でユーザが見つけられませんでした。現在のバージョンでスコアを送信しているか確認してください。)
render :reload
end
def show
date = params[:date].to_date
@logs = Log.where(user_id: @user.id, created_date: date).preload(:sheet)
unless @logs.present?
render_404
return
end
@prev_update, @next_update = Log.prev_next(@user.id, date)
@color = Static::COLOR
end
def destroy
log = current_user.owner? ? Log.find(params[:id]) : current_user.logs.find(params[:id])
if log
flash[:notice] = "#{log.title}のログを削除し,状態を戻しました"
log.destroy
else
flash[:notice] = '存在しないログデータです'
end
if log && current_user.logs.where(created_date: log.created_date).count.zero?
redirect_to list_log_path(current_user.iidxid)
else
render :reload
end
end
private
def load_user
@user = User.find_by_iidxid!(params[:id])
end
def log_params
params.require(:log).permit(:created_date)
end
end
|
mitixx/abilitysheet
|
config/initializers/session_store.rb
|
<reponame>mitixx/abilitysheet<gh_stars>10-100
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
Rails.application.config.session_store :cookie_store, key: '_abilitysheet_session', secure: Rails.env.production? || Rails.env.staging?
|
mitixx/abilitysheet
|
app/controllers/users/omniauth_callbacks_controller.rb
|
# frozen_string_literal: true
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
before_action :authenticate_user!
def google_oauth2
callback_from :google_oauth2
end
private
def auth
request.env['omniauth.auth']
end
def callback_from(provider)
@provider = provider.to_s
@user = User.find_for_oauth(auth, current_user)
if @user.nil?
user_nil_case
elsif @user.persisted?
user_persisted_case
end
end
def user_nil_case
# NOTE: 連携アカウントのメアドで登録はしているが未連携の場合
if User.exists?(email: auth.info.email)
flash[:danger] = "#{auth.info.email}は登録済みですが、未連携です"
redirect_to oauth_helps_url
return
end
# NOTE: 新規ユーザの場合
# .find_for_oauthで@userが見つからないので @user.nil? => true
flash[:danger] = '最初に登録が必要です。'
redirect_to new_user_registration_url
end
def user_persisted_case
# NOTE: 既に連携済のユーザがログインに利用した場合
# 未ログインのためcurrent_userはnilだが、auth情報から@userが引けるため
if current_user.nil?
sign_in @user
flash[:notice] = "#{@provider.split('_')[0].capitalize}を利用したログインに成功しました"
redirect_to after_sign_in_path_for(:user)
return
end
# NOTE: 登録済ユーザが連携を行おうとした場合
# current_userがnilではなく、@userが引けるケース
flash[:notice] = '連携に成功しました'
redirect_to edit_user_registration_path
end
end
|
mitixx/abilitysheet
|
db/migrate/20191010113324_add_score_index.rb
|
class AddScoreIndex < ActiveRecord::Migration[6.0]
def change
add_index :scores, %i[user_id version updated_at]
end
end
|
mitixx/abilitysheet
|
app/controllers/api/v1/scores_controller.rb
|
<gh_stars>10-100
# frozen_string_literal: true
class Api::V1::ScoresController < Api::V1::BaseController
before_action :load_user
before_action :authenticate!, only: :update
def show
render json: { scores: @user.scores.is_active.is_current_version.preload(:sheet).map(&:schema) }
end
def detail
sheet = Sheet.find(params[:sheet_id])
render json: {
title: sheet.title,
scores: @user.scores.includes(:sheet).where(sheet_id: params[:sheet_id]).order(version: :desc).map(&:schema),
textage: sheet.textage
}
end
def update
sheet = Sheet.find(params[:sheet_id])
score = @user.scores.is_current_version.find_by_sheet_id(sheet.id)
score ||= @user.scores.create(sheet_id: sheet.id, version: Abilitysheet::Application.config.iidx_version)
score.update_with_logs(sheet_id: sheet.id, state: params[:state])
render json: score.schema
end
private
def load_user
@user = User.find_by_iidxid!(params[:iidxid] || params[:score_iidxid])
end
end
|
mitixx/abilitysheet
|
app/controllers/application_controller.rb
|
# frozen_string_literal: true
class ApplicationController < ActionController::Base
before_action :set_raven_context
# protect_from_forgery with: :exception
# refs: https://github.com/rails/rails/issues/24257
# refs: https://github.com/plataformatec/devise/pull/4033/files
protect_from_forgery prepend: true
before_action :configure_permitted_parameters, if: :devise_controller?
after_action :add_response_header_user_id
rescue_from ActionController::RoutingError, ActiveRecord::RecordNotFound, with: :render_404
protected
def detect_device_variant
return if params[:device] == 'pc'
case request.user_agent
when /iPhone|Android|Nokia|Mobile/
request.variant = :mobile
end
end
def render_404
render file: Rails.root.join('public', '404.html'), status: 404, layout: false, content_type: 'text/html'
end
def check_xhr
return if request.xhr?
render_404
end
def configure_permitted_parameters
allow_parameters = %i[email username iidxid djname grade pref]
devise_parameter_sanitizer.permit(:sign_up, keys: allow_parameters)
devise_parameter_sanitizer.permit(:account_update, keys: allow_parameters)
end
def admin_user!
return true if current_user.admin?
flash[:danger] = '許可されていないページです'
redirect_to root_path
end
def special_user!
return if current_user.special?
flash[:danger] = '不正な操作です.'
redirect_to list_log_path
end
def owner_user!
return if current_user.owner?
flash[:danger] = '許可されていないページです'
redirect_to root_path
end
def member_user!
return if current_user.member?
flash[:danger] = '許可されていないページです'
redirect_to root_path
end
def handle_unverified_request
super
rescue ActionController::InvalidAuthenticityToken => e
Raven.capture_exception(e)
flash[:danger] = 'ページの有効期限が切れています,再度お試し下さい'
redirect_to root_path
end
private
def set_raven_context
Raven.user_context(user: current_user.attributes) if current_user
Raven.extra_context(params: params.to_unsafe_h, url: request.url)
end
def add_response_header_user_id
response.set_header('X-User-Id', current_user&.iidxid.to_s)
end
end
|
mitixx/abilitysheet
|
spec/requests/users_spec.rb
|
# frozen_string_literal: true
describe Api::V1::UsersController, type: :request do
include_context 'api'
describe 'GET /api/v1/users/me' do
before { create(:user) }
describe 'ユーザのログイン状態を返す' do
let(:url) { '/api/v1/users/me' }
let(:method) { 'get' }
context 'ログインしていない場合' do
let(:result) do
{ current_user: nil }
end
it_behaves_like '200 Success'
end
context 'ログインしている場合' do
before { login(User.first) }
let(:result) do
{
current_user: {
id: Integer,
iidxid: String,
djname: String,
role: Integer,
follows: Array,
grade: Integer,
pref: Integer,
created_at: String,
followers: Array,
image_url: nil
}
}
end
it_behaves_like '200 Success'
end
end
end
describe 'GET /api/v1/users/status' do
before { create(:user) }
describe 'ユーザのログイン状態を返す' do
let(:url) { '/api/v1/users/status' }
let(:method) { 'get' }
context 'ログインしていない場合' do
let(:result) do
{ status: nil }
end
it_behaves_like '200 Success'
end
context 'ログインしている場合' do
before { login(User.first) }
let(:result) do
{ status: User.first.iidxid }
end
it_behaves_like '200 Success'
end
end
end
end
|
mitixx/abilitysheet
|
app/controllers/admin/mails_controller.rb
|
# frozen_string_literal: true
class Admin::MailsController < ApplicationController
before_action :authenticate_user!
before_action :admin_user!
def new; end
def create
NoticeMail.form_deal(params[:email_address], params[:subject], params[:body]).deliver
flash[:notice] = %(メールを送信しました)
redirect_to new_admin_mail_path
end
end
|
mitixx/abilitysheet
|
spec/factories/users.rb
|
<gh_stars>10-100
# frozen_string_literal: true
# == Schema Information
#
# Table name: users
#
# id :bigint(8) not null, primary key
# email :string default(""), not null
# username :string default(""), not null
# encrypted_password :string default(""), not null
# reset_password_token :string
# reset_password_sent_at :datetime
# remember_created_at :datetime
# sign_in_count :integer default(0), not null
# current_sign_in_at :datetime
# last_sign_in_at :datetime
# current_sign_in_ip :inet
# last_sign_in_ip :inet
# iidxid :string not null
# version :integer default(22), not null
# djname :string not null
# grade :integer
# pref :integer not null
# role :integer default(0), not null
# failed_attempts :integer default(0), not null
# unlock_token :string
# locked_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_users_on_iidxid (iidxid) UNIQUE
# index_users_on_reset_password_token (reset_password_token) UNIQUE
# index_users_on_unlock_token (unlock_token) UNIQUE
# index_users_on_username (username) UNIQUE
#
FactoryBot.define do
factory :user do
sequence(:email) { |n| "<EMAIL>" }
djname { 'TEST' }
iidxid { '1234-5678' }
grade { Abilitysheet::Application.config.iidx_grade }
pref { 0 }
username { 'test' }
password { '<PASSWORD>' }
role { 100 }
end
end
|
mitixx/abilitysheet
|
config/initializers/sidekiq.rb
|
redis_params = { url: ENV['REDIS_URL'] }
Sidekiq.configure_server do |config|
config.redis = redis_params
end
Sidekiq.configure_client do |config|
config.redis = redis_params
end
Sidekiq.default_worker_options = { retry: 0 }
schedule_file = 'config/schedule.yml'
if File.exist?(schedule_file) && Sidekiq.server?
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
end
|
mitixx/abilitysheet
|
app/services/clearing_transition_table_service.rb
|
<reponame>mitixx/abilitysheet
# frozen_string_literal: true
class ClearingTransitionTableService < ApplicationService
def initialize(user)
super()
@user_id = user.id
end
def execute
hash = {}
sheets = Sheet.active.joins(:logs).select('sheets.title, logs.new_state, logs.created_date').where('logs.user_id = ? AND logs.new_state != logs.pre_state', @user_id)
sheets.each do |sheet|
hash[sheet.title] ||= {}
next if hash[sheet.title][sheet.new_state] && hash[sheet.title][sheet.new_state] > sheet.created_date
hash[sheet.title][sheet.new_state] = sheet.created_date
end
hash
end
end
|
mitixx/abilitysheet
|
spec/models/user_ist_spec.rb
|
# frozen_string_literal: true
# == Schema Information
#
# Table name: follows
#
# id :integer not null, primary key
# user_id :integer
# target_user_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
require 'ist_client'
describe User::Ist, type: :model do
describe '#update_ist' do
let(:user) { create(:user, grade: 18, iidxid: '8594-9652', djname: 'HOGE', pref: 0) }
let(:version) { Abilitysheet::Application.config.iidx_version }
it 'ユーザ情報が正しく更新できる' do
VCR.use_cassette('sync_sheet') do
RedisHelper.load_sheets_data
sync_sheet
end
expect(user.avatar.attached?).to be_falsey
VCR.use_cassette('ist') do
user.update_ist
end
expect(user.avatar.attached?).to be_truthy
expect(user.djname).to eq '839'
expect(user.grade).to eq 4
expect(user.pref).to eq 37
end
it 'スコアレコードが更新されている' do
VCR.use_cassette('sync_sheet') do
RedisHelper.load_sheets_data
sync_sheet
end
VCR.use_cassette('ist') do
user.update_ist
end
scores = user.scores.is_current_version
# スコアレコードが更新されている
expect(scores.find_by(sheet: Sheet.find_by(title: 'AA'))).to have_attributes(
version: version,
state: 0,
score: 3045,
bp: 6
)
# ログが作られている
expect(user.logs.find_by(sheet_id: Sheet.find_by(title: 'AA'))).to have_attributes(
version: version,
pre_state: 7,
new_state: 0,
pre_score: nil,
new_score: 3045,
pre_bp: nil,
new_bp: 6
)
end
it 'クリアランプだけでも更新されている' do
VCR.use_cassette('sync_sheet') do
RedisHelper.load_sheets_data
sync_sheet
end
# クリアランプだけ変わるケースの確認用
user.scores.create!(
sheet_id: Sheet.find_by(title: '東京神話').id,
state: 4,
score: nil,
bp: nil,
version: version
)
expect do
VCR.use_cassette('ist') do
user.update_ist
end
end.to change { Log.count }.by(261)
scores = user.scores.is_current_version
# クリアランプの変更だけでもスコアレコードが更新されている
expect(scores.find_by(sheet: Sheet.find_by(title: '東京神話'))).to have_attributes(
version: version,
state: 2,
score: 0,
bp: 0
)
# クリアランプの変更だけでもログが作られている
expect(user.logs.find_by(sheet_id: Sheet.find_by(title: '東京神話'))).to have_attributes(
version: version,
pre_state: 4,
new_state: 2,
pre_score: nil,
new_score: 0,
pre_bp: nil,
new_bp: 0
)
end
it '既に同じデータがある場合はログが作られない' do
VCR.use_cassette('sync_sheet') do
RedisHelper.load_sheets_data
sync_sheet
end
# 同じデータがない場合は261件ログが増える
# 同じデータを意図的に作ってログのデータが減ることを確認する
user.scores.create!(
sheet_id: Sheet.find_by(title: '東京神話').id,
state: 2,
score: 0,
bp: 0,
version: version
)
expect do
VCR.use_cassette('ist') do
user.update_ist
end
end.to change { Log.count }.by(260)
end
it '存在しないユーザはraiseすること' do
user.update!(iidxid: '1234-5678')
VCR.use_cassette('not_found_ist') do
expect { user.update_ist }.to raise_error IstClient::NotFoundUser
end
end
end
context 'module method' do
let(:test_class) { Struct.new(:test_class) { include User::Ist } }
let(:instance) { test_class.new }
describe '#find_pref' do
it('海外なら0を返すこと') { expect(instance.find_pref('海外')).to eq 0 }
it('北海道なら1を返すこと') { expect(instance.find_pref('北海道')).to eq 1 }
it('香川県なら37を返すこと') { expect(instance.find_pref('香川県')).to eq 37 }
it('沖縄県なら47を返すこと') { expect(instance.find_pref('沖縄県')).to eq 47 }
it('香港なら48を返すこと') { expect(instance.find_pref('香港')).to eq 48 }
end
describe '#find_grade' do
it('SP --なら19を返すこと') { expect(instance.find_grade('SP --')).to eq 19 }
it('SP 七級なら18を返すこと') { expect(instance.find_grade('SP 七級')).to eq 18 }
it('SP 中伝なら1を返すこと') { expect(instance.find_grade('SP 中伝')).to eq 1 }
it('SP 皆伝なら0を返すこと') { expect(instance.find_grade('SP 皆伝')).to eq 0 }
end
describe '#update_user' do
let(:instance) { create(:user, djname: 'HOGE', pref: 1, grade: 5) }
it 'emojiユーザはdjnameだけ更新されないこと' do
user = {
'user_activity' => {
'djname' => '♨',
'pref_status' => '東京都',
'sp_grade_status' => 'SP 八段'
},
'image_path' => 'https://score.iidx.app/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZ<KEY>--7b255d5e81086f819b59e59c38debecaa6a6caba/avatar.png'
}
VCR.use_cassette('invalid_djname_ist') { instance.update_user(user) }
expect(instance.pref).to eq 13
expect(instance.grade).to eq 4
expect(instance.djname).to eq 'HOGE'
end
end
end
end
|
mitixx/abilitysheet
|
app/controllers/api/v1/statics_controller.rb
|
<reponame>mitixx/abilitysheet
# frozen_string_literal: true
class Api::V1::StaticsController < Api::V1::BaseController
def index
render json: {
grade: User::Static::GRADE.zip(User::Static::GRADE_COLOR).map { |grade, grade_color| { grade => grade_color } },
pref: User::Static::PREF
}
end
end
|
mitixx/abilitysheet
|
lib/ist_client.rb
|
# frozen_string_literal: true
class IstClient
class NotFoundUser < StandardError; end
def initialize(url = 'https://score.iidx.app')
@url = url
end
def get_scores(iidxid, params)
endpoint = @url + "/api/v1/scores/#{iidxid}?" + params.to_query
body = Net::HTTP.get(URI.parse(endpoint))
JSON.parse(body)
end
def get_musics(params)
endpoint = "#{@url}/api/v1/musics?#{params.to_query}"
body = Net::HTTP.get(URI.parse(endpoint))
JSON.parse(body)
end
def get_user(iidxid)
endpoint = @url + "/api/v1/users/#{iidxid}"
resp = Net::HTTP.get_response(URI.parse(endpoint))
raise NotFoundUser if resp.code == '404'
hash = JSON.parse(resp.body)
return hash unless hash['image_path']
hash['image_path'] = @url + hash['image_path']
hash
end
end
|
mitixx/abilitysheet
|
app/controllers/api/v1/health_check_controller.rb
|
<reponame>mitixx/abilitysheet<filename>app/controllers/api/v1/health_check_controller.rb<gh_stars>10-100
# frozen_string_literal: true
class Api::V1::HealthCheckController < Api::V1::BaseController
def index
ActiveRecord::Base.connection.execute('select 1')
client = Redis.new(url: ENV['REDIS_URL'])
client.ping
render :ok
end
end
|
mitixx/abilitysheet
|
db/migrate/20151219233629_create_follows.rb
|
class CreateFollows < ActiveRecord::Migration[5.1]
def change
create_table :follows do |t|
t.integer :user_id
t.integer :target_user_id
t.timestamps null: false
end
add_index :follows, [:user_id, :target_user_id], unique: true
end
end
|
mitixx/abilitysheet
|
config/initializers/sentry.rb
|
# frozen_string_literal: true
logger = ::Logger.new('log/raven.log')
logger.level = ::Logger::DEBUG
Raven.configure do |config|
config.logger = logger
config.dsn = ENV['SENTRY_DSN']
config.environments = %w(staging production)
config.current_environment = Rails.env
config.release = ENV.fetch('RELEASE', 'vx.y.z')
end
|
mitixx/abilitysheet
|
spec/requests/logs_spec.rb
|
# frozen_string_literal: true
describe Api::V1::LogsController, type: :request do
include_context 'api'
describe 'GET /api/v1/logs/graph/1111-1111/2016/2' do
before do
create(:user, iidxid: '1111-1111', id: 1)
end
let(:url) { '/api/v1/logs/graph/1111-1111/2016/2' }
let(:method) { 'get' }
let(:result) do
{
categories: %w[2015-12 2016-01 2016-02],
pie: [0, 0, 0, 0, 0, 0, 0, 0],
column: [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
],
column_max: 0,
spline: [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
],
spline_max: 0
}
end
it_behaves_like '200 Success'
end
describe 'GET /api/v1/logs/1111-1111/2016/3' do
before do
create(:sheet, id: 1, title: 'logs sample')
create(:sheet, id: 2, title: 'logs sample2')
create(:user, iidxid: '1111-1111', id: 1)
create(:log, sheet_id: 2, user_id: 1, new_state: 4, created_date: '2016-02-03')
create(:log, sheet_id: 1, user_id: 1, new_state: 3, created_date: '2016-03-01')
create(:log, sheet_id: 2, user_id: 1, new_state: 1, created_date: '2016-03-03')
end
let(:url) { '/api/v1/logs/1111-1111/2016/3' }
let(:method) { 'get' }
let(:result) do
{
logs: [
{
state: 3,
title: 'logs sample',
created_date: '2016-03-01'
},
{
state: 1,
title: 'logs sample2',
created_date: '2016-03-03'
}
]
}
end
it_behaves_like '200 Success'
end
end
|
mitixx/abilitysheet
|
spec/models/social_spec.rb
|
<gh_stars>10-100
# frozen_string_literal: true
# == Schema Information
#
# Table name: socials
#
# id :bigint(8) not null, primary key
# provider :string
# raw :json
# secret :string
# token :string
# uid :string
# user_id :bigint(8)
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_socials_on_user_id_and_provider (user_id,provider) UNIQUE
#
describe Social, type: :model do
end
|
mitixx/abilitysheet
|
spec/systems/users/show_spec.rb
|
# frozen_string_literal: true
feature 'プロフィールページ', type: :system, js: true do
given(:user) { create(:user, id: 1, djname: 'PROF', iidxid: '1111-1111', pref: 0, grade: 4, created_at: '2016-03-06') }
context '非ログイン時' do
background do
create(:score, user_id: 1, sheet_id: 1)
visit user_path(user.iidxid)
end
scenario 'DJNAMEが存在する' do
expect(page).to have_content('PROF')
end
scenario 'IIDXIDが存在する' do
expect(page).to have_content('1111-1111')
end
scenario 'ノマゲ参考表のリンクが存在する' do
expect(page).to have_link('ノマゲ参考表')
end
scenario 'ハード参考表のリンクが存在する' do
expect(page).to have_link('ハード参考表')
end
scenario '段位が存在する' do
expect(page).to have_content('八段')
end
scenario '所属が存在する' do
expect(page).to have_content('海外')
end
scenario '登録日が存在する' do
expect(page).to have_content('Joined on 2016/03/06')
end
scenario '統計情報が存在する' do
expect(page).to have_content('統計情報')
end
scenario '更新履歴が存在する' do
expect(page).to have_content('更新履歴')
end
scenario 'ノマゲ比較が存在しない' do
expect(page).to have_no_content('ノマゲ比較')
end
scenario 'ハード比較が存在しない' do
expect(page).to have_no_content('ハード比較')
end
scenario 'ライバル追加/削除が存在しない' do
expect(page).to have_no_link('ライバルから削除')
expect(page).to have_no_link('ライバルに追加')
end
scenario 'ライバル/逆ライバルの数が表示されている' do
expect(page).to have_selector('#rival-number', text: '0')
expect(page).to have_selector('#reverse-rival-number', text: '0')
end
end
context 'ログイン時' do
background do
user2 = create(:user, username: 'user2', id: 2, grade: 4)
login(user2)
visit user_path(user.iidxid)
end
scenario 'DJNAMEが存在する' do
expect(page).to have_content('PROF')
end
scenario 'IIDXIDが存在する' do
expect(page).to have_content('1111-1111')
end
scenario 'ノマゲ参考表のリンクが存在する' do
expect(page).to have_link('ノマゲ参考表')
end
scenario 'ハード参考表のリンクが存在する' do
expect(page).to have_link('ハード参考表')
end
scenario '段位が存在する' do
expect(page).to have_content('八段')
end
scenario '所属が存在する' do
expect(page).to have_content('海外')
end
scenario '登録日が存在する' do
expect(page).to have_content('Joined on 2016/03/06')
end
scenario '統計情報が存在する' do
expect(page).to have_content('統計情報')
end
scenario '更新履歴が存在する' do
expect(page).to have_content('更新履歴')
end
scenario 'ノマゲ比較が存在する' do
expect(page).to have_content('ノマゲ比較')
end
scenario 'ハード比較が存在する' do
expect(page).to have_content('ハード比較')
end
scenario 'ライバル追加/削除が行える' do
expect(page).to have_link('ライバルに追加')
click_link 'ライバルに追加'
user.reload
expect(page).to have_selector('#reverse-rival-number', text: '1')
expect(user.followers.count).to eq 1
expect(page).to have_link('ライバルから削除')
click_link 'ライバルから削除'
user.reload
expect(page).to have_selector('#reverse-rival-number', text: '0')
expect(user.followers.count).to eq 0
expect(page).to have_link('ライバルに追加')
end
scenario 'ライバル/逆ライバルの数が表示されている' do
expect(page).to have_selector('#rival-number', text: '0')
expect(page).to have_selector('#reverse-rival-number', text: '0')
end
end
end
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.