diff options
author | rhenium <re4k@re4k.info> | 2013-05-11 16:39:33 +0900 |
---|---|---|
committer | rhenium <re4k@re4k.info> | 2013-05-11 16:39:33 +0900 |
commit | 46717c9399655306a462c13ae84ac6fac1ad76b4 (patch) | |
tree | aa1951b68ab46895e4c97250d68d86d8b20ec6bf /spec | |
parent | 86d799076664950c84045785604b0e7f4d3ccfe3 (diff) | |
download | aclog-46717c9399655306a462c13ae84ac6fac1ad76b4.tar.gz |
fix tests
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/account_spec.rb | 52 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 24 |
2 files changed, 41 insertions, 35 deletions
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 767dc24..76ef4a2 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -25,20 +25,6 @@ describe Account do end end - describe "#user" do - let(:account) { FactoryGirl.create(:account_1) } - subject { account.user } - - context "when exist" do - before { @user = FactoryGirl.create(:user_1) } - it { should eq @user } - end - - context "when not exist" do - it { should be nil } - end - end - describe "#update_connection" do let(:account) { FactoryGirl.create(:account_1) } it "should not raise error" do @@ -56,4 +42,42 @@ describe Account do describe "#import_favorites" do # TODO end + + describe "#api_friendship?" do + before do + stub_request(:get, "https://api.twitter.com/1.1/friendships/show.json?source_id=1326331596&target_id=456"). + to_return(status: 200, body: '{"relationship":{"source":{"followed_by":false,"screen_name":"aclog_test","id_str":"1326331596","blocking":null,"want_retweets":null,"notifications_enabled":null,"id":1326331596,"all_replies":null,"can_dm":false,"following":false,"marked_spam":null},"target":{"followed_by":false,"screen_name":"davegray","id_str":"456","id":456,"following":false}}}') + stub_request(:get, "https://api.twitter.com/1.1/friendships/show.json?source_id=1326331596&target_id=280414022"). + to_return(status: 200, body: '{"relationship":{"source":{"notifications_enabled":null,"screen_name":"aclog_test","followed_by":true,"all_replies":null,"id_str":"1326331596","marked_spam":null,"id":1326331596,"want_retweets":null,"blocking":null,"can_dm":true,"following":true},"target":{"screen_name":"cn","followed_by":true,"id_str":"280414022","id":280414022,"following":true}}}') + end + let(:account) { FactoryGirl.create(:account_1) } + context "when not following" do + let(:source_user_id) { account.user_id } + let(:target_user_id) { 456 } + subject { account.__send__(:api_friendship?, source_user_id, target_user_id) } + it { should be false } + end + + context "when following" do + let(:source_user_id) { account.user_id } + let(:target_user_id) { 280414022 } # @cn + subject { account.__send__(:api_friendship?, source_user_id, target_user_id) } + it { should be true } + end + end + + describe "#user" do + let(:account) { FactoryGirl.create(:account_1) } + subject { account.user } + + context "when exist" do + before { @user = FactoryGirl.create(:user_1) } + it { should eq @user } + end + + context "when not exist" do + it { should be nil } + end + end + end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ee6c724..a10e04d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -36,10 +36,6 @@ describe User do end end - describe ".delete_cache" do - # TODO - end - describe "#protected?" do context "when not protected" do let(:user) { FactoryGirl.create(:user, protected: false) } @@ -80,31 +76,17 @@ describe User do describe "#stats" do let!(:account) { FactoryGirl.create(:account_1) } let(:user) { FactoryGirl.create(:user_1) } - let(:stats_api) { {favorites_count: 10, - listed_count: 12, - followers_count: 14, - tweets_count: 16, - friends_count: 18, - bio: "abc"} } before do user_2, user_3 = FactoryGirl.create_list(:user, 2) tweet_1, tweet_2 = FactoryGirl.create_list(:tweet, 2, user: user) FactoryGirl.create(:favorite, tweet: tweet_1, user: user_2) FactoryGirl.create(:favorite, tweet: tweet_1, user: user_3) FactoryGirl.create(:retweet, tweet: tweet_2, user: user_2) - - stub_request(:get, "https://api.twitter.com/1.1/account/verify_credentials.json") - .to_return(status: 200, body: {id: user.id, - favourites_count: 10, - listed_count: 12, - followers_count: 14, - statuses_count: 16, - friends_count: 18, - description: "abc"}.to_json) end - subject { OpenStruct.new(user.stats(true)) } - its(:stats_api) { should eq stats_api } + subject { user.stats } + its(:updated_at) { should_not be nil } + its(:since_join) { should be_a Integer } its(:favorites_count) { should be 0 } its(:retweets_count) { should be 0 } its(:tweets_count) { should be 2 } |