From 0001c84713cf2cc7f1c138b8f7e731c024dc2e46 Mon Sep 17 00:00:00 2001 From: "P.S.V.R" Date: Sat, 7 Jan 2012 22:36:38 +0800 Subject: [PATCH 1/6] gonna make some improvements --- README.textile | 61 -------------------------------------------------- readme.md | 1 + 2 files changed, 1 insertion(+), 61 deletions(-) delete mode 100644 README.textile create mode 100644 readme.md diff --git a/README.textile b/README.textile deleted file mode 100644 index 9a7d1d9..0000000 --- a/README.textile +++ /dev/null @@ -1,61 +0,0 @@ -Quora clone write in Ruby on Rails. - -h2. Requirements - -Install there software at first - -* Linux _(suggest Ubuntu 10.10+)_ or Mac OS X _(Don't try it on Windows, and send error messages to me!)_ -* Ruby 1.9.2 _(not support 1.9.1 or 1.8)_ -* MongoDB 1.8 -* Redis 2.2.2 -* Node.js 0.4.5 -* Coreseek 4.0.1 _(In English content, you can use Sphinx 1.10)_ -* Git - -h2. Installation - -h3. Start Redis, Mongodb first, you need - -pre. -$ sudo service redis start -$ sudo service mongodb start - -h3. Download Quora source code from Github - -pre. -$ git clone git://github.com/huacnlee/quora.git - -h3. Configure Quora - -pre. -$ cd quora -$ bundle install --path vendor/bundle -$ cp config/mongoid.yml.default config/mongoid.yml -$ cp config/setting.yml.default config/setting.yml -$ cp config/redis.yml.default config/redis.yml -$ cp config/zomet.yml.default config/zomet.yml -$ cp config/sphinx.yml.default config/sphinx.yml - -h3. Create Sphinx config files and index the database to Sphinx _(Before here, you need install Coreseek first.)_ - -pre. -$ rake mongoid_sphinx:configure -$ rake mongoid_sphinx:index -$ rake mongoid_sphinx:start - -h3. If you have Quora project old data in the Mongodb, you need to run this script to index the old data for search - -pre. -$ rake search:index - -h3. After, run Rails Server - -pre. -$ rails s - -Then, open your browser, points to http://127.0.0.1:3000 -That is it, enjoy yourself. - -If you have any Issues or Questions, please send message to "Quora Issues":https://github.com/huacnlee/quora/issues on Github. - - diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..8ce47e1 --- /dev/null +++ b/readme.md @@ -0,0 +1 @@ +# “者也”改进版 \ No newline at end of file From 2b32a41a89580d9843b5139ef283fbe975438e0f Mon Sep 17 00:00:00 2001 From: "P.S.V.R" Date: Thu, 2 Feb 2012 17:01:23 +0800 Subject: [PATCH 2/6] added tests, fixed one bug --- .rspec | 1 + Gemfile | 13 ++++++ Gemfile.lock | 74 +++++++++++++++++++++++++++++++ app/helpers/application_helper.rb | 2 +- app/views/logs/_log.html.erb | 7 +-- config/mongoid.yml.default | 30 ------------- config/redis.yml.default | 11 ----- config/setting.yml.default | 43 ------------------ config/zomet.yml.default | 15 ------- spec/factories.rb | 34 ++++++++++++++ spec/requests/log_spec.rb | 20 +++++++++ spec/spec_helper.rb | 43 ++++++++++++++++++ 12 files changed, 190 insertions(+), 103 deletions(-) create mode 100644 .rspec delete mode 100644 config/mongoid.yml.default delete mode 100644 config/redis.yml.default delete mode 100644 config/setting.yml.default delete mode 100644 config/zomet.yml.default create mode 100644 spec/factories.rb create mode 100644 spec/requests/log_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..53607ea --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--colour diff --git a/Gemfile b/Gemfile index 65368c8..76a5aa6 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 27ef7e3..3280fe6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 @@ -224,6 +291,7 @@ 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) @@ -231,6 +299,8 @@ DEPENDENCIES 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) @@ -243,6 +313,7 @@ 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) @@ -250,10 +321,13 @@ DEPENDENCIES 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) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a2bbfe4..0584b84 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/views/logs/_log.html.erb b/app/views/logs/_log.html.erb index 389a715..533274f 100644 --- a/app/views/logs/_log.html.erb +++ b/app/views/logs/_log.html.erb @@ -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 @@ -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? @@ -97,9 +98,9 @@ when "UserLog"
<%= user_avatar_tag(log.user,:small) %>
-
small_title<% end %>"><%= ask_title_tag(item) %>
+
small_title<% end %>"><%= ask_title_tag(item) %>
- <%= 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) %> diff --git a/config/mongoid.yml.default b/config/mongoid.yml.default deleted file mode 100644 index 67a026c..0000000 --- a/config/mongoid.yml.default +++ /dev/null @@ -1,30 +0,0 @@ -defaults: &defaults - host: '127.0.0.1' - autocreate_indexes: false - allow_dynamic_fields: true - include_root_in_json: false - parameterize_keys: true - persist_in_safe_mode: false - raise_not_found_error: true - reconnect_time: 3 - -development: - <<: *defaults - database: quora_development - -development_mongohq: - <<: *defaults - #uri: mongodb://:@flame.mongohq.com:27070/quora - #use demo mongohq database for fast run - uri: mongodb://root:666666@flame.mongohq.com:27070/quora - -test: - <<: *defaults - database: quora_test - -# set these environment variables on your prod server -production: - <<: *defaults - host: '127.0.0.1' - database: quora - diff --git a/config/redis.yml.default b/config/redis.yml.default deleted file mode 100644 index 34fbd7e..0000000 --- a/config/redis.yml.default +++ /dev/null @@ -1,11 +0,0 @@ -defaults: &defaults - host: '127.0.0.1' - port: 6379 -development: - <<: *defaults -test: - <<: *defaults -production: - <<: *defaults -development_mongohq: - <<: *defaults diff --git a/config/setting.yml.default b/config/setting.yml.default deleted file mode 100644 index 6122d42..0000000 --- a/config/setting.yml.default +++ /dev/null @@ -1,43 +0,0 @@ -default: &defaults - # 网站名称 - app_name: "者也" - # 页脚版权 - foot_html: "© 者也 zheye.org - 非营利问答平台,开源项目,代码。内测期间,如有问题还请谅解。" - # 网站的域名 - domain: "127.0.0.1:3000" - # 配置图片的域名 - upload_url: "http://127.0.0.1:3000/uploads" - # 设置管理员,在下面填写需要设置为管理员的用户 email - admin_emails: - - "huacnlee@gmail.com" - email_sender: 'no-reply@zheye.org' - aws_access_key_id: 'your aws access_key_id' - aws_secret_access_key: 'your aws secret_access_key' - # 是否开放注册 - allow_register: true - # 问题被多少次 spam 隐藏 - ask_spam_max: 8 - # 回答被多少次 spam 会删除线 - answer_spam_max: 5 - google_analytics_id: "UA-22413508-1" - spam_words: /敏感词1|敏感词2/ - -development: - <<: *defaults - -development_mongohq: - <<: *defaults - -test: - <<: *defaults - -production: - <<: *defaults - app_name: "者也" - # 页脚版权 - foot_html: "© 者也 zheye.org - 非营利问答平台,开源项目,代码,内测期间,如有问题还请谅解。" - # 网站的域名 - domain: "zheye.org" - # 配置图片的域名 - upload_url: "http://zheye.org/uploads" - google_analytics_id: "UA-22413508-1" diff --git a/config/zomet.yml.default b/config/zomet.yml.default deleted file mode 100644 index b8125de..0000000 --- a/config/zomet.yml.default +++ /dev/null @@ -1,15 +0,0 @@ -default: &defaults - server: 'localhost' - -development: - <<: *defaults - -development_mongohq: - <<: *defaults - -test: - <<: *defaults - -production: - <<: *defaults - diff --git a/spec/factories.rb b/spec/factories.rb new file mode 100644 index 0000000..aac55a0 --- /dev/null +++ b/spec/factories.rb @@ -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 \ No newline at end of file diff --git a/spec/requests/log_spec.rb b/spec/requests/log_spec.rb new file mode 100644 index 0000000..b616859 --- /dev/null +++ b/spec/requests/log_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..8d390ab --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,43 @@ +# 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 "rails/mongoid" +require 'rspec/rails' +require 'rspec/autorun' +require 'capybara/rspec' + +# 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} + +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 + config.before(:all) do + Mongoid.database.collections.map do |collection| + collection.drop if collection.name !~ /system/ + end + $redis.flushall + Redis::Search.config.redis.flushall + Resque.redis.flushall + end + +end From f761c601dc77834968171110f9536304e0987474 Mon Sep 17 00:00:00 2001 From: "P.S.V.R" Date: Thu, 2 Feb 2012 17:03:45 +0800 Subject: [PATCH 3/6] not planning to delete theses.. --- config/mongoid.yml.default | 30 ++++++++++++++++++++++++++ config/redis.yml.default | 11 ++++++++++ config/setting.yml.default | 43 ++++++++++++++++++++++++++++++++++++++ config/zomet.yml.default | 15 +++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 config/mongoid.yml.default create mode 100644 config/redis.yml.default create mode 100644 config/setting.yml.default create mode 100644 config/zomet.yml.default diff --git a/config/mongoid.yml.default b/config/mongoid.yml.default new file mode 100644 index 0000000..67a026c --- /dev/null +++ b/config/mongoid.yml.default @@ -0,0 +1,30 @@ +defaults: &defaults + host: '127.0.0.1' + autocreate_indexes: false + allow_dynamic_fields: true + include_root_in_json: false + parameterize_keys: true + persist_in_safe_mode: false + raise_not_found_error: true + reconnect_time: 3 + +development: + <<: *defaults + database: quora_development + +development_mongohq: + <<: *defaults + #uri: mongodb://:@flame.mongohq.com:27070/quora + #use demo mongohq database for fast run + uri: mongodb://root:666666@flame.mongohq.com:27070/quora + +test: + <<: *defaults + database: quora_test + +# set these environment variables on your prod server +production: + <<: *defaults + host: '127.0.0.1' + database: quora + diff --git a/config/redis.yml.default b/config/redis.yml.default new file mode 100644 index 0000000..34fbd7e --- /dev/null +++ b/config/redis.yml.default @@ -0,0 +1,11 @@ +defaults: &defaults + host: '127.0.0.1' + port: 6379 +development: + <<: *defaults +test: + <<: *defaults +production: + <<: *defaults +development_mongohq: + <<: *defaults diff --git a/config/setting.yml.default b/config/setting.yml.default new file mode 100644 index 0000000..6122d42 --- /dev/null +++ b/config/setting.yml.default @@ -0,0 +1,43 @@ +default: &defaults + # 网站名称 + app_name: "者也" + # 页脚版权 + foot_html: "© 者也 zheye.org - 非营利问答平台,开源项目,代码。内测期间,如有问题还请谅解。" + # 网站的域名 + domain: "127.0.0.1:3000" + # 配置图片的域名 + upload_url: "http://127.0.0.1:3000/uploads" + # 设置管理员,在下面填写需要设置为管理员的用户 email + admin_emails: + - "huacnlee@gmail.com" + email_sender: 'no-reply@zheye.org' + aws_access_key_id: 'your aws access_key_id' + aws_secret_access_key: 'your aws secret_access_key' + # 是否开放注册 + allow_register: true + # 问题被多少次 spam 隐藏 + ask_spam_max: 8 + # 回答被多少次 spam 会删除线 + answer_spam_max: 5 + google_analytics_id: "UA-22413508-1" + spam_words: /敏感词1|敏感词2/ + +development: + <<: *defaults + +development_mongohq: + <<: *defaults + +test: + <<: *defaults + +production: + <<: *defaults + app_name: "者也" + # 页脚版权 + foot_html: "© 者也 zheye.org - 非营利问答平台,开源项目,代码,内测期间,如有问题还请谅解。" + # 网站的域名 + domain: "zheye.org" + # 配置图片的域名 + upload_url: "http://zheye.org/uploads" + google_analytics_id: "UA-22413508-1" diff --git a/config/zomet.yml.default b/config/zomet.yml.default new file mode 100644 index 0000000..b8125de --- /dev/null +++ b/config/zomet.yml.default @@ -0,0 +1,15 @@ +default: &defaults + server: 'localhost' + +development: + <<: *defaults + +development_mongohq: + <<: *defaults + +test: + <<: *defaults + +production: + <<: *defaults + From 47592f7516c4c04b3149c40f4efd572f48535cae Mon Sep 17 00:00:00 2001 From: "P.S.V.R" Date: Thu, 2 Feb 2012 17:08:59 +0800 Subject: [PATCH 4/6] readme won't change --- README.textile | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ readme.md | 1 - 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 README.textile delete mode 100644 readme.md diff --git a/README.textile b/README.textile new file mode 100644 index 0000000..9a7d1d9 --- /dev/null +++ b/README.textile @@ -0,0 +1,61 @@ +Quora clone write in Ruby on Rails. + +h2. Requirements + +Install there software at first + +* Linux _(suggest Ubuntu 10.10+)_ or Mac OS X _(Don't try it on Windows, and send error messages to me!)_ +* Ruby 1.9.2 _(not support 1.9.1 or 1.8)_ +* MongoDB 1.8 +* Redis 2.2.2 +* Node.js 0.4.5 +* Coreseek 4.0.1 _(In English content, you can use Sphinx 1.10)_ +* Git + +h2. Installation + +h3. Start Redis, Mongodb first, you need + +pre. +$ sudo service redis start +$ sudo service mongodb start + +h3. Download Quora source code from Github + +pre. +$ git clone git://github.com/huacnlee/quora.git + +h3. Configure Quora + +pre. +$ cd quora +$ bundle install --path vendor/bundle +$ cp config/mongoid.yml.default config/mongoid.yml +$ cp config/setting.yml.default config/setting.yml +$ cp config/redis.yml.default config/redis.yml +$ cp config/zomet.yml.default config/zomet.yml +$ cp config/sphinx.yml.default config/sphinx.yml + +h3. Create Sphinx config files and index the database to Sphinx _(Before here, you need install Coreseek first.)_ + +pre. +$ rake mongoid_sphinx:configure +$ rake mongoid_sphinx:index +$ rake mongoid_sphinx:start + +h3. If you have Quora project old data in the Mongodb, you need to run this script to index the old data for search + +pre. +$ rake search:index + +h3. After, run Rails Server + +pre. +$ rails s + +Then, open your browser, points to http://127.0.0.1:3000 +That is it, enjoy yourself. + +If you have any Issues or Questions, please send message to "Quora Issues":https://github.com/huacnlee/quora/issues on Github. + + diff --git a/readme.md b/readme.md deleted file mode 100644 index 8ce47e1..0000000 --- a/readme.md +++ /dev/null @@ -1 +0,0 @@ -# “者也”改进版 \ No newline at end of file From 8f273b7ecb60575d84cdb4562f0d135f84629c7b Mon Sep 17 00:00:00 2001 From: "P.S.V.R" Date: Thu, 2 Feb 2012 18:11:30 +0800 Subject: [PATCH 5/6] just another bug --- app/mailers/base_mailer.rb | 2 +- app/models/log.rb | 4 ++-- config/initializers/setup_mailer.rb | 20 ++++++++++---------- spec/models/ask_spec.rb | 24 ++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 spec/models/ask_spec.rb diff --git a/app/mailers/base_mailer.rb b/app/mailers/base_mailer.rb index 1ab6a11..74d60b8 100644 --- a/app/mailers/base_mailer.rb +++ b/app/mailers/base_mailer.rb @@ -1,6 +1,6 @@ require "resque" class BaseMailer < ActionMailer::Base - include Resque::Mailer + # include Resque::Mailer default :sender => Setting.email_sender helper :application,:users,:asks layout "mailer" diff --git a/app/models/log.rb b/app/models/log.rb index 90fda31..d738cd9 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -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 diff --git a/config/initializers/setup_mailer.rb b/config/initializers/setup_mailer.rb index 8ef6c71..bd64cbd 100644 --- a/config/initializers/setup_mailer.rb +++ b/config/initializers/setup_mailer.rb @@ -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 diff --git a/spec/models/ask_spec.rb b/spec/models/ask_spec.rb new file mode 100644 index 0000000..ba3aa29 --- /dev/null +++ b/spec/models/ask_spec.rb @@ -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 From 40629933727c351527fd4f49e3f1f5024c09a458 Mon Sep 17 00:00:00 2001 From: "P.S.V.R" Date: Thu, 2 Feb 2012 18:14:06 +0800 Subject: [PATCH 6/6] oops --- app/mailers/base_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/base_mailer.rb b/app/mailers/base_mailer.rb index 74d60b8..1ab6a11 100644 --- a/app/mailers/base_mailer.rb +++ b/app/mailers/base_mailer.rb @@ -1,6 +1,6 @@ require "resque" class BaseMailer < ActionMailer::Base - # include Resque::Mailer + include Resque::Mailer default :sender => Setting.email_sender helper :application,:users,:asks layout "mailer"