From fa0b1348ae92816ea6c988c6adcabbcb92e75152 Mon Sep 17 00:00:00 2001 From: Kento Karakawa Date: Thu, 18 Feb 2016 01:17:41 +0900 Subject: [PATCH] =?UTF-8?q?[modify]=20Controller,=20Views=E6=9C=80?= =?UTF-8?q?=E9=81=A9=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + Configファイルを作成し、Controller・Viewsの冗長をなくす + テストフレームワークをMiniTestからRSpecに変更 + Rakefileの中身もConfigを読み込むように変更 --- .gitignore | 1 - .rspec | 3 + Gemfile | 3 + Gemfile.lock | 199 ++++++++++++++++++++ app/controllers/ranking_controller.rb | 11 +- app/views/ranking/history.html.slim | 130 ++----------- config/config.yml | 43 +++++ lib/tasks/crawl_ranking.rake | 52 ++--- spec/rails_helper.rb | 43 +++++ spec/spec_helper.rb | 78 ++++++++ test/controllers/.keep | 0 test/controllers/ranking_controller_test.rb | 7 - test/fixtures/.keep | 0 test/fixtures/videos.yml | 11 -- test/helpers/.keep | 0 test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/models/video_test.rb | 7 - test/test_helper.rb | 10 - 20 files changed, 413 insertions(+), 185 deletions(-) create mode 100644 .rspec create mode 100644 Gemfile.lock create mode 100644 config/config.yml create mode 100644 spec/rails_helper.rb create mode 100644 spec/spec_helper.rb delete mode 100644 test/controllers/.keep delete mode 100644 test/controllers/ranking_controller_test.rb delete mode 100644 test/fixtures/.keep delete mode 100644 test/fixtures/videos.yml delete mode 100644 test/helpers/.keep delete mode 100644 test/integration/.keep delete mode 100644 test/mailers/.keep delete mode 100644 test/models/.keep delete mode 100644 test/models/video_test.rb delete mode 100644 test/test_helper.rb diff --git a/.gitignore b/.gitignore index de84810..659b7c7 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,6 @@ /tmp # Ignore bundler -/Gemfile.lock /vendor/* # Ignore DB seeds diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..0d786ba --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--color +--warnings +--require spec_helper diff --git a/Gemfile b/Gemfile index 6d804da..f3e7ca9 100644 --- a/Gemfile +++ b/Gemfile @@ -38,6 +38,9 @@ gem 'sdoc', '~> 0.4.0', group: :doc gem 'anemone' group :development, :test do + # Test flamework + gem 'rspec-rails', '~> 3.0.0' + # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..5efd266 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,199 @@ +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.2.3) + actionpack (= 4.2.3) + actionview (= 4.2.3) + activejob (= 4.2.3) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.3) + actionview (= 4.2.3) + activesupport (= 4.2.3) + rack (~> 1.6) + rack-test (~> 0.6.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.3) + activesupport (= 4.2.3) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (4.2.3) + activesupport (= 4.2.3) + globalid (>= 0.3.0) + activemodel (4.2.3) + activesupport (= 4.2.3) + builder (~> 3.1) + activerecord (4.2.3) + activemodel (= 4.2.3) + activesupport (= 4.2.3) + arel (~> 6.0) + activesupport (4.2.3) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + anemone (0.7.2) + nokogiri (>= 1.3.0) + robotex (>= 1.0.0) + arel (6.0.3) + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) + builder (3.2.2) + byebug (8.2.2) + coffee-rails (4.1.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.1.x) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.10.0) + concurrent-ruby (1.0.0) + debug_inspector (0.0.2) + diff-lcs (1.2.5) + erubis (2.7.0) + execjs (2.6.0) + globalid (0.3.6) + activesupport (>= 4.1.0) + i18n (0.7.0) + jbuilder (2.4.1) + activesupport (>= 3.0.0, < 5.1) + multi_json (~> 1.2) + jquery-rails (4.1.0) + rails-dom-testing (~> 1.0) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + json (1.8.3) + libv8 (3.16.14.13) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.3) + mime-types (>= 1.16, < 3) + mime-types (2.99) + mini_portile2 (2.0.0) + minitest (5.8.4) + multi_json (1.11.2) + mysql2 (0.3.20) + nokogiri (1.6.7.2) + mini_portile2 (~> 2.0.0.rc2) + rack (1.6.4) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.2.3) + actionmailer (= 4.2.3) + actionpack (= 4.2.3) + actionview (= 4.2.3) + activejob (= 4.2.3) + activemodel (= 4.2.3) + activerecord (= 4.2.3) + activesupport (= 4.2.3) + bundler (>= 1.3.0, < 2.0) + railties (= 4.2.3) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.7) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6.0) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (4.2.3) + actionpack (= 4.2.3) + activesupport (= 4.2.3) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (10.5.0) + rdoc (4.2.2) + json (~> 1.4) + ref (2.0.0) + robotex (1.0.0) + rspec-core (3.0.4) + rspec-support (~> 3.0.0) + rspec-expectations (3.0.4) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.0.0) + rspec-mocks (3.0.4) + rspec-support (~> 3.0.0) + rspec-rails (3.0.2) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.0.0) + rspec-expectations (~> 3.0.0) + rspec-mocks (~> 3.0.0) + rspec-support (~> 3.0.0) + rspec-support (3.0.4) + sass (3.4.21) + sass-rails (5.0.4) + railties (>= 4.0.0, < 5.0) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + sdoc (0.4.1) + json (~> 1.7, >= 1.7.7) + rdoc (~> 4.0) + slim (3.0.6) + temple (~> 0.7.3) + tilt (>= 1.3.3, < 2.1) + slim-rails (3.0.1) + actionmailer (>= 3.1, < 5.0) + actionpack (>= 3.1, < 5.0) + activesupport (>= 3.1, < 5.0) + railties (>= 3.1, < 5.0) + slim (~> 3.0) + spring (1.6.3) + sprockets (3.5.2) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.0.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + temple (0.7.6) + therubyracer (0.12.2) + libv8 (~> 3.16.14.0) + ref + thor (0.19.1) + thread_safe (0.3.5) + tilt (2.0.2) + turbolinks (2.5.3) + coffee-rails + tzinfo (1.2.2) + thread_safe (~> 0.1) + uglifier (2.7.2) + execjs (>= 0.3.0) + json (>= 1.8.0) + web-console (2.3.0) + activemodel (>= 4.0) + binding_of_caller (>= 0.7.2) + railties (>= 4.0) + sprockets-rails (>= 2.0, < 4.0) + +PLATFORMS + ruby + +DEPENDENCIES + anemone + byebug + coffee-rails (~> 4.1.0) + jbuilder (~> 2.0) + jquery-rails + mysql2 (~> 0.3.20) + rails (= 4.2.3) + rspec-rails (~> 3.0.0) + sass-rails (~> 5.0) + sdoc (~> 0.4.0) + slim-rails + spring + therubyracer + turbolinks + uglifier (>= 1.3.0) + web-console (~> 2.0) + +BUNDLED WITH + 1.11.2 diff --git a/app/controllers/ranking_controller.rb b/app/controllers/ranking_controller.rb index 95bdbd7..eb58cc4 100644 --- a/app/controllers/ranking_controller.rb +++ b/app/controllers/ranking_controller.rb @@ -1,16 +1,9 @@ class RankingController < ApplicationController def history - @products = [] params[:cate] ||= "all" - - video = Video.order(view: 'desc').limit(100) - video.where!(category: params[:cate]) unless params[:cate] == "all" - - video.each do |v| - @products += [{img: v.image, date: v.created_at.strftime('%Y年%m月%d日 %H時%M分%S秒'), comment: v.comment.to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\1,'), view: v.view.to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\1,'), title: v.title, link: v.url}] - end - + @video = Video.order(view: 'desc').limit(100) + @video.where!(category: params[:cate]) unless params[:cate] == "all" end end diff --git a/app/views/ranking/history.html.slim b/app/views/ranking/history.html.slim index 5eda137..dbd2003 100644 --- a/app/views/ranking/history.html.slim +++ b/app/views/ranking/history.html.slim @@ -4,116 +4,16 @@ ul.nav.nav-tabs li role="presentation" class="#{"active" if params[:cate] == "all"}" a href="/ranking/history/all" 全て - li.dropdown role="presentation" class="#{"active" if ["g_ent2", "ent", "music", "sing", "play", "dance", "vocaloid", "nicoindies"].include?(params[:cate])}" - a.dropdown-toggle data-toggle="dropdown" href="#" aria-haspopup="true" aria-expanded="false" - | エンタメ・音楽 - span.caret + - YAML.load_file("#{Rails.root}/config/config.yml")[:nico_cate].each do |title, content| + li.dropdown role="presentation" class="#{"active" if content.values.include?(params[:cate])}" + a.dropdown-toggle data-toggle="dropdown" href="#" aria-haspopup="true" aria-expanded="false" + | #{title} + span.caret - ul.dropdown-menu - li class="#{"active" if params[:cate] == "g_ent2"}" - a href="/ranking/history/g_ent2" 合算 - li class="#{"active" if params[:cate] == "ent"}" - a href="/ranking/history/ent" エンターテイメント - li class="#{"active" if params[:cate] == "music"}" - a href="/ranking/history/music" 音楽 - li class="#{"active" if params[:cate] == "sing"}" - a href="/ranking/history/sing" 歌ってみた - li class="#{"active" if params[:cate] == "play"}" - a href="/ranking/history/play" 演奏してみた - li class="#{"active" if params[:cate] == "dance"}" - a href="/ranking/history/dance" 踊ってみた - li class="#{"active" if params[:cate] == "vocaloid"}" - a href="/ranking/history/vocaloid" VOCALOID - li class="#{"active" if params[:cate] == "nicoindies"}" - a href="/ranking/history/nicoindies" ニコニコインディーズ - - li.dropdown role="presentation" class="#{"active" if ["g_life2", "animal", "cooking", "nature", "travel", "sport", "lecture", "drive", "history"].include?(params[:cate])}" - - a.dropdown-toggle data-toggle="dropdown" href="#" aria-haspopup="true" aria-expanded="false" - | 生活・一般・スポ - span.caret - - ul.dropdown-menu - li class="#{"active" if params[:cate] == "g_life2"}" - a href="/ranking/history/g_life2" 合算 - li class="#{"active" if params[:cate] == "animal"}" - a href="/ranking/history/animal" 動物 - li class="#{"active" if params[:cate] == "cooking"}" - a href="/ranking/history/cooking" 料理 - li class="#{"active" if params[:cate] == "nature"}" - a href="/ranking/history/nature" 自然 - li class="#{"active" if params[:cate] == "travel"}" - a href="/ranking/history/travel" 旅行 - li class="#{"active" if params[:cate] == "sport"}" - a href="/ranking/history/sport" スポーツ - li class="#{"active" if params[:cate] == "lecture"}" - a href="/ranking/history/lecture" ニコニコ動画講座 - li class="#{"active" if params[:cate] == "drive"}" - a href="/ranking/history/drive" 車載動画 - li class="#{"active" if params[:cate] == "history"}" - a href="/ranking/history/history" 歴史 - - li.dropdown role="presentation" class="#{"active" if params[:cate] == "g_politics"}" - a.dropdown-toggle data-toggle="dropdown" href="#" aria-haspopup="true" aira-expanded="false" - | 政治 - span.caret - - ul.dropdown-menu - li class="#{"active" if params[:cate] == "g_politics"}" - a href="/ranking/history/g_politics" 合算 - - li.dropdown role="presentation" class="#{"active" if ["g_tech", "science", "tech", "handcraft", "make"].include?(params[:cate])}" - a.dropdown-toggle data-toggle="dropdown" href="#" aria-haspopup="true" aira-expanded="false" - | 科学・技術 - span.caret - - ul.dropdown-menu - li class="#{"active" if params[:cate] == "g_tech"}" - a href="/ranking/history/g_tech" 合算 - li class="#{"active" if params[:cate] == "science"}" - a href="/ranking/history/science" 科学 - li class="#{"active" if params[:cate] == "tech"}" - a href="/ranking/history/tech" ニコニコ技術部 - li class="#{"active" if params[:cate] == "handcraft"}" - a href="/ranking/history/handcraft" ニコニコ手芸部 - li class="#{"active" if params[:cate] == "make"}" - a href="/ranking/history/make" 作ってみた - - li.dropdown role="presentation" class="#{"active" if ["g_culture2", "anime", "game", "toho", "imas", "radio", "draw"].include?(params[:cate])}" - a.dropdown-toggle data-toggle="dropdown" href="#" aria-haspopup="true" aira-expanded="false" - | アニメ・ゲーム・絵 - span.caret - - ul.dropdown-menu - li class="#{"active" if params[:cate] == "g_culture2"}" - a href="/ranking/history/g_culture2" 合算 - li class="#{"active" if params[:cate] == "anime"}" - a href="/ranking/history/anime" アニメ - li class="#{"active" if params[:cate] == "game"}" - a href="/ranking/history/game" ゲーム - li class="#{"active" if params[:cate] == "toho"}" - a href="/ranking/history/toho" 東方 - li class="#{"active" if params[:cate] == "imas"}" - a href="/ranking/history/imas" アイドルマスター - li class="#{"active" if params[:cate] == "radio"}" - a href="/ranking/history/radio" ラジオ - li class="#{"active" if params[:cate] == "draw"}" - a href="/ranking/history/draw" 描いてみた - - li.dropdown role="presentation" class="#{"active" if ["g_other", "are", "diary", "other"].include?(params[:cate])}" - a.dropdown-toggle data-toggle="dropdown" href="#" aria-haspopup="true" aira-expanded="false" - | その他 - span.caret - - ul.dropdown-menu - li class="#{"active" if params[:cate] == "g_other"}" - a href="/ranking/history/g_other" 合算 - li class="#{"active" if params[:cate] == "are"}" - a href="/ranking/history/are" 例のアレ - li class="#{"active" if params[:cate] == "diary"}" - a href="/ranking/history/diary" 日記 - li class="#{"active" if params[:cate] == "other"}" - a href="/ranking/history/other" その他 + ul.dropdown-menu + - content.each do |name, url| + li class="#{"active" if params[:cate] == url}" + a href="/ranking/history/#{url}" #{name} table.table.table-hover thead @@ -124,8 +24,8 @@ ul.nav.nav-tabs th 再生数 tbody - - @products.each.with_index(1) do |item, idx| - tr onclick="window.open('http://www.nicovideo.jp#{item[:link]}', '_blank');" style="cursor: pointer;" + - @video.each.with_index(1) do |item, idx| + tr onclick="window.open('#{YAML.load_file("#{Rails.root}/config/config.yml")[:nico_url]}#{item[:url]}', '_blank');" style="cursor: pointer;" - if idx < 4 td h1 @@ -143,12 +43,12 @@ ul.nav.nav-tabs h4 span.label.label-default #{idx}位 td - img src="#{item[:img]}" width="160" + img src="#{item[:image]}" width="160" td span.text-info #{item[:title]} br - = item[:date] + = item[:created_at].strftime('%Y年%m月%d日 %H時%M分%S秒') td - = item[:comment] + = item[:comment].to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\1,') td - = item[:view] + = item[:view].to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\1,') diff --git a/config/config.yml b/config/config.yml new file mode 100644 index 0000000..f6a483e --- /dev/null +++ b/config/config.yml @@ -0,0 +1,43 @@ +:nico_url: http://www.nicovideo.jp +:nico_crawl: http://www.nicovideo.jp/ranking/fav/hourly/ +:nico_cate: + エンタメ・音楽: + 合算: g_ent2 + エンターテイメント: ent + 音楽: music + 歌ってみた: sing + 演奏してみた: play + 踊ってみた: dance + VOCALOID: vocaloid + ニコニコインディーズ: nicoindies + 生活・一般・スポ: + 合算: g_life2 + 動物: animal + 料理: cooking + 自然: nature + 旅行: travel + スポーツ: sport + ニコニコ動画講座: lecture + 車載動画: drive + 歴史: history + 政治: + 合算: g_politics + 科学・技術: + 合算: g_tech + 科学: science + ニコニコ技術部: tech + ニコニコ手芸部: handcraft + 作ってみた: make + アニメ・ゲーム・絵: + 合算: g_culture2 + アニメ: anime + ゲーム: game + 東方: toho + アイドルマスター: imas + ラジオ: radio + 描いてみた: draw + その他: + 合算: g_other + 例のアレ: are + 日記: diary + その他: other diff --git a/lib/tasks/crawl_ranking.rake b/lib/tasks/crawl_ranking.rake index 3b8763d..1cf49f0 100644 --- a/lib/tasks/crawl_ranking.rake +++ b/lib/tasks/crawl_ranking.rake @@ -1,32 +1,34 @@ namespace :crawl_ranking do - desc "Rankingから動画をcrawl" - task :create => :environment do - category = ['g_ent2', 'ent', 'music', 'sing', 'play', 'dance', 'vocaloid', 'nicoindies', 'g_life2', 'animal', 'cooking', 'nature', 'travel', 'sport', 'lecture', 'drive', 'history', 'g_politics', 'g_tech', 'science', 'tech', 'handcraft', 'make', 'g_culture2', 'anime', 'game', 'toho', 'imas', 'radio', 'draw', 'g_other', 'are', 'diary', 'other'] - category.each do |cate| - Anemone.crawl("http://www.nicovideo.jp/ranking/fav/hourly/"+cate, {depth_limit: 0} ) do |anemone| - anemone.on_every_page do |page| - page.doc.xpath("/html/body//section[@class='content']/div[contains(@class,'contentBody')]//li[contains(@class,'videoRanking')]").each do |node| - title = node.xpath("./div[@class='itemContent']/p/a").text - date = node.xpath("./div[@class='videoList01Wrap']/p[@class='itemTime' or @class='itemTime new']/span").text - link = node.xpath("./div[@class='videoList01Wrap']/div[@class='itemThumbBox']/div[@class='itemThumb']/a").attribute('href').value - img = node.xpath("./div[@class='videoList01Wrap']/div[@class='itemThumbBox']/div[@class='itemThumb']/a/img")[1].attribute('data-original').value - viewCount = node.xpath("./div[@class='itemContent']/div[@class='itemData']//li[contains(@class,'view')]/span").text.delete(',').to_i - comment = node.xpath("./div[@class='itemContent']/div[@class='itemData']//li[contains(@class,'comment')]/span").text.delete(',').to_i - mylist = node.xpath("./div[@class='itemContent']/div[@class='itemData']//li[contains(@class,'mylist')]/span").text.delete(',').to_i + desc "Rankingから動画をcrawl" + task create: :environment do + config = YAML.load_file("#{Rails.root}/config/config.yml") + category = [] + config[:nico_cate].each { |title, content| category += content.values } + category.each do |cate| + Anemone.crawl("#{config[:nico_crawl]}#{cate}", {depth_limit: 0} ) do |anemone| + anemone.on_every_page do |page| + page.doc.xpath("/html/body//section[@class='content']/div[contains(@class,'contentBody')]//li[contains(@class,'videoRanking')]").each do |node| + title = node.xpath("./div[@class='itemContent']/p/a").text + date = node.xpath("./div[@class='videoList01Wrap']/p[@class='itemTime' or @class='itemTime new']/span").text + url = node.xpath("./div[@class='videoList01Wrap']/div[@class='itemThumbBox']/div[@class='itemThumb']/a").attribute('href').value + image = node.xpath("./div[@class='videoList01Wrap']/div[@class='itemThumbBox']/div[@class='itemThumb']/a/img")[1].attribute('data-original').value + view = node.xpath("./div[@class='itemContent']/div[@class='itemData']//li[contains(@class,'view')]/span").text.delete(',').to_i + comment = node.xpath("./div[@class='itemContent']/div[@class='itemData']//li[contains(@class,'comment')]/span").text.delete(',').to_i + mylist = node.xpath("./div[@class='itemContent']/div[@class='itemData']//li[contains(@class,'mylist')]/span").text.delete(',').to_i - video = Video.where(:url => link).first - if !video.nil? - video[:view] = viewCount - video[:comment] = comment - video[:mylist] = mylist - video.save - else - Video.create(:title => title, :category => cate, :url => link, :image => img, :view => viewCount, :comment => comment, :mylist => mylist, :created_at => date) - end - end - end + video = Video.where(url: url).first + unless video.nil? + video[:view] = view + video[:comment] = comment + video[:mylist] = mylist + video.save + else + Video.create(title: title, category: cate, url: url, image: image, view: view, comment: comment, mylist: mylist, created_at: date) end + end end + end end + end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..4d1d439 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,43 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV["RAILS_ENV"] ||= 'test' +require 'spec_helper' +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } + +# Checks for pending migrations before tests are run. +# If you are not using ActiveRecord, you can remove this line. +ActiveRecord::Migration.maintain_test_schema! + +RSpec.configure do |config| + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..cfb18dc --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,78 @@ +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause this +# file to always be loaded, without a need to explicitly require it in any files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, make a +# separate helper file that requires this one and then use it only in the specs +# that actually need it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed + + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # Enable only the newer, non-monkey-patching expect syntax. + # For more details, see: + # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax + expectations.syntax = :expect + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Enable only the newer, non-monkey-patching expect syntax. + # For more details, see: + # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + mocks.syntax = :expect + + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended. + mocks.verify_partial_doubles = true + end +=end +end diff --git a/test/controllers/.keep b/test/controllers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/controllers/ranking_controller_test.rb b/test/controllers/ranking_controller_test.rb deleted file mode 100644 index f2a7192..0000000 --- a/test/controllers/ranking_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class RankingControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/fixtures/.keep b/test/fixtures/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/videos.yml b/test/fixtures/videos.yml deleted file mode 100644 index 937a0c0..0000000 --- a/test/fixtures/videos.yml +++ /dev/null @@ -1,11 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html - -# This model initially had no columns defined. If you add columns to the -# model remove the '{}' from the fixture names and add the columns immediately -# below each fixture, per the syntax in the comments below -# -one: {} -# column: value -# -two: {} -# column: value diff --git a/test/helpers/.keep b/test/helpers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/integration/.keep b/test/integration/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/mailers/.keep b/test/mailers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/models/.keep b/test/models/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/models/video_test.rb b/test/models/video_test.rb deleted file mode 100644 index cf3f0b1..0000000 --- a/test/models/video_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class VideoTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index 92e39b2..0000000 --- a/test/test_helper.rb +++ /dev/null @@ -1,10 +0,0 @@ -ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../../config/environment', __FILE__) -require 'rails/test_help' - -class ActiveSupport::TestCase - # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. - fixtures :all - - # Add more helper methods to be used by all tests here... -end