diff --git a/Gemfile b/Gemfile index e7446b6..46d1cc2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' git_source(:github) do |repo_name| - repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") + repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/') "https://github.com/#{repo_name}.git" end @@ -14,13 +14,13 @@ gem 'pg_search' gem 'omniauth' gem 'omniauth-slack' +gem 'bcrypt' +gem 'bootstrap-sass', '~> 3.3.7' gem 'devise' -gem 'httparty' gem 'figaro' -gem 'twitter' -gem 'bootstrap-sass', '~> 3.3.7' +gem 'httparty' gem 'jquery-rails' -gem 'bcrypt' +gem 'twitter' # Use Puma as the app server gem 'puma', '~> 3.7' @@ -47,7 +47,7 @@ gem 'jbuilder', '~> 2.5' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console - gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + gem 'byebug', platforms: %i[mri mingw x64_mingw] # Adds support for Capybara system testing and selenium driver gem 'capybara', '~> 2.13' gem 'selenium-webdriver' @@ -55,12 +55,12 @@ end group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. - gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' + gem 'web-console', '>= 3.3.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] diff --git a/app/controllers/effin_quotes_controller.rb b/app/controllers/effin_quotes_controller.rb index 742ffbb..ced9033 100644 --- a/app/controllers/effin_quotes_controller.rb +++ b/app/controllers/effin_quotes_controller.rb @@ -9,8 +9,7 @@ def logs @logs = EffinLog.all end - def home - end + def home; end def check @quote = EffinQuote.incomplete.first @@ -49,6 +48,6 @@ def destroy end def quote_params - params.require(:effin_quote).permit(:contents) + params.require(:effin_quote).permit(:contents) end end diff --git a/app/controllers/oauth_controller.rb b/app/controllers/oauth_controller.rb index 01ba409..db07244 100644 --- a/app/controllers/oauth_controller.rb +++ b/app/controllers/oauth_controller.rb @@ -1,35 +1,33 @@ class OauthController < ApplicationController - def authorize - options = { - site: 'https://slack.com/oauth/authorize' - } - client ||= OAuth2::Client.new( - '12060783617.285877762837', - ENV('SLACK_CLIENT_SECRET'), - options - ) - params = { - scope: 'commands', - redirect_uri: 'https://www.effinbot.com/oauth/callback' - } - redirect_to client.auth_code.authorize_url(params) - end - - def success + def authorize + options = { + site: 'https://slack.com/oauth/authorize' + } + client ||= OAuth2::Client.new( + '12060783617.285877762837', + ENV('SLACK_CLIENT_SECRET'), + options + ) + params = { + scope: 'commands', + redirect_uri: 'https://www.effinbot.com/oauth/callback' + } + redirect_to client.auth_code.authorize_url(params) end - def error - end + def success; end + + def error; end - def authorize_callback - code = params["code"] + def authorize_callback + code = params['code'] puts code response = HTTParty.get("https://slack.com/api/oauth.access?code=#{code}&client_id=12060783617.285877762837&client_secret=#{ENV['SLACK_CLIENT_SECRET']}") - if response["ok"] && response["ok"] == true - redirect_to '/success' + if response['ok'] && response['ok'] == true + redirect_to '/success' else - redirect_to '/error' + redirect_to '/error' end - end + end end diff --git a/app/models/effin_quote.rb b/app/models/effin_quote.rb index 114f075..cbabfa3 100644 --- a/app/models/effin_quote.rb +++ b/app/models/effin_quote.rb @@ -1,17 +1,17 @@ class EffinQuote < ApplicationRecord include PgSearch - pg_search_scope :search_by_word, against: [ :contents ] + pg_search_scope :search_by_word, against: [:contents] def complete? url && twitter_url && contents end def self.complete - where("url is not null and twitter_url is not null and contents is not null") + where('url is not null and twitter_url is not null and contents is not null') end def self.incomplete - where("url is null or twitter_url is null or contents is null") + where('url is null or twitter_url is null or contents is null') end def self.find_by_word(word) diff --git a/app/views/effin_quotes/show.json.jbuilder b/app/views/effin_quotes/show.json.jbuilder index ad3e31b..4588aa7 100644 --- a/app/views/effin_quotes/show.json.jbuilder +++ b/app/views/effin_quotes/show.json.jbuilder @@ -1 +1 @@ -json.extract! @quote, :id, :contents, :url, :twitter_url \ No newline at end of file +json.extract! @quote, :id, :contents, :url, :twitter_url diff --git a/bin/setup b/bin/setup index 78c4e86..ca842c1 100755 --- a/bin/setup +++ b/bin/setup @@ -21,7 +21,6 @@ chdir APP_ROOT do # Install JavaScript dependencies if using Yarn # system('bin/yarn') - # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') # cp 'config/database.yml.sample', 'config/database.yml' diff --git a/bin/spring b/bin/spring index fb2ec2e..991bd4e 100755 --- a/bin/spring +++ b/bin/spring @@ -8,7 +8,7 @@ unless defined?(Spring) require 'bundler' lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) - spring = lockfile.specs.detect { |spec| spec.name == "spring" } + spring = lockfile.specs.detect { |spec| spec.name == 'spring' } if spring Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path gem 'spring', spring.version diff --git a/bin/yarn b/bin/yarn index c2bacef..329aee9 100755 --- a/bin/yarn +++ b/bin/yarn @@ -2,10 +2,10 @@ VENDOR_PATH = File.expand_path('..', __dir__) Dir.chdir(VENDOR_PATH) do begin - exec "yarnpkg #{ARGV.join(" ")}" + exec "yarnpkg #{ARGV.join(' ')}" rescue Errno::ENOENT - $stderr.puts "Yarn executable was not detected in the system." - $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + $stderr.puts 'Yarn executable was not detected in the system.' + $stderr.puts 'Download Yarn at https://yarnpkg.com/en/docs/install' exit 1 end end diff --git a/config/environments/production.rb b/config/environments/production.rb index 9c96254..8701d26 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -52,7 +52,7 @@ config.log_level = :debug # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -80,7 +80,7 @@ # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - if ENV["RAILS_LOG_TO_STDOUT"].present? + if ENV['RAILS_LOG_TO_STDOUT'].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) diff --git a/config/puma.rb b/config/puma.rb index 1e19380..ccda173 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -4,16 +4,16 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT') { 3000 } # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV') { 'development' } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together diff --git a/config/routes.rb b/config/routes.rb index 1f180e3..789bdf8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,14 +1,14 @@ Rails.application.routes.draw do devise_for :users - root to: "effin_quotes#home" - + root to: 'effin_quotes#home' + get 'commands/create' - get '/authorize', to: 'oauth#authorize' - get '/oauth/callback', to: 'oauth#authorize_callback' + get '/authorize', to: 'oauth#authorize' + get '/oauth/callback', to: 'oauth#authorize_callback' get '/success', to: 'oauth#success' get '/error', to: 'oauth#error' - resources :effin_quotes, only: [:index, :show, :destroy, :update] do + resources :effin_quotes, only: %i[index show destroy update] do collection do get :find get :incomplete diff --git a/config/spring.rb b/config/spring.rb index c9119b4..9fa7863 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,6 +1,6 @@ -%w( +%w[ .ruby-version .rbenv-vars tmp/restart.txt tmp/caching-dev.txt -).each { |path| Spring.watch(path) } +].each { |path| Spring.watch(path) } diff --git a/db/from_tweets.rb b/db/from_tweets.rb index 951e212..e42117b 100644 --- a/db/from_tweets.rb +++ b/db/from_tweets.rb @@ -1,11 +1,11 @@ client = Twitter::REST::Client.new do |config| - config.consumer_key = ENV("TWITTER_CONSUMER_KEY") - config.consumer_secret = ENV("TWITTER_CONSUMER_SECRET") - config.access_token = ENV("TWITTER_ACCESS_TOKEN") - config.access_token_secret = ENV("TWITTER_ACCESS_TOKEN_SECRET") + config.consumer_key = ENV('TWITTER_CONSUMER_KEY') + config.consumer_secret = ENV('TWITTER_CONSUMER_SECRET') + config.access_token = ENV('TWITTER_ACCESS_TOKEN') + config.access_token_secret = ENV('TWITTER_ACCESS_TOKEN_SECRET') end -tweets = client.get_all_tweets("effinbirds") +tweets = client.get_all_tweets('effinbirds') raw = tweets.map do |t| next unless t.media && t.media.first && t.media.first.uri @@ -21,7 +21,7 @@ EffinQuote.create(url: r.first.to_s, twitter_url: r.second.to_s) end -def collect_with_max_id(collection=[], max_id=nil, &block) +def collect_with_max_id(collection = [], max_id = nil, &block) response = yield(max_id) collection += response response.empty? ? collection.flatten : collect_with_max_id(collection, response.last.id - 1, &block) @@ -29,7 +29,7 @@ def collect_with_max_id(collection=[], max_id=nil, &block) def client.get_all_tweets(user) collect_with_max_id do |max_id| - options = {count: 200, include_rts: true} + options = { count: 200, include_rts: true } options[:max_id] = max_id unless max_id.nil? user_timeline(user, options) end diff --git a/db/migrate/20171220175659_devise_create_users.rb b/db/migrate/20171220175659_devise_create_users.rb index 5a1bfb6..b88380e 100644 --- a/db/migrate/20171220175659_devise_create_users.rb +++ b/db/migrate/20171220175659_devise_create_users.rb @@ -2,8 +2,8 @@ class DeviseCreateUsers < ActiveRecord::Migration[5.1] def change create_table :users do |t| ## Database authenticatable - t.string :email, null: false, default: "" - t.string :encrypted_password, null: false, default: "" + t.string :email, null: false, default: '' + t.string :encrypted_password, null: false, default: '' ## Recoverable t.string :reset_password_token @@ -30,7 +30,6 @@ def change # t.string :unlock_token # Only if unlock strategy is :email or :both # t.datetime :locked_at - t.timestamps null: false end diff --git a/db/schema.rb b/db/schema.rb index 8c6ff9d..7296f74 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,45 +10,44 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171221102153) do - +ActiveRecord::Schema.define(version: 20_171_221_102_153) do # These are extensions that must be enabled in order to support this database - enable_extension "plpgsql" + enable_extension 'plpgsql' - create_table "effin_logs", force: :cascade do |t| - t.bigint "effin_quote_id" - t.string "text" - t.boolean "random" - t.string "team_doman" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["effin_quote_id"], name: "index_effin_logs_on_effin_quote_id" + create_table 'effin_logs', force: :cascade do |t| + t.bigint 'effin_quote_id' + t.string 'text' + t.boolean 'random' + t.string 'team_doman' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['effin_quote_id'], name: 'index_effin_logs_on_effin_quote_id' end - create_table "effin_quotes", force: :cascade do |t| - t.string "contents" - t.string "url" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "twitter_url" + create_table 'effin_quotes', force: :cascade do |t| + t.string 'contents' + t.string 'url' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.string 'twitter_url' end - create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.inet "current_sign_in_ip" - t.inet "last_sign_in_ip" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["email"], name: "index_users_on_email", unique: true - t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + create_table 'users', force: :cascade do |t| + t.string 'email', default: '', null: false + t.string 'encrypted_password', default: '', null: false + t.string 'reset_password_token' + t.datetime 'reset_password_sent_at' + t.datetime 'remember_created_at' + t.integer 'sign_in_count', default: 0, null: false + t.datetime 'current_sign_in_at' + t.datetime 'last_sign_in_at' + t.inet 'current_sign_in_ip' + t.inet 'last_sign_in_ip' + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + t.index ['email'], name: 'index_users_on_email', unique: true + t.index ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true end - add_foreign_key "effin_logs", "effin_quotes" + add_foreign_key 'effin_logs', 'effin_quotes' end diff --git a/db/seeds.rb b/db/seeds.rb index 79bb0d2..8e9ae20 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -14,7 +14,7 @@ # { # contents: "got it you're dim", # url: "https://pbs.twimg.com/media/DQ117aPW4AEmnWF.jpg" -# }, +# }, # { # contents: "where is your fucking brain", # url: "https://pbs.twimg.com/media/DQxjO2fWsAEFIMd.jpg" @@ -23,4 +23,4 @@ # contents: "I am not your fucking mom", # url: "https://pbs.twimg.com/media/DQwsRAzXcAAIV-n.jpg" # } -# ]) \ No newline at end of file +# ]) diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index d19212a..23701b4 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -1,4 +1,4 @@ -require "test_helper" +require 'test_helper' class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400] diff --git a/test/controllers/commands_controller_test.rb b/test/controllers/commands_controller_test.rb index e247364..e409182 100644 --- a/test/controllers/commands_controller_test.rb +++ b/test/controllers/commands_controller_test.rb @@ -1,9 +1,8 @@ require 'test_helper' class CommandsControllerTest < ActionDispatch::IntegrationTest - test "should get create" do + test 'should get create' do get commands_create_url assert_response :success end - end diff --git a/test/controllers/effin_quotes_controller_test.rb b/test/controllers/effin_quotes_controller_test.rb index 846424e..77d013a 100644 --- a/test/controllers/effin_quotes_controller_test.rb +++ b/test/controllers/effin_quotes_controller_test.rb @@ -1,19 +1,18 @@ require 'test_helper' class EffinQuotesControllerTest < ActionDispatch::IntegrationTest - test "should get index" do + test 'should get index' do get effin_quotes_index_url assert_response :success end - test "should get show" do + test 'should get show' do get effin_quotes_show_url assert_response :success end - test "should get find" do + test 'should get find' do get effin_quotes_find_url assert_response :success end - end