Skip to content

Commit

Permalink
Add test(partial)
Browse files Browse the repository at this point in the history
  • Loading branch information
re4k committed Apr 4, 2013
1 parent 61dde16 commit 84183b7
Show file tree
Hide file tree
Showing 33 changed files with 280 additions and 169 deletions.
31 changes: 17 additions & 14 deletions Gemfile
Expand Up @@ -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

30 changes: 24 additions & 6 deletions Gemfile.lock
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -176,8 +192,8 @@ DEPENDENCIES
counter_culture
daemon-spawn
dalli
em-twitter
em-work_queue
factory_girl_rails
haml-rails
jbuilder
jquery-rails
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/assets/stylesheets/application.css.sass
Expand Up @@ -3,6 +3,8 @@
@import "users"
@import "sidebar"

body
:font-family "Ubuntu", sans-serif
a
:text-decoration none
:color #3b5998
Expand Down
10 changes: 4 additions & 6 deletions app/controllers/sessions_controller.rb
Expand Up @@ -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

Expand Down
16 changes: 13 additions & 3 deletions 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

Expand Down
12 changes: 9 additions & 3 deletions app/views/main/index.html.haml
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions 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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/worker.rb
Expand Up @@ -65,7 +65,7 @@ def receive_account(msg)
: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})")
Expand Down
4 changes: 4 additions & 0 deletions config/application.rb
Expand Up @@ -27,5 +27,9 @@ class Application < Rails::Application
end

config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)

config.generators do |g|
g.fixture_replacement :factory_girl
end
end
end
4 changes: 3 additions & 1 deletion config/environments/test.rb
Expand Up @@ -5,7 +5,7 @@
# 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
Expand Down Expand Up @@ -33,4 +33,6 @@

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

config.cache_store = :null_store
end
3 changes: 3 additions & 0 deletions config/settings/test.yml
@@ -0,0 +1,3 @@
consumer:
- key: JVkX2Uy0Qtigsh0GiG5Lw
secret: vfkPvOkzKUGuZ4xKtFAVvlAKoL3u2grxchuQEBvE
4 changes: 2 additions & 2 deletions lib/aclog/notification.rb
Expand Up @@ -16,8 +16,8 @@ def self.reply_tweet(user, text, tweet)
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
Expand Down
42 changes: 0 additions & 42 deletions lib/receiver/logger.rb

This file was deleted.

17 changes: 17 additions & 0 deletions 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


29 changes: 29 additions & 0 deletions 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

0 comments on commit 84183b7

Please sign in to comment.