Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Tests added, Bugs Fixed #107

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--colour
13 changes: 13 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,17 @@ gem "redis-search", "0.6.1"

group :development do
gem 'rails-dev-boost-beta','0.1.2', :require => 'rails_development_boost'
gem "rspec-rails", "~> 2.6"
gem 'pry'
end


group :test do
gem "rspec-rails", "~> 2.6"
gem 'turn', :require => false
gem "factory_girl_rails", "~> 1.2"
gem 'capybara'
gem 'guard-rspec'
gem 'pry'
gem 'ruby-debug19', :require => 'ruby-debug'
end
74 changes: 74 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ GEM
activesupport (= 3.0.5)
activesupport (3.0.5)
addressable (2.2.6)
ansi (1.4.1)
archive-tar-minitar (0.5.2)
arel (2.0.10)
aws-ses (0.4.2)
builder
Expand All @@ -49,13 +51,24 @@ GEM
bson (1.2.4)
bson_ext (1.2.4)
builder (2.1.2)
capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
carrierwave (0.5.3)
activesupport (~> 3.0)
cells (3.6.5)
actionpack (~> 3.0)
railties (~> 3.0)
childprocess (0.3.0)
ffi (~> 1.0.6)
chinese_pinyin (0.3.0)
coderay (1.0.5)
colorize (0.5.8)
columnize (0.3.6)
dalli (1.1.2)
devise (1.2.rc2)
bcrypt-ruby (~> 2.1.2)
Expand All @@ -64,22 +77,38 @@ GEM
devise_invitable (0.4.rc5)
devise (~> 1.2.rc2)
rails (~> 3.0.0)
diff-lcs (1.1.3)
erubis (2.6.6)
abstract (>= 1.0.0)
factory_girl (2.5.0)
activesupport
factory_girl_rails (1.6.0)
factory_girl (~> 2.5.0)
railties (>= 3.0.0)
faraday (0.5.7)
addressable (~> 2.2.4)
multipart-post (~> 1.1.0)
rack (>= 1.1.0, < 2)
ffi (1.0.11)
guard (1.0.0)
ffi (>= 0.5.0)
thor (~> 0.14.6)
guard-rspec (0.6.0)
guard (>= 0.10.0)
i18n (0.6.0)
json (1.4.6)
json_pure (1.6.1)
juggernaut (2.0.3)
redis
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
memcache-client (1.8.5)
method_source (0.7.0)
mime-types (1.16)
mini_magick (3.2)
subexec (~> 0.0.4)
Expand Down Expand Up @@ -146,6 +175,10 @@ GEM
oa-oauth (~> 0.2.0)
orm_adapter (0.0.5)
polyglot (0.3.2)
pry (0.9.8)
coderay (~> 1.0.5)
method_source (~> 0.7)
slop (>= 2.4.3, < 3)
pyu-ruby-sasl (0.0.3.3)
rack (1.2.3)
rack-mount (0.6.14)
Expand Down Expand Up @@ -186,15 +219,45 @@ GEM
rest-client (1.6.3)
mime-types (>= 1.16)
rmmseg-cpp-huacnlee (0.2.9)
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
rspec-mocks (~> 2.8.0)
rspec-core (2.8.0)
rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
rspec-rails (2.8.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.8.0)
ruby-debug-base19 (0.11.25)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
ruby-debug19 (0.11.6)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby-openid (2.1.8)
ruby-openid-apps-discovery (1.2.0)
ruby-openid (>= 2.1.7)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
rubyntlm (0.1.1)
rubyzip (0.9.5)
selenium-webdriver (2.13.0)
childprocess (>= 0.2.1)
ffi (~> 1.0.9)
json_pure
rubyzip
settingslogic (2.0.6)
simple_form (1.3.1)
sinatra (1.2.6)
rack (~> 1.1)
tilt (>= 1.2.2, < 2.0)
slop (2.4.3)
smurf-huacnlee (1.0.5)
subexec (0.0.4)
tagged-cache (1.1.1)
Expand All @@ -204,6 +267,8 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
turn (0.8.3)
ansi
tzinfo (0.3.29)
vegas (0.1.8)
rack (>= 1.0.0)
Expand All @@ -216,6 +281,8 @@ GEM
activesupport (>= 2.3.4)
will_paginate (3.0.pre)
xml-simple (1.1.0)
xpath (0.1.4)
nokogiri (~> 1.3)

PLATFORMS
ruby
Expand All @@ -224,13 +291,16 @@ DEPENDENCIES
aws-ses (= 0.4.2)
bson (= 1.2.4)
bson_ext (= 1.2.4)
capybara
carrierwave (= 0.5.3)
cells (= 3.6.5)
chinese_pinyin (= 0.3.0)
colorize (= 0.5.8)
dalli (= 1.1.2)
devise (= 1.2.rc2)
devise_invitable (= 0.4.rc5)
factory_girl_rails (~> 1.2)
guard-rspec
htmldiff!
juggernaut
memcache-client (= 1.8.5)
Expand All @@ -243,17 +313,21 @@ DEPENDENCIES
oa-openid (= 0.2.0)
omniauth (= 0.2.0)
omniauth_china (= 0.0.6)
pry
rails (= 3.0.5)
rails-dev-boost-beta (= 0.1.2)
redis (= 2.1.1)
redis-search (= 0.6.1)
resque (= 1.15.0)
resque_mailer (= 1.0.1)
rmmseg-cpp-huacnlee (= 0.2.9)
rspec-rails (~> 2.6)
ruby-debug19
settingslogic (= 2.0.6)
simple_form (= 1.3.1)
smurf-huacnlee
tagged-cache (= 1.1.1)
turn
voteable_mongoid (= 0.6.0)
whenever (= 0.6.2)
will_paginate (= 3.0.pre)
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module ApplicationHelper
def use_yahei_font?(ua)
use = true
["Windows NT 5.2", "Windows NT 5.1"].each do |w|
if ua.include?(w)
if ua and ua.include?(w)
use = false
break
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def send_notification
target_id: self.target_parent_id,
action: "INVITE_TO_ANSWER")
when "NEW_TO_USER"
Notification.create(user_id: self.target_id,
Notification.create(user_id: self.target_parent_id,
log_id: self.id,
target_id: self.target_parent_id,
target_id: self.target_id,
action: "ASK_USER")
end
end
Expand Down
7 changes: 4 additions & 3 deletions app/views/logs/_log.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<%
log.action = "" if log.action.blank?
action = log.action.gsub("ADDTOPIC", "ADD_TOPIC").gsub("DELTOPIC", "DEL_TOPIC")

case log._type
when "AskLog"
item = log.ask
Expand Down Expand Up @@ -74,6 +73,8 @@ when "UserLog"
item = Topic.first(:conditions => { :id => log.target_id })
elsif ["FOLLOW_USER", "UNFOLLOW_USER"].include?(action)
item = User.first(:conditions => { :id => log.target_id})
elsif ["FOLLOW_ASK", "UNFOLLOW_ASK"].include?(action)
item = Ask.first(:conditions => { :id => log.target_id})
elsif ["AGREE"].include?(action)
answer = Answer.first(:conditions => {:id => log.target_id})
if !answer.blank?
Expand All @@ -97,9 +98,9 @@ when "UserLog"
<div class="savatar">
<%= user_avatar_tag(log.user,:small) %>
</div>
<div class="title<% if ["FOLLOW", "UNFOLLOW"].include?(action) %> small_title<% end %>"><%= ask_title_tag(item) %></div>
<div class="title<% if ["FOLLOW_ASK", "UNFOLLOW_ASK"].include?(action) %> small_title<% end %>"><%= ask_title_tag(item) %></div>
<div class="info">
<%= user_name_tag(log.user) %> <%= action == "FOLLOW" ? "关注了该问题" : (action == "UNFOLLOW" ? "取消关注了该问题" : "赞同该回答") %>
<%= user_name_tag(log.user) %> <%= action == "FOLLOW_ASK" ? "关注了该问题" : (action == "UNFOLLOW_ASK" ? "取消关注了该问题" : "赞同该回答") %>
• <%= item.answers_count %> 个答案
<% if current_user %>
<% if current_user.ask_followed?(item) %>
Expand Down
20 changes: 10 additions & 10 deletions config/initializers/setup_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
#:user_name => Setting.smtp_username,
#:password => Setting.smtp_password
#}
ActionMailer::Base.add_delivery_method :ses, AWS::SES::Base,
:access_key_id => Setting.aws_access_key_id,
:secret_access_key => Setting.aws_secret_access_key

# action mailer config
ActionMailer::Base.default_content_type = "text/html"
#ActionMailer::Base.delivery_method = :smtp
#ActionMailer::Base.delivery_method = :test
ActionMailer::Base.delivery_method = :ses
# ActionMailer::Base.add_delivery_method :ses, AWS::SES::Base,
# :access_key_id => Setting.aws_access_key_id,
# :secret_access_key => Setting.aws_secret_access_key
#
# # action mailer config
# ActionMailer::Base.default_content_type = "text/html"
# #ActionMailer::Base.delivery_method = :smtp
# #ActionMailer::Base.delivery_method = :test
# ActionMailer::Base.delivery_method = :ses
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.default_url_options[:host] = "#{Setting.domain}"
ActionMailer::Base.raise_delivery_errors = true
# ActionMailer::Base.raise_delivery_errors = true
34 changes: 34 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FactoryGirl.define do
factory :user do
sequence(:email){|n| "foo#{n}@bar.com"}
sequence(:name){|n| "u#{n}"}
password 'really_really_dark'
end

factory :topic do
sequence(:name){|n| "topic#{n}"}
end

factory :ask do
user
current_user_id{user.id}
sequence(:title){|n| "ask_#{n}"}
end

factory :answer do
ask
user
sequence(:body){|n| "blah #{n} blah blah #{n}..."}
end

factory :ask_log_ADD_TOPIC,class:AskLog do
ask
user
title {FactoryGirl.create_list(:topic,3).collect(&:name).join(',')}
target_id {ask.id}
action 'ADD_TOPIC'
target_parent_id {ask.id}
target_parent_title {ask.title}
diff ""
end
end
24 changes: 24 additions & 0 deletions spec/models/ask_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# coding: utf-8
require 'spec_helper'

describe "Ask" do
before(:all) do
@user1 = FactoryGirl.create(:user)
@user2 = FactoryGirl.create(:user)
end
it "when create and invite, notify the invitee" do
@ask = FactoryGirl.create(:ask)
Notification.all.delete
@user1.notifications.unread.count.should eq 0
invite = AskInvite.invite(@ask.id, @user1.id, @user2.id)
@user1.reload
@user1.notifications.unread.count.should eq 1
end
it "when create with to_user_id, notify the to_user" do
Notification.all.delete
@user1.notifications.unread.count.should eq 0
@ask = FactoryGirl.create(:ask,:to_user_id => @user1.id)
@user1.reload
@user1.notifications.unread.count.should eq 1
end
end
20 changes: 20 additions & 0 deletions spec/requests/log_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# coding: utf-8
require 'spec_helper'

describe "logs_controller requests" do
it "when user follow/unfollow asks, display it via index" do
user = FactoryGirl.create(:user)
ask = FactoryGirl.create(:ask)
Log.all.delete
visit logs_path
page.should_not have_content('关注了该问题')
page.should_not have_content('取消关注了该问题')
user.follow_ask(ask)
visit logs_path
page.should have_content('关注了该问题')
user.unfollow_ask(ask)
visit logs_path
user.unfollow_ask(ask)
page.should have_content('取消关注了该问题')
end
end
Loading