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 /spec | |
parent | 61dde16fd55babd2ccf5ff6a9c8be1f600868d9b (diff) | |
download | aclog-84183b7bb1c42a80b323ea3caef30467dcde23a6.tar.gz |
Add test(partial)
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/accounts.rb | 17 | ||||
-rw-r--r-- | spec/factories/users.rb | 29 | ||||
-rw-r--r-- | spec/models/account_spec.rb | 78 | ||||
-rw-r--r-- | spec/models/favorite_spec.rb | 5 | ||||
-rw-r--r-- | spec/models/issue_spec.rb | 5 | ||||
-rw-r--r-- | spec/models/retweet_spec.rb | 5 | ||||
-rw-r--r-- | spec/models/stolen_tweet_spec.rb | 5 | ||||
-rw-r--r-- | spec/models/tweet_spec.rb | 5 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 5 | ||||
-rw-r--r-- | spec/spec_helper.rb | 42 |
10 files changed, 196 insertions, 0 deletions
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 |