Skip to content

Commit

Permalink
Merge pull request #64 from true-runes/development
Browse files Browse the repository at this point in the history
v1.2.0
  • Loading branch information
nikukyugamer committed May 31, 2021
2 parents 01452a9 + ed9a651 commit d5fe002
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 107 deletions.
119 changes: 62 additions & 57 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,64 @@
version: 2.1

orbs:
slack: circleci/slack@4.1
jobs:
build:

executors:
rails_executor:
docker:
- image: circleci/ruby:3.0.1
- image: circleci/postgres:12.2
# https://hub.docker.com/r/cimg/ruby
- image: cimg/ruby:<< parameters.ruby_version_tag >>
# https://github.com/CircleCI-Public/circleci-dockerfiles/tree/master/postgres/images
- image: circleci/postgres:<< parameters.pg_version_tag >>
environment:
- POSTGRES_USER: suikoden_election_2021
- POSTGRES_PASSWORD: suikoden_election_2021
- POSTGRES_USER: root
- POSTGRES_PASSWORD: postgres
- POSTGRES_DB: suikoden_election_2021_test
working_directory: ~/repo
parameters:
ruby_version_tag:
type: string
default: '3.0.1'
pg_version_tag:
type: string
default: '13.2'

jobs:
build:
executor:
name: rails_executor
ruby_version_tag: '3.0.1'
pg_version_tag: '13.2'
environment:
TZ: "Asia/Tokyo"
working_directory: ~/working_directory
steps:
- checkout
# TODO: Setup Database, bundle install, bundle exec rubocop, bundle exec rspec
- restore_cache:
name: Restore RubyGems Cache
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
- v1-dependencies-
- restore_cache:
name: Restore Yarn Cache
keys:
- yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-packages-v1-{{ .Branch }}-
- yarn-packages-v1-
- run:
name: Install Bundler 2
name: Prepare the artifact directory
command: |
gem install bundler
mkdir /tmp/bluemoon
- run:
name: Hello, World!
command: |
echo 'Hello, World!'
- run:
name: Install Yarn
name: Check Ruby version
command: |
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update -y && sudo apt-get install yarn -y
ruby -v > /tmp/my_artifact
- run:
name: Check the installed Ruby path
command: |
which ruby > /tmp/bluemoon/which_ruby.txt
- run:
name: Install the latest Bundler
command: |
gem install bundler
- run:
name: Bundle install
command: |
Expand All @@ -44,43 +69,18 @@ jobs:
paths:
- ./vendor/bundle
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
- save_cache:
name: Save Yarn Cache
paths:
- ~/.cache/yarn
key: yarn-packages-v1-{{ .Branch }}-{{ checksum "yarn.lock" }}
- run:
name: $ yarn install を行う
name: Execute RuboCop
command: |
yarn install
# - run:
# name: $ bundle exec rails db:create を行う
# command: |
# bundle exec rails db:create
# - run:
# name: $ bundle exec rails db:migrate を行う
# command: |
# bundle exec rails db:migrate
# - run:
# name: $ bundle exec rails db:seed を行う
# command: |
# bundle exec rails db:seed
# - run:
# name: RuboCop
# command: bundle exec rubocop -D -E -S -P
# - run:
# name: run tests
# command: |
# mkdir /tmp/test-results
# TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
# circleci tests split --split-by=timings)"

# bundle exec rspec \
# --format progress \
# --format RspecJunitFormatter \
# --out /tmp/test-results/rspec.xml \
# --format progress \
# $TEST_FILES
bundle exec rubocop
- run:
name: Execute RSpec
command: |
mkdir -p /tmp/test_results /tmp/screenshots
bundle exec rspec --format progress \
--format RspecJunitFormatter \
--out /tmp/test_results/rspec.xml \
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
- slack/notify:
channel: notice-circleci
event: always
Expand All @@ -99,8 +99,13 @@ jobs:
}
]
}
- store_artifacts:
path: /tmp/my_artifact
destination: discord_log_storage
- store_artifacts:
path: /tmp/bluemoon
- store_test_results:
path: /tmp/test-results
path: /tmp/test_results
- store_artifacts:
path: /tmp/test-results
destination: test-results
path: /tmp/screenshots
destination: rspec_screenshot
87 changes: 46 additions & 41 deletions .github/workflows/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,32 @@ jobs:
image: ruby:3.0.1
env:
BUNDLE_PATH: vendor/bundle
RAILS_ENV: test
POSTGRES_HOST_TEST: postgres
RAILS_DATABASE_USER: postgres
RAILS_DATABASE_PASSWORD: postgres
services:
postgres:
image: postgres:12.2
image: postgres:13.2
ports:
- 5432:5432
env:
POSTGRES_USER: suikoden_election_2021
POSTGRES_PASSWORD: suikoden_election_2021
POSTGRES_USER_TEST: suikoden_election_2021
POSTGRES_PASSWORD_TEST: suikoden_election_2021
POSTGRES_USER: root
POSTGRES_PASSWORD: postgres
POSTGRES_USER_TEST: root
POSTGRES_PASSWORD_TEST: postgres
POSTGRES_DB: suikoden_election_2021_test
options:
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: 基本パッケージのインストールを行う
run: |
apt-get update
apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget lsof
# - name: 基本パッケージのインストールを行う
# run: |
# apt-get update
# apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget lsof
- name: Yarn のインストールを行う
run: |
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
Expand Down Expand Up @@ -65,35 +70,35 @@ jobs:
- name: $ yarn install を行う
run: |
yarn install
# - name: $ bundle exec rails db:create を行う
# run: |
# bundle exec rails db:create
# env:
# POSTGRES_HOST: postgres
# RAILS_ENV: test
# - name: $ bundle exec rails db:migrate を行う
# run: |
# bundle exec rails db:migrate
# env:
# POSTGRES_HOST: postgres
# RAILS_ENV: test
# - name: $ bundle exec rails db:seed を行う
# run: |
# bundle exec rails db:seed
# env:
# POSTGRES_HOST: postgres
# RAILS_ENV: test
# - name: $ bundle exec rails assets:precompile を行う
# run: |
# bundle exec rails assets:precompile
# - name: RSpec を実行する
# if: always()
# run: |
# bundle exec rspec
# env:
# POSTGRES_HOST: postgres
# RAILS_ENV: test
# - name: RuboCop を実行する
# if: always()
# run: |
# bundle exec rubocop -D -E -S -P
- name: $ bundle exec rails db:create を行う
run: |
bundle exec rails db:create
env:
POSTGRES_HOST_TEST: postgres
RAILS_ENV: test
- name: $ bundle exec rails db:migrate を行う
run: |
bundle exec rails db:migrate
env:
POSTGRES_HOST_TEST: postgres
RAILS_ENV: test
- name: $ bundle exec rails db:seed を行う
run: |
bundle exec rails db:seed
env:
POSTGRES_HOST_TEST: postgres
RAILS_ENV: test
# - name: $ bundle exec rails assets:precompile を行う
# run: |
# bundle exec rails assets:precompile
- name: RSpec を実行する
if: always()
run: |
bundle exec rspec
env:
POSTGRES_HOST_TEST: postgres
RAILS_ENV: test
- name: RuboCop を実行する
if: always()
run: |
bundle exec rubocop -D -E -S -P
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ group :development do
gem 'rubocop-rails'
gem 'spring'
end

group :test do
gem 'rspec_junit_formatter'
end
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ GEM
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.2)
rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.15.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
Expand Down Expand Up @@ -315,6 +317,7 @@ DEPENDENCIES
puma
rails
rspec-rails
rspec_junit_formatter
rubocop-rails
spring
twitter
Expand Down
13 changes: 13 additions & 0 deletions app/lib/selector.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Selector
class << self
# 対象を絞って高速化する
# 'hashtag' には '#' は不要
def excluded_already_existing_tweets_by_hashtag_from_tweet_storage(hashtag)
BySearchWordTweet.where(
search_word: "##{hashtag}"
).where.not(
id_number: Tweet.contains_hashtag(hashtag).pluck(:id_number)
)
end
end
end
25 changes: 22 additions & 3 deletions app/models/tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ class Tweet < ApplicationRecord

scope :not_retweet, -> { where(is_retweet: false) }
scope :be_retweet, -> { where(is_retweet: true) }
scope :with_hashtag, ->(hashtag) { joins(:hashtags).where(hashtags: { text: hashtag }) }
scope :contains_hashtag, ->(hashtag) { joins(:hashtags).where(hashtags: { text: hashtag }) }
scope :mentioned_user, ->(user) { joins(:mentions).where(mentions: { user_id_number: user.id_number }) }

# TODO: TweetStorage の方にも書く
def self.filter_by_tweeted_at(from, to)
where('tweeted_at > ?', from).where('tweeted_at < ?', to)
where(tweeted_at: from..to)
end

def self.valid_votes
begin_datetime = Time.zone.parse('2021-06-11 21:00:00')
end_datetime = Time.zone.parse('2021-06-13 11:59:59')

where(tweeted_at: begin_datetime..end_datetime)
end

def has_this_hashtag?(hashtag)
Expand Down Expand Up @@ -47,7 +54,19 @@ def url
"https://twitter.com/#{user.screen_name}/status/#{id_number}"
end

def url_only_by_id_number
def url_by_id_number_only
"https://twitter.com/twitter/status/#{id_number}"
end

def has_hashtags?
hashtags.present?
end

def has_assets?
assets.present?
end

def has_in_tweet_urls?
in_tweet_urls.present?
end
end
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ def assets; end
def protected?
is_protected
end

def url
"https://twitter.com/#{screen_name}"
end

def url_by_id_number_only
"https://twitter.com/i/user/#{id_number}"
end
end
8 changes: 4 additions & 4 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ development:
test:
<<: *default
database: suikoden_election_2021_test
host: <%= ENV['POSTGRES_HOST_DEVELOPMENT'] || 'localhost' %>
port: <%= ENV['POSTGRES_PORT_DEVELOPMENT'] || 5432 %>
username: <%= ENV['POSTGRES_USERNAME_DEVELOPMENT'] || 'suikoden_election_2021' %>
password: <%= ENV['POSTGRES_PASSWORD_DEVELOPMENT'] || 'suikoden_election_2021' %>
host: <%= ENV['POSTGRES_HOST_TEST'] || 'localhost' %>
port: <%= ENV['POSTGRES_PORT_TEST'] || 5432 %>
username: <%= ENV['POSTGRES_USERNAME_TEST'] || 'root' %>
password: <%= ENV['POSTGRES_PASSWORD_TEST'] || 'postgres' %>

tweet_storage:
<<: *default
Expand Down
10 changes: 9 additions & 1 deletion spec/factories/tweets.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
FactoryBot.define do
factory :tweet do

id_number { 192789663528910849 }
full_text { "おはようございます!\nこんにちは!" }
source { '<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a>' }
in_reply_to_tweet_id_number { nil }
in_reply_to_user_id_number { nil }
is_retweet { false }
language { 'ja' }
is_public { true }
tweeted_at { Time.zone.now.yesterday }
end
end
Loading

0 comments on commit d5fe002

Please sign in to comment.