diff options
author | re4k <re4k@re4k.info> | 2013-04-04 19:20:51 +0900 |
---|---|---|
committer | re4k <re4k@re4k.info> | 2013-04-04 19:20:51 +0900 |
commit | 84183b7bb1c42a80b323ea3caef30467dcde23a6 (patch) | |
tree | c248d894619fce6c585747dff5f8f03c15d989c4 | |
parent | 61dde16fd55babd2ccf5ff6a9c8be1f600868d9b (diff) | |
download | aclog-84183b7bb1c42a80b323ea3caef30467dcde23a6.tar.gz |
Add test(partial)
33 files changed, 280 insertions, 169 deletions
@@ -4,30 +4,33 @@ source 'https://rubygems.org' gem 'rails', '4.0.0.beta1' gem 'mysql2' gem 'dalli' + gem 'counter_culture' +gem 'rails_config' +gem 'yajl-ruby', :require => "yajl" gem 'unicorn' gem 'thin' gem 'daemon-spawn', :require => 'daemon_spawn' - -gem 'rails_config' -gem 'kaminari' +gem 'msgpack' gem 'em-work_queue' -group :assets do - gem 'jquery-rails' - gem 'sass-rails', '~> 4.0.0.beta1' - gem 'coffee-rails', '~> 4.0.0.beta1' - gem 'uglifier', '>= 1.0.3' -end +gem 'twitter' +gem 'omniauth-twitter', :github => "re4k/omniauth-twitter" +gem 'kaminari' gem 'haml-rails' +gem 'sass-rails', '~> 4.0.0.beta1' gem 'jbuilder' +gem 'coffee-rails', '~> 4.0.0.beta1' +gem 'jquery-rails' +gem 'uglifier', '>= 1.0.3' gem 'bootstrap-sass' -gem 'msgpack' -gem 'omniauth-twitter', :github => "re4k/omniauth-twitter" -gem 'em-twitter' -gem 'twitter' -gem 'yajl-ruby', :require => "yajl" +group :development, :test do + gem 'rspec' + gem 'rspec-rails' + gem 'factory_girl_rails'#, :require => 'factory_girl' +end + diff --git a/Gemfile.lock b/Gemfile.lock index 8d641c5..ecc7377 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,16 +52,18 @@ GEM daemon-spawn (0.4.2) daemons (1.1.9) dalli (2.6.2) - em-twitter (0.2.2) - eventmachine (~> 1.0) - http_parser.rb (~> 0.5) - simple_oauth (~> 0.1) + diff-lcs (1.2.2) em-work_queue (0.0.1) eventmachine erubis (2.7.0) eventmachine (1.0.3) execjs (1.4.0) multi_json (~> 1.0) + factory_girl (4.2.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.2.1) + factory_girl (~> 4.2.0) + railties (>= 3.0.0) faraday (0.8.7) multipart-post (~> 1.1) haml (4.0.1) @@ -73,7 +75,6 @@ GEM railties (>= 3.1, < 4.1) hashie (1.2.0) hike (1.2.1) - http_parser.rb (0.5.3) i18n (0.6.4) jbuilder (1.2.0) activesupport (>= 3.0.0) @@ -126,6 +127,21 @@ GEM rake (10.0.4) rdoc (3.12.2) json (~> 1.4) + rspec (2.13.0) + rspec-core (~> 2.13.0) + rspec-expectations (~> 2.13.0) + rspec-mocks (~> 2.13.0) + rspec-core (2.13.1) + rspec-expectations (2.13.0) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.13.0) + rspec-rails (2.13.0) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 2.13.0) + rspec-expectations (~> 2.13.0) + rspec-mocks (~> 2.13.0) sass (3.2.7) sass-rails (4.0.0.beta1) railties (>= 4.0.0.beta, < 5.0) @@ -176,8 +192,8 @@ DEPENDENCIES counter_culture daemon-spawn dalli - em-twitter em-work_queue + factory_girl_rails haml-rails jbuilder jquery-rails @@ -187,6 +203,8 @@ DEPENDENCIES omniauth-twitter! rails (= 4.0.0.beta1) rails_config + rspec + rspec-rails sass-rails (~> 4.0.0.beta1) thin twitter diff --git a/app/assets/stylesheets/application.css.sass b/app/assets/stylesheets/application.css.sass index 5c4ac94..47e2903 100644 --- a/app/assets/stylesheets/application.css.sass +++ b/app/assets/stylesheets/application.css.sass @@ -3,6 +3,8 @@ @import "users" @import "sidebar" +body + :font-family "Ubuntu", sans-serif a :text-decoration none :color #3b5998 diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index d16175a..6138aeb 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -4,12 +4,10 @@ class SessionsController < ApplicationController def callback auth = request.env["omniauth.auth"] - account = Account.find_or_initialize_by(:user_id => auth["uid"]) - account.oauth_token = auth["credentials"]["token"] - account.oauth_token_secret = auth["credentials"]["secret"] - account.consumer_version = Settings.consumer_version - account.save! - + account = Account.register_or_update(user_id: auth["uid"], + oauth_token: auth["credentials"]["token"], + oauth_token_secret: auth["credentials"]["secret"], + consumer_version: Settings.consumer_version) session[:account] = account session[:user_id] = account.user_id diff --git a/app/models/account.rb b/app/models/account.rb index f235784..59dabf9 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1,11 +1,21 @@ class Account < ActiveRecord::Base + def self.register_or_update(hash) + account = where(:user_id => hash[:user_id]).first_or_initialize + account.oauth_token = hash[:oauth_token] + account.oauth_token_secret = hash[:oauth_token_secret] + account.consumer_version = hash[:consumer_version] + account.save if account.changed? + account + end + def user User.cached(user_id) end - def twitter_user - Rails.cache.fetch("twitter_user/#{user_id}", :expires_in => 1.hour) do - client.user(user_id) rescue nil + def twitter_user(uid = nil) + uid ||= user_id + Rails.cache.fetch("twitter_user/#{uid}", :expires_in => 1.hour) do + client.user(uid) rescue nil end end diff --git a/app/views/main/index.html.haml b/app/views/main/index.html.haml index 6a1878e..02d5b2b 100644 --- a/app/views/main/index.html.haml +++ b/app/views/main/index.html.haml @@ -7,13 +7,19 @@ Favstar を参考に開発しています。現時点でトロフィー以外の機能はすべて使えるはずです。 %p API も提供する予定です。about → api を見てください(まだ開発中であり、変更がある可能性もあります) +.alert + (04/04) 諸事情でアプリケーションを作り直しました。再認証(logout → login)すると新しいトークンで上書きされます。 + わざわざ再認証しなくても今のところ支障はありませんが、再認証した場合は、Twitter の設定の + = link_to "アプリ連携", "https://twitter.com/settings/applications" + から不要な "AcLog" と "Aclog2" は解除しても大丈夫です。 %h4 - 今後の予定(2013/04/03) + 今後の予定(2013/04/04) %ul - %li トロフィー機能を付ける予定はありません - %li ふぁぼったー・Favstar からのデータの取り込み + %li 通知を細かく設定できるように %li パクリツイート対策 + %li ふぁぼったー・Favstar からのデータの取り込み %li ふぁぼ爆撃対策 + %li トロフィー機能をいらないよね… %p = link_to "ツイート", "https://twitter.com/share", :class => "twitter-share-button", :"data-text" => "aclog", :"data-count" => "none", :"data-url" => "http://aclog.koba789.com/" %hr diff --git a/client/Gemfile.lock b/client/Gemfile.lock index b35eb77..e14846e 100644 --- a/client/Gemfile.lock +++ b/client/Gemfile.lock @@ -1,7 +1,7 @@ GEM remote: https://rubygems.org/ specs: - em-twitter (0.2.1) + em-twitter (0.2.2) eventmachine (~> 1.0) http_parser.rb (~> 0.5) simple_oauth (~> 0.1) @@ -12,7 +12,7 @@ GEM msgpack (0.5.4) settingslogic (2.0.9) simple_oauth (0.2.0) - thor (0.17.0) + thor (0.18.1) yajl-ruby (1.1.0) PLATFORMS diff --git a/client/worker.rb b/client/worker.rb index a74188b..d5b03ec 100644 --- a/client/worker.rb +++ b/client/worker.rb @@ -65,7 +65,7 @@ class Worker :method => "GET"} if @clients[account_id] unless @clients[account_id].options[:oauth][:token] == conopts[:oauth][:token] - @clients.connection.update(conopts) + @clients[account_id].connection.update(conopts) $logger.info("Updated(##{account_id}/#{user_id}/#{msg["consumer_version"].to_i})") else $logger.info("Not Updated(##{account_id}/#{user_id}/#{msg["consumer_version"].to_i})") diff --git a/config/application.rb b/config/application.rb index e1ce527..f731bfa 100644 --- a/config/application.rb +++ b/config/application.rb @@ -27,5 +27,9 @@ module Aclog end config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif) + + config.generators do |g| + g.fixture_replacement :factory_girl + end end end diff --git a/config/environments/test.rb b/config/environments/test.rb index 7254eb2..83e386b 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -5,7 +5,7 @@ Aclog::Application.configure do # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! - config.cache_classes = true + config.cache_classes = false # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that @@ -33,4 +33,6 @@ Aclog::Application.configure do # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr + + config.cache_store = :null_store end diff --git a/config/settings/test.yml b/config/settings/test.yml index e69de29..15335ad 100644 --- a/config/settings/test.yml +++ b/config/settings/test.yml @@ -0,0 +1,3 @@ +consumer: + - key: JVkX2Uy0Qtigsh0GiG5Lw + secret: vfkPvOkzKUGuZ4xKtFAVvlAKoL3u2grxchuQEBvE diff --git a/lib/aclog/notification.rb b/lib/aclog/notification.rb index b2a89ba..85919a3 100644 --- a/lib/aclog/notification.rb +++ b/lib/aclog/notification.rb @@ -16,8 +16,8 @@ module Aclog begin @@account.update("@#{user.screen_name} #{text} #{url}", :in_reply_to_status_id => tweet.id) rescue Exception - logger.error($!) - logger.error($@) + Rails.logger.error($!) + Rails.logger.error($@) end end end diff --git a/lib/receiver/logger.rb b/lib/receiver/logger.rb deleted file mode 100644 index e1ecf56..0000000 --- a/lib/receiver/logger.rb +++ /dev/null @@ -1,42 +0,0 @@ -class Receiver::Logger - def debug(msg) - if @level == :debug - log(@out, "DEBUG", msg) - end - end - - def info(msg) - unless @level == :none - @level == :error - @level == :warn - log(@out, "INFO", msg) - end - end - - def warn(msg) - unless @level == :none - @level == :error - log(@err, "WARN", msg) - end - end - - def error(msg) - unless @level == :none - log(@err, "ERROR", msg) - end - end - - def fatal(msg) - log(@err, "FATAL", msg) - end - - def log(out, type, msg) - out.puts Time.now.utc.iso8601(3) + " " + type + ": " + msg.to_s - end - - def initialize(level = :warn) - @out = STDOUT - @err = STDERR - @level = level - end -end diff --git a/spec/factories/accounts.rb b/spec/factories/accounts.rb new file mode 100644 index 0000000..de97702 --- /dev/null +++ b/spec/factories/accounts.rb @@ -0,0 +1,17 @@ +FactoryGirl.define do + factory :account_1, class: Account do |f| + f.user_id 1326331596 + f.oauth_token "1326331596-ELn8lmw2WnACmBfdrLrqjGTlEsrw2kICXwcKy3Z" + f.oauth_token_secret "QZIquEKkr0GUgwRu402RskBaGPs7Q00GCfRwjQTdo" + f.consumer_version 0 + end + + factory :account_2, class: Account do |f| + f.user_id 1326331596 + f.oauth_token "1326331596-iguYFYUWruy37dw7687e3GGYDUEYeghgwdguiGE" + f.oauth_token_secret "v4H646FYRJUT5hvhHJ7fyudfoiGEqXs3erlopnKJb" + f.consumer_version 1 + end +end + + diff --git a/spec/factories/users.rb b/spec/factories/users.rb new file mode 100644 index 0000000..3ee0055 --- /dev/null +++ b/spec/factories/users.rb @@ -0,0 +1,29 @@ +FactoryGirl.define do + factory :user_1, class: User do |f| + f.id 1326331596 + f.screen_name "aclog_test" + f.profile_image_url "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png" + f.protected false + end + + factory :user_exists, class: User do |f| + f.id 15926668 + f.screen_name "toshi_a" + f.profile_image_url "https://si0.twimg.com/profile_images/3252770797/b462225c334fd35c22581684e98cb10d_normal.png" + f.protected false + end + + factory :user_not_exists, class: User do |f| + f.id 0 + f.screen_name "" + f.profile_image_url "" + f.protected false + end + + factory :user_suspended, class: User do |f| + f.id 230367516 + f.screen_name "re4k" + f.profile_image_url "https://si0.twimg.com/profile_images/3211524383/0b9d7fdd3fdf0c122af079fda4a7727a_normal.png" + f.protected false + end +end diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb new file mode 100644 index 0000000..6b48169 --- /dev/null +++ b/spec/models/account_spec.rb @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +require 'spec_helper' + +describe Account do + describe "Account.register_or_update" do + it "登録されていなかった時 新しいレコードを作る。" do + account_1 = FactoryGirl.build(:account_1) + created_1 = Account.register_or_update(user_id: account_1.user_id, + oauth_token: account_1.oauth_token, + oauth_token_secret: account_1.oauth_token_secret, + consumer_version: account_1.consumer_version) + created_1.user_id.should eq account_1.user_id + end + + it "登録されていた時 レコードを更新する。" do + created_1 = FactoryGirl.create(:account_1) + + account_2 = FactoryGirl.build(:account_2) + created_2 = Account.register_or_update(user_id: account_2.user_id, + oauth_token: account_2.oauth_token, + oauth_token_secret: account_2.oauth_token_secret, + consumer_version: account_2.consumer_version) + created_2.oauth_token.should eq account_2.oauth_token + created_2.id.should eq created_1.id + end + end + + describe "Account#user" do + before(:each){@account_1 = FactoryGirl.create(:account_1)} + + it "ユーザーが記録されていた時 User を返す。" do + FactoryGirl.create(:user_1) + + got_user = @account_1.user + got_user.id.should eq @account_1.user_id + end + + it "ユーザーが記録されていなかった時 nil を返す。" do + got_user = @account_1.user + got_user.should eq nil + end + end + + describe "Account#twitter_user" do + before(:each){@account_1 = FactoryGirl.create(:account_1)} + + it "ユーザーが存在する時 Twitter::User を返す。" do + user = FactoryGirl.create(:user_exists) + + got_user = @account_1.twitter_user(user.id) + got_user.screen_name.should eq user.screen_name + end + + it "ユーザーが存在しない時 nil を返す。" do + user = FactoryGirl.create(:user_not_exists) + + got_user = @account_1.twitter_user(user.id) + got_user.should eq nil + end + + it "ユーザーが凍結している時 nil を返す。" do + user = FactoryGirl.create(:user_suspended) + + got_user = @account_1.twitter_user(user.id) + got_user.should eq nil + end + + it "引数を省略した時自分の user_id を使う。" do + user = FactoryGirl.create(:user_1) + + got_user = @account_1.twitter_user + got_user.screen_name.should eq user.screen_name + end + end + + describe "Account.import_favorites" do + end +end diff --git a/spec/models/favorite_spec.rb b/spec/models/favorite_spec.rb new file mode 100644 index 0000000..c029e13 --- /dev/null +++ b/spec/models/favorite_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Favorite do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb new file mode 100644 index 0000000..8813189 --- /dev/null +++ b/spec/models/issue_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Issue do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/retweet_spec.rb b/spec/models/retweet_spec.rb new file mode 100644 index 0000000..bd2b4d3 --- /dev/null +++ b/spec/models/retweet_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Retweet do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/stolen_tweet_spec.rb b/spec/models/stolen_tweet_spec.rb new file mode 100644 index 0000000..7b3ad68 --- /dev/null +++ b/spec/models/stolen_tweet_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe StolenTweet do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/tweet_spec.rb b/spec/models/tweet_spec.rb new file mode 100644 index 0000000..a826279 --- /dev/null +++ b/spec/models/tweet_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Tweet do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..44032b4 --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe User do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..b32a16e --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,42 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV["RAILS_ENV"] ||= 'test' +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' +require 'rspec/autorun' + +# Requires supporting ruby files with custom matchers and macros, etc, +# in spec/support/ and its subdirectories. +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.check_pending! if defined?(ActiveRecord::Migration) + +RSpec.configure do |config| + # ## Mock Framework + # + # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: + # + # config.mock_with :mocha + # config.mock_with :flexmock + # config.mock_with :rr + + # 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 + + # If true, the base class of anonymous controllers will be inferred + # automatically. This will be the default behavior in future versions of + # rspec-rails. + config.infer_base_class_for_anonymous_controllers = false + + # 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" +end diff --git a/test/controllers/errors_controller_test.rb b/test/controllers/errors_controller_test.rb deleted file mode 100644 index dcd460a..0000000 --- a/test/controllers/errors_controller_test.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'test_helper' - -class ErrorsControllerTest < ActionController::TestCase - test "should get error_404" do - get :error_404 - assert_response :success - end - - test "should get error_500" do - get :error_500 - assert_response :success - end - -end diff --git a/test/controllers/report_controller_test.rb b/test/controllers/report_controller_test.rb deleted file mode 100644 index 1949a88..0000000 --- a/test/controllers/report_controller_test.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'test_helper' - -class ReportControllerTest < ActionController::TestCase - test "should get index" do - get :index - assert_response :success - end - - test "should get tweet" do - get :tweet - assert_response :success - end - - test "should get spam" do - get :spam - assert_response :success - end - - test "should get issue" do - get :issue - assert_response :success - end - -end diff --git a/test/controllers/search_controller_test.rb b/test/controllers/search_controller_test.rb deleted file mode 100644 index bfbf22d..0000000 --- a/test/controllers/search_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class SearchControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/fixtures/issues.yml b/test/fixtures/issues.yml deleted file mode 100644 index 1f5849b..0000000 --- a/test/fixtures/issues.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - type: 1 - data: MyText - -two: - type: 1 - data: MyText diff --git a/test/fixtures/stolen_tweets.yml b/test/fixtures/stolen_tweets.yml deleted file mode 100644 index 9196fe8..0000000 --- a/test/fixtures/stolen_tweets.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - tweet_id: 1 - original_id: 1 - -two: - tweet_id: 1 - original_id: 1 diff --git a/test/helpers/errors_helper_test.rb b/test/helpers/errors_helper_test.rb deleted file mode 100644 index 2b0c217..0000000 --- a/test/helpers/errors_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class ErrorsHelperTest < ActionView::TestCase -end diff --git a/test/helpers/report_helper_test.rb b/test/helpers/report_helper_test.rb deleted file mode 100644 index b37320b..0000000 --- a/test/helpers/report_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class ReportHelperTest < ActionView::TestCase -end diff --git a/test/helpers/search_helper_test.rb b/test/helpers/search_helper_test.rb deleted file mode 100644 index 3034163..0000000 --- a/test/helpers/search_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class SearchHelperTest < ActionView::TestCase -end diff --git a/test/models/issue_test.rb b/test/models/issue_test.rb deleted file mode 100644 index c3887b8..0000000 --- a/test/models/issue_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class IssueTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/models/stolen_tweet_test.rb b/test/models/stolen_tweet_test.rb deleted file mode 100644 index b20db96..0000000 --- a/test/models/stolen_tweet_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class StolenTweetTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end |