aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRhenium <rhenium@rhe.jp>2013-11-17 10:27:45 +0900
committerRhenium <rhenium@rhe.jp>2013-11-17 10:27:45 +0900
commitbbe477f59fb6aa1c6817386f3168d86e9f114520 (patch)
tree4910df86f2ff4728fe973b9be63e30d5940ecad7 /spec
parent9ad75b115fe5b5dc23d02afb8b3a130ed0c8dd47 (diff)
downloadaclog-bbe477f59fb6aa1c6817386f3168d86e9f114520.tar.gz
fix spec
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/application_controller_spec.rb36
-rw-r--r--spec/models/tweet_spec.rb61
-rw-r--r--spec/models/user_spec.rb36
-rw-r--r--spec/spec_helper.rb5
4 files changed, 68 insertions, 70 deletions
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index 91219e7..528f838 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -20,42 +20,6 @@ describe ApplicationController do
end
end
- describe "#_get_user" do
- let(:user) { FactoryGirl.create(:user) }
-
- context "when user exists" do
- subject { controller.__send__(:_get_user, id, screen_name) }
-
- context "and specify only id" do
- let(:id) { user.id }
- let(:screen_name) { nil }
- it { should eq user }
- end
-
- context "and specify only screen_name" do
- let(:id) { nil }
- let(:screen_name) { user.screen_name }
- it { should eq user }
- end
- end
-
- context "when user not exists" do
- subject { -> { controller.__send__(:_get_user, id, screen_name) } }
-
- context "when specify not existing id" do
- let(:id) { user.id + 1 }
- let(:screen_name) { nil }
- it { should raise_error Aclog::Exceptions::UserNotFound }
- end
-
- context "when specify only screen_name" do
- let(:id) { nil }
- let(:screen_name) { "1234567890abcdef" }
- it { should raise_error Aclog::Exceptions::UserNotFound }
- end
- end
- end
-
describe "#authorized_to_show_user?" do
before do
@user = FactoryGirl.create(:user, protected: true)
diff --git a/spec/models/tweet_spec.rb b/spec/models/tweet_spec.rb
index 39374b5..f103e9a 100644
--- a/spec/models/tweet_spec.rb
+++ b/spec/models/tweet_spec.rb
@@ -1,16 +1,14 @@
# -*- coding: utf-8 -*-
require "spec_helper"
-include Aclog::Twitter
-
describe Tweet do
before do
@user_0, @user_1, @user_2 = FactoryGirl.create_list(:user, 3) # t/f/r = 3/1/0, 1/2/1, 0/0/1
- @tweet_0_0 = FactoryGirl.create(:tweet, id: snowflake(2.days.ago) + 5000, user: @user_0, tweeted_at: 2.days.ago) # f/r = 2/0
- @tweet_0_1 = FactoryGirl.create(:tweet, id: snowflake(4.days.ago) + 5000, user: @user_0, tweeted_at: 4.days.ago) # f/r = 0/1
- @tweet_0_2 = FactoryGirl.create(:tweet, id: snowflake(6.days.ago) + 5000, user: @user_0, tweeted_at: 6.days.ago) # f/r = 0/0
- @tweet_1_0 = FactoryGirl.create(:tweet, id: snowflake(1.days.ago) + 5000, user: @user_1, tweeted_at: 1.days.ago) # f/r = 1/1
+ @tweet_0_0 = FactoryGirl.create(:tweet, id: snowflake_min(2.days.ago) + 5000, user: @user_0, tweeted_at: 2.days.ago) # f/r = 2/0
+ @tweet_0_1 = FactoryGirl.create(:tweet, id: snowflake_min(4.days.ago) + 5000, user: @user_0, tweeted_at: 4.days.ago) # f/r = 0/1
+ @tweet_0_2 = FactoryGirl.create(:tweet, id: snowflake_min(6.days.ago) + 5000, user: @user_0, tweeted_at: 6.days.ago) # f/r = 0/0
+ @tweet_1_0 = FactoryGirl.create(:tweet, id: snowflake_min(1.days.ago) + 5000, user: @user_1, tweeted_at: 1.days.ago) # f/r = 1/1
@tweet_0_0_f_0 = FactoryGirl.create(:favorite, user: @user_0, tweet: @tweet_0_0)
@tweet_0_0_f_1 = FactoryGirl.create(:favorite, user: @user_1, tweet: @tweet_0_0)
@@ -23,6 +21,7 @@ describe Tweet do
subject { @tweet_0_0.reload }
its(:favorites_count) { should be subject.favorites.count }
its(:retweets_count) { should be subject.retweets.count }
+ its(:reactions_count) { should be subject.favorites.count + subject.retweets.count }
end
describe ".delete_from_id" do
@@ -80,27 +79,38 @@ describe Tweet do
describe "reacted" do
subject { Tweet.reacted }
it { should_not include -> tweet { tweet.favorites_count + tweet.retweets_count == 0 } }
- it { should_not include -> tweet { tweet.favorites.count + tweet.retweets.count == 0 } }
its(:count) { should be 3 }
end
- describe "order_by_id" do
- subject { Tweet.order_by_id }
- it { subject.first.id.should be > subject.last.id }
+ describe "not_protected" do
+ subject { Tweet.not_protected.includes(:user) }
+ it { should_not include -> tweet { tweet.user.protected? } }
end
- describe "order_by_favorites" do
- subject { Tweet.order_by_favorites }
- it { subject.first.favorites.count.should be >= subject.last.favorites.count }
+ describe "max_id" do
+ subject { Tweet.max_id(@tweet_0_0.id - 1) }
+ its(:count) { should be 2 }
+ it { should_not include -> tweet { tweet.id > @tweet_0_0.id - 1 } }
+ end
+
+ describe "since_id" do
+ subject { Tweet.since_id(@tweet_0_0.id) }
+ its(:count) { should be 1 }
+ it { should_not include -> tweet { tweet.id <= @tweet_0_0.id } }
+ end
+
+ describe "page" do
+ subject { Tweet.limit(3).page(2) }
+ its(:count) { should be 1 }
end
- describe "order_by_retweets" do
- subject { Tweet.order_by_retweets }
- it { subject.first.retweets.count.should be >= subject.last.retweets.count }
+ describe "order_by_id" do
+ subject { Tweet.order_by_id }
+ it { subject.first.id.should be > subject.last.id }
end
describe "order_by_reactions" do
- subject { Tweet.order_by_favorites }
+ subject { Tweet.order_by_reactions }
it {
(subject.first.favorites.count + subject.first.retweets.count)
.should be >= (subject.last.favorites.count + subject.last.retweets.count)
@@ -126,22 +136,5 @@ describe Tweet do
it { subject.select {|m| m.retweets.any? {|n| n.user_id == @user_1.id } }.count.should be 1 }
it { should_not include -> tweet { not (tweet.retweets + tweet.favorites).any? {|a| a.user_id == @user_1.id } } }
end
-
- describe "not_protected" do
- subject { Tweet.not_protected.includes(:user) }
- it { should_not include -> tweet { tweet.user.protected? } }
- end
-
- describe "max_id" do
- subject { Tweet.max_id(@tweet_0_0.id - 1) }
- its(:count) { should be 2 }
- it { should_not include -> tweet { tweet.id > @tweet_0_0.id - 1 } }
- end
-
- describe "since" do
- subject { Tweet.since_id(@tweet_0_0.id) }
- its(:count) { should be 1 }
- it { should_not include -> tweet { tweet.id <= @tweet_0_0.id } }
- end
end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 0b65d5c..3b98850 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -36,6 +36,42 @@ describe User do
end
end
+ describe ".get" do
+ let(:user) { FactoryGirl.create(:user) }
+
+ context "when user exists" do
+ subject { User.get(id, screen_name) }
+
+ context "and specify only id" do
+ let(:id) { user.id }
+ let(:screen_name) { nil }
+ it { should eq user }
+ end
+
+ context "and specify only screen_name" do
+ let(:id) { nil }
+ let(:screen_name) { user.screen_name }
+ it { should eq user }
+ end
+ end
+
+ context "when user not exists" do
+ subject { -> { User.get(id, screen_name) } }
+
+ context "when specify not existing id" do
+ let(:id) { user.id + 1 }
+ let(:screen_name) { nil }
+ it { should raise_error Aclog::Exceptions::UserNotFound }
+ end
+
+ context "when specify only screen_name" do
+ let(:id) { nil }
+ let(:screen_name) { "1234567890abcdef" }
+ it { should raise_error Aclog::Exceptions::UserNotFound }
+ end
+ end
+ end
+
describe "#protected?" do
context "when not protected" do
let(:user) { FactoryGirl.create(:user, protected: false) }
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 006c743..39d4b0f 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -52,3 +52,8 @@ RSpec.configure do |config|
# --seed 1234
config.order = "random"
end
+
+def snowflake_min(time)
+ (time.to_datetime.to_i * 1000 - 1288834974657) << 22
+end
+