aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRhenium <rhenium@rhe.jp>2013-07-30 05:42:23 +0900
committerRhenium <rhenium@rhe.jp>2013-07-30 05:42:23 +0900
commitd1ed18861838e3bb8e42b9f17818e1fb7f9b3d44 (patch)
tree714050bd75d03134796560e83eb0256947771b8b /spec
parente0d1ab3a78544053e57970c57c758d1779db3ba4 (diff)
downloadaclog-d1ed18861838e3bb8e42b9f17818e1fb7f9b3d44.tar.gz
fix specs
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/application_controller_spec.rb24
-rw-r--r--spec/helpers/tweets_helper_spec.rb6
-rw-r--r--spec/models/account_spec.rb55
-rw-r--r--spec/models/favorite_spec.rb30
-rw-r--r--spec/models/retweet_spec.rb35
-rw-r--r--spec/models/tweet_spec.rb20
-rw-r--r--spec/models/user_spec.rb2
7 files changed, 100 insertions, 72 deletions
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index 4491e30..75f0e48 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -60,13 +60,13 @@ describe ApplicationController do
end
it "as the user's follower" do
- account.stub!(:following?).and_return(true)
+ account.stub(:following?).and_return(true)
session[:account] = account
subject.should be true
end
it "as not the user's follower" do
- account.stub!(:following?).and_return(false)
+ account.stub(:following?).and_return(false)
session[:account] = account
subject.should be false
end
@@ -77,25 +77,25 @@ describe ApplicationController do
before { request.headers["X-Verify-Credentials-Authorization"] = true }
it "as the user" do
- controller.stub!(:authenticate_with_twitter_oauth_echo).and_return(user.id)
+ controller.stub(:authenticate_with_twitter_oauth_echo).and_return(user.id)
subject.should be true
end
it "as the user's follower" do
- controller.stub!(:authenticate_with_twitter_oauth_echo).and_return(user.id)
+ controller.stub(:authenticate_with_twitter_oauth_echo).and_return(user.id)
user.id += 1
Account.any_instance.stub(:following?).and_return(true)
subject.should be true
end
it "not as the user's follower" do
- controller.stub!(:authenticate_with_twitter_oauth_echo).and_return(user.id + 1)
+ controller.stub(:authenticate_with_twitter_oauth_echo).and_return(user.id + 1)
Account.any_instance.stub(:following?).and_return(false)
subject.should be false
end
it "but failed in verification" do
- controller.stub!(:authenticate_with_twitter_oauth_echo).and_raise(Aclog::Exceptions::OAuthEchoUnauthorized)
+ controller.stub(:authenticate_with_twitter_oauth_echo).and_raise(Aclog::Exceptions::OAuthEchoUnauthorized)
Account.any_instance.stub(:following?).and_return(false)
subject.should be false
end
@@ -106,14 +106,14 @@ describe ApplicationController do
subject { user; account; !!controller.__send__(:authorized_to_show_best?, user) }
context "when account is protected" do
- before { controller.stub!(:authorized_to_show_user?).and_return(false) }
+ before { controller.stub(:authorized_to_show_user?).and_return(false) }
let(:user) { FactoryGirl.create(:user, protected: true) }
let(:account) { FactoryGirl.create(:account_1, user: user) }
it { should be false }
end
context "when account is not protected" do
- before { controller.stub!(:authorized_to_show_user?).and_return(true) }
+ before { controller.stub(:authorized_to_show_user?).and_return(true) }
context "when account is not registered" do
let(:user) { FactoryGirl.create(:user) }
let(:account) { nil }
@@ -147,12 +147,12 @@ describe ApplicationController do
describe "#authorize_to_show_user!" do
subject { -> { controller.__send__(:authorize_to_show_user!, nil) } }
it "when authorized to show user" do
- controller.stub!(:authorized_to_show_user?).and_return(true)
+ controller.stub(:authorized_to_show_user?).and_return(true)
subject.should_not raise_error
end
it "when not authorized to show user" do
- controller.stub!(:authorized_to_show_user?).and_return(false)
+ controller.stub(:authorized_to_show_user?).and_return(false)
subject.should raise_error(Aclog::Exceptions::UserProtected)
end
end
@@ -162,7 +162,7 @@ describe ApplicationController do
subject { -> { controller.__send__(:authorize_to_show_best!, user) } }
context "when user is not protected" do
- before { controller.stub!(:authorized_to_show_user?).and_return(true) }
+ before { controller.stub(:authorized_to_show_user?).and_return(true) }
it "when account is not registered" do
subject.should raise_error(Aclog::Exceptions::UserNotRegistered)
@@ -175,7 +175,7 @@ describe ApplicationController do
end
context "when user is protected and not accessible" do
- before { controller.stub!(:authorized_to_show_user?).and_return(false) }
+ before { controller.stub(:authorized_to_show_user?).and_return(false) }
it { should raise_error(Aclog::Exceptions::UserProtected) }
end
diff --git a/spec/helpers/tweets_helper_spec.rb b/spec/helpers/tweets_helper_spec.rb
index 67426be..d25b77c 100644
--- a/spec/helpers/tweets_helper_spec.rb
+++ b/spec/helpers/tweets_helper_spec.rb
@@ -46,17 +46,17 @@ describe TweetsHelper do
let(:user) { FactoryGirl.create(:user) }
subject { helper.user_truncated?(tweet) }
context "when full=true" do
- before { helper.stub!(:user_limit).and_return(nil) }
+ before { helper.stub(:user_limit).and_return(nil) }
let(:tweet) { FactoryGirl.create(:tweet, user: user, favorites_count: Settings.tweets.users.count_lot + 1, retweets_count: Settings.tweets.users.count_lot + 1) }
it { should be false }
end
context "when _count equals count_default" do
- before { helper.stub!(:user_limit).and_return(Settings.tweets.users.count_default) }
+ before { helper.stub(:user_limit).and_return(Settings.tweets.users.count_default) }
let(:tweet) { FactoryGirl.create(:tweet, user: user, favorites_count: Settings.tweets.users.count_default, retweets_count: Settings.tweets.users.count_default) }
it { should be false }
end
context "when _count is larger than count_default" do
- before { helper.stub!(:user_limit).and_return(Settings.tweets.users.count_default) }
+ before { helper.stub(:user_limit).and_return(Settings.tweets.users.count_default) }
let(:tweet) { FactoryGirl.create(:tweet, user: user, favorites_count: Settings.tweets.users.count_default, retweets_count: Settings.tweets.users.count_default + 1) }
it { should be true }
end
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb
index 02239a4..2b9c645 100644
--- a/spec/models/account_spec.rb
+++ b/spec/models/account_spec.rb
@@ -29,18 +29,39 @@ describe Account do
end
end
- describe "#update_settings!" do
- let(:account) { FactoryGirl.create(:account_1) }
- subject { account.update_settings!(notification: false, private: true) }
- its(:notification) { should be false }
- its(:private) { should be true }
+ describe ".set_of_collector" do
+ before { Settings.collector.stub(:count).and_return(3) }
+ let!(:accounts) { 10.times.map {|i| Account.create!(user_id: i, oauth_token: "abc", oauth_token_secret: "def", consumer_version: 1) } }
+ subject { Account.set_of_collector(2) }
+ it { should_not include -> m { m.id % 3 != 2 } }
end
- describe "#deactivate!" do
- let(:account) { FactoryGirl.create(:account_1) }
- it { account.active?.should be true }
- subject { account.tap(&:deactivate!) }
- its(:active?) { should be false }
+ describe "#notification?" do
+ context "when enabled" do
+ let(:account) { FactoryGirl.create(:account_1, notification: true) }
+ subject { account }
+ its(:notification?) { should be true }
+ end
+
+ context "when disabled" do
+ let(:account) { FactoryGirl.create(:account_1, notification: false) }
+ subject { account }
+ its(:notification?) { should be false }
+ end
+ end
+
+ describe "#private?" do
+ context "when private" do
+ let(:account) { FactoryGirl.create(:account_1, private: true) }
+ subject { account }
+ its(:private?) { should be true }
+ end
+
+ context "when public" do
+ let(:account) { FactoryGirl.create(:account_1, private: false) }
+ subject { account }
+ its(:private?) { should be false }
+ end
end
describe "#active?" do
@@ -56,6 +77,20 @@ describe Account do
end
end
+ describe "#update_settings!" do
+ let(:account) { FactoryGirl.create(:account_1) }
+ subject { account.update_settings!(notification: false, private: true) }
+ its(:notification) { should be false }
+ its(:private) { should be true }
+ end
+
+ describe "#deactivate!" do
+ let(:account) { FactoryGirl.create(:account_1) }
+ it { account.active?.should be true }
+ subject { account.tap(&:deactivate!) }
+ its(:active?) { should be false }
+ end
+
describe "#update_connection" do
let(:account) { FactoryGirl.create(:account_1) }
it "should not raise error" do
diff --git a/spec/models/favorite_spec.rb b/spec/models/favorite_spec.rb
index 80227bb..4cc6fe5 100644
--- a/spec/models/favorite_spec.rb
+++ b/spec/models/favorite_spec.rb
@@ -1,21 +1,17 @@
-require 'spec_helper'
+require "spec_helper"
describe Favorite do
- describe ".from_hash" do
- let(:hash) { {tweet_id: 123, user_id: 456} }
- subject { Favorite.from_hash(hash) }
- its(:tweet_id) { should be 123 }
- its(:user_id) { should be 456 }
- end
-
- describe ".from_tweet_object" do
- let(:user) { FactoryGirl.create(:user_1) }
- let(:tweet) { FactoryGirl.create(:tweet, user: user) }
- let(:tweet_object) { OpenStruct.new(
- favoriters: [123, 456, 789, 1012, 345, 678],
- id: tweet.id) }
- subject { Favorite.from_tweet_object(tweet_object); tweet.favorites.map(&:user_id).sort }
- its(:count) { should be 6 }
- it { should eq tweet_object.favoriters.sort }
+ describe ".from_receiver" do
+ let(:user_0) { FactoryGirl.create(:user) }
+ let(:user_1) { FactoryGirl.create(:user) }
+ let(:hash) { {"tweet" => {"id" => 123,
+ "text" => "abc",
+ "source" => "web",
+ "tweeted_at" => Time.now.to_s,
+ "user" => {"id" => user_0.id}},
+ "user" => {"id" => user_1.id}} }
+ subject { Favorite.from_receiver(hash) }
+ its(:tweet_id) { should be hash["tweet"]["id"] }
+ its(:user_id) { should be hash["user"]["id"] }
end
end
diff --git a/spec/models/retweet_spec.rb b/spec/models/retweet_spec.rb
index e2696bd..6a630e3 100644
--- a/spec/models/retweet_spec.rb
+++ b/spec/models/retweet_spec.rb
@@ -1,24 +1,19 @@
-require 'spec_helper'
+require "spec_helper"
describe Retweet do
- describe ".from_hash" do
- let(:hash) { {id: 890, tweet_id: 123, user_id: 456} }
- subject { Retweet.from_hash(hash) }
- its(:id) { should be 890 }
- its(:tweet_id) { should be 123 }
- its(:user_id) { should be 456 }
- end
-
- describe ".from_tweet_object" do
- let(:user) { FactoryGirl.create(:user_1) }
- let(:tweet) { FactoryGirl.create(:tweet, user: user) }
- let(:tweet_object) { OpenStruct.new(
- user: OpenStruct.new(user.attributes.update(profile_image_url_https: "abc")),
- id: 890,
- user_id: 123,
- retweeted_status: OpenStruct.new(id: tweet.id)) }
- subject { Retweet.from_tweet_object(tweet_object); tweet.retweets.map(&:user_id).sort }
- its(:count) { should be 1 }
- it { should eq [user.id] }
+ describe ".from_receiver" do
+ let(:user_0) { FactoryGirl.create(:user) }
+ let(:user_1) { FactoryGirl.create(:user) }
+ let(:hash) { {"id" => 1234,
+ "tweet" => {"id" => 123,
+ "text" => "abc",
+ "source" => "web",
+ "tweeted_at" => Time.now.to_s,
+ "user" => {"id" => user_0.id}},
+ "user" => {"id" => user_1.id}} }
+ subject { Retweet.from_receiver(hash) }
+ its(:id) { should be hash["id"] }
+ its(:tweet_id) { should be hash["tweet"]["id"] }
+ its(:user_id) { should be hash["user"]["id"] }
end
end
diff --git a/spec/models/tweet_spec.rb b/spec/models/tweet_spec.rb
index c631358..39374b5 100644
--- a/spec/models/tweet_spec.rb
+++ b/spec/models/tweet_spec.rb
@@ -52,19 +52,21 @@ describe Tweet do
end
end
- describe ".from_hash" do
+ describe ".from_receiver" do
let(:test_data) do
- {text: "abc",
- source: "web",
- tweeted_at: Time.now,
- user_id: @user_0.id}
+ {"id" => 123,
+ "text" => "abc",
+ "source" => "web",
+ "tweeted_at" => Time.now.to_s,
+ "user" => {"id" => @user_0.id}}
end
- subject { Tweet.from_hash(test_data) }
+ subject { Tweet.from_receiver(test_data) }
it { should be_a Tweet }
- its(:text) { should eq test_data[:text] }
- its(:source) { should eq test_data[:source] }
- its(:tweeted_at) { should eq test_data[:tweeted_at] }
+ its(:id) { should be test_data["id"] }
+ its(:text) { should eq test_data["text"] }
+ its(:source) { should eq test_data["source"] }
+ its(:tweeted_at) { should eq Time.parse(test_data["tweeted_at"]) }
its(:user) { should eq @user_0 }
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 06aae92..c2e92a7 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -68,7 +68,7 @@ describe User do
describe "#profile_image_url_original" do
let(:user) { FactoryGirl.create(:user) }
- before { user.stub!(:profile_image_url).and_return("https://example.com/profile_image_normal.png") }
+ before { user.stub(:profile_image_url).and_return("https://example.com/profile_image_normal.png") }
subject { user.profile_image_url_original }
it { should eq "https://example.com/profile_image.png" }
end