Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add shop integration test.

  • Loading branch information...
commit d65c4f1dfd41180f57ce02a222a04f4957aaaf08 1 parent 79504b1
@saberma authored
View
8 Vagrantfile
@@ -20,7 +20,7 @@ Vagrant::Config.run do |config|
config.vm.forward_port "resque-web", 8282, 8282
config.vm.forward_port "livereload", 35729, 35729
config.vm.forward_port "sphinx", 9313, 9313
- config.vm.forward_port "sphinx-test", 9314, 9314
+ #config.vm.forward_port "sphinx-test", 9314, 9314 #在宿主机运行测试
#fixed: share folder performance. http://vagrantup.com/docs/nfs.html
config.vm.share_folder("v-root", "/vagrant", ".", :nfs => true)
@@ -40,8 +40,8 @@ Vagrant::Config.run do |config|
chef.log_level = :debug
end
- config.vm.customize do |vm|
- vm.memory_size = 1024
- end
+ #config.vm.customize do |vm|
+ # vm.memory_size = 1024
+ #end
end
View
1  config/routes.rb
@@ -39,6 +39,7 @@
#match '/s/files/:id/theme/assets/:asset' => 'shops#asset', # :asset参数值为style.css(包含.号),rspec报No route matches
scope module: :shop do
match '/s/files/:id/theme/assets/:file.:format' => 'shops#asset'
+ match '/s/files/test/:id/theme/assets/:file.:format' => 'shops#asset' #测试中使用
end
match "/admin" => "home#dashboard"
View
182 config/test.sphinx.conf
@@ -0,0 +1,182 @@
+indexer
+{
+}
+
+searchd
+{
+ listen = 127.0.0.1:9314
+ log = /home/saberma/Documents/shopqi/log/searchd.log
+ query_log = /home/saberma/Documents/shopqi/log/searchd.query.log
+ pid_file = /home/saberma/Documents/shopqi/log/searchd.test.pid
+}
+
+source article_core_0
+{
+ type = pgsql
+ sql_host = localhost
+ sql_user = postgres
+ sql_pass =
+ sql_db = shopqi_test
+ sql_query_pre = UPDATE "articles" SET "delta" = FALSE WHERE "delta" = TRUE
+ sql_query_pre = SET TIME ZONE 'UTC'
+ sql_query = SELECT "articles"."id" * 3::INT8 + 0 AS "id" , "articles"."title" AS "title", "articles"."body_html" AS "body_html", "articles"."id" AS "sphinx_internal_id", 0 AS "sphinx_deleted", 3448190970 AS "class_crc", "articles"."shop_id" AS "shop_id" FROM "articles" WHERE ("articles"."id" >= $start AND "articles"."id" <= $end AND "articles"."delta" = FALSE) GROUP BY "articles"."id", "articles"."title", "articles"."body_html", "articles"."id", "articles"."shop_id"
+ sql_query_range = SELECT COALESCE(MIN("id"), 1::bigint), COALESCE(MAX("id"), 1::bigint) FROM "articles" WHERE "articles"."delta" = FALSE
+ sql_attr_uint = sphinx_internal_id
+ sql_attr_uint = sphinx_deleted
+ sql_attr_uint = class_crc
+ sql_attr_uint = shop_id
+ sql_query_info = SELECT * FROM "articles" WHERE "id" = (($id - 0) / 3)
+}
+
+index article_core
+{
+ source = article_core_0
+ path = /home/saberma/Documents/shopqi/db/sphinx/test/article_core
+ charset_dictpath = /home/saberma/Documents/shopqi/lib
+ charset_type = zh_cn.utf-8
+}
+
+source article_delta_0 : article_core_0
+{
+ type = pgsql
+ sql_host = localhost
+ sql_user = postgres
+ sql_pass =
+ sql_db = shopqi_test
+ sql_query_pre =
+ sql_query_pre = SET TIME ZONE 'UTC'
+ sql_query = SELECT "articles"."id" * 3::INT8 + 0 AS "id" , "articles"."title" AS "title", "articles"."body_html" AS "body_html", "articles"."id" AS "sphinx_internal_id", 0 AS "sphinx_deleted", 3448190970 AS "class_crc", "articles"."shop_id" AS "shop_id" FROM "articles" WHERE ("articles"."id" >= $start AND "articles"."id" <= $end AND "articles"."delta" = TRUE) GROUP BY "articles"."id", "articles"."title", "articles"."body_html", "articles"."id", "articles"."shop_id"
+ sql_query_range = SELECT COALESCE(MIN("id"), 1::bigint), COALESCE(MAX("id"), 1::bigint) FROM "articles" WHERE "articles"."delta" = TRUE
+ sql_attr_uint = sphinx_internal_id
+ sql_attr_uint = sphinx_deleted
+ sql_attr_uint = class_crc
+ sql_attr_uint = shop_id
+ sql_query_info = SELECT * FROM "articles" WHERE "id" = (($id - 0) / 3)
+}
+
+index article_delta : article_core
+{
+ source = article_delta_0
+ path = /home/saberma/Documents/shopqi/db/sphinx/test/article_delta
+}
+
+index article
+{
+ type = distributed
+ local = article_delta
+ local = article_core
+}
+
+source page_core_0
+{
+ type = pgsql
+ sql_host = localhost
+ sql_user = postgres
+ sql_pass =
+ sql_db = shopqi_test
+ sql_query_pre = UPDATE "pages" SET "delta" = FALSE WHERE "delta" = TRUE
+ sql_query_pre = SET TIME ZONE 'UTC'
+ sql_query = SELECT "pages"."id" * 3::INT8 + 1 AS "id" , "pages"."title" AS "title", "pages"."body_html" AS "body_html", "pages"."id" AS "sphinx_internal_id", 0 AS "sphinx_deleted", 3023575326 AS "class_crc", "pages"."shop_id" AS "shop_id" FROM "pages" WHERE ("pages"."id" >= $start AND "pages"."id" <= $end AND "pages"."delta" = FALSE) GROUP BY "pages"."id", "pages"."title", "pages"."body_html", "pages"."id", "pages"."shop_id"
+ sql_query_range = SELECT COALESCE(MIN("id"), 1::bigint), COALESCE(MAX("id"), 1::bigint) FROM "pages" WHERE "pages"."delta" = FALSE
+ sql_attr_uint = sphinx_internal_id
+ sql_attr_uint = sphinx_deleted
+ sql_attr_uint = class_crc
+ sql_attr_uint = shop_id
+ sql_query_info = SELECT * FROM "pages" WHERE "id" = (($id - 1) / 3)
+}
+
+index page_core
+{
+ source = page_core_0
+ path = /home/saberma/Documents/shopqi/db/sphinx/test/page_core
+ charset_dictpath = /home/saberma/Documents/shopqi/lib
+ charset_type = zh_cn.utf-8
+}
+
+source page_delta_0 : page_core_0
+{
+ type = pgsql
+ sql_host = localhost
+ sql_user = postgres
+ sql_pass =
+ sql_db = shopqi_test
+ sql_query_pre =
+ sql_query_pre = SET TIME ZONE 'UTC'
+ sql_query = SELECT "pages"."id" * 3::INT8 + 1 AS "id" , "pages"."title" AS "title", "pages"."body_html" AS "body_html", "pages"."id" AS "sphinx_internal_id", 0 AS "sphinx_deleted", 3023575326 AS "class_crc", "pages"."shop_id" AS "shop_id" FROM "pages" WHERE ("pages"."id" >= $start AND "pages"."id" <= $end AND "pages"."delta" = TRUE) GROUP BY "pages"."id", "pages"."title", "pages"."body_html", "pages"."id", "pages"."shop_id"
+ sql_query_range = SELECT COALESCE(MIN("id"), 1::bigint), COALESCE(MAX("id"), 1::bigint) FROM "pages" WHERE "pages"."delta" = TRUE
+ sql_attr_uint = sphinx_internal_id
+ sql_attr_uint = sphinx_deleted
+ sql_attr_uint = class_crc
+ sql_attr_uint = shop_id
+ sql_query_info = SELECT * FROM "pages" WHERE "id" = (($id - 1) / 3)
+}
+
+index page_delta : page_core
+{
+ source = page_delta_0
+ path = /home/saberma/Documents/shopqi/db/sphinx/test/page_delta
+}
+
+index page
+{
+ type = distributed
+ local = page_delta
+ local = page_core
+}
+
+source product_core_0
+{
+ type = pgsql
+ sql_host = localhost
+ sql_user = postgres
+ sql_pass =
+ sql_db = shopqi_test
+ sql_query_pre = UPDATE "products" SET "delta" = FALSE WHERE "delta" = TRUE
+ sql_query_pre = SET TIME ZONE 'UTC'
+ sql_query = SELECT "products"."id" * 3::INT8 + 2 AS "id" , "products"."title" AS "title", "products"."body_html" AS "body_html", "products"."product_type" AS "product_type", "products"."vendor" AS "vendor", array_to_string(array_accum(COALESCE("product_variants"."option1", '0')), ' ') AS "option1", array_to_string(array_accum(COALESCE("product_variants"."option2", '0')), ' ') AS "option2", array_to_string(array_accum(COALESCE("product_variants"."option3", '0')), ' ') AS "option3", array_to_string(array_accum(COALESCE("product_variants"."sku", '0')), ' ') AS "sku", "products"."id" AS "sphinx_internal_id", 0 AS "sphinx_deleted", 485965105 AS "class_crc", "products"."shop_id" AS "shop_id" FROM "products" LEFT OUTER JOIN "product_variants" ON "product_variants"."product_id" = "products"."id" WHERE ("products"."id" >= $start AND "products"."id" <= $end AND "products"."delta" = FALSE) GROUP BY "products"."id", "products"."title", "products"."body_html", "products"."product_type", "products"."vendor", "products"."id", "products"."shop_id"
+ sql_query_range = SELECT COALESCE(MIN("id"), 1::bigint), COALESCE(MAX("id"), 1::bigint) FROM "products" WHERE "products"."delta" = FALSE
+ sql_attr_uint = sphinx_internal_id
+ sql_attr_uint = sphinx_deleted
+ sql_attr_uint = class_crc
+ sql_attr_uint = shop_id
+ sql_query_info = SELECT * FROM "products" WHERE "id" = (($id - 2) / 3)
+}
+
+index product_core
+{
+ source = product_core_0
+ path = /home/saberma/Documents/shopqi/db/sphinx/test/product_core
+ charset_dictpath = /home/saberma/Documents/shopqi/lib
+ charset_type = zh_cn.utf-8
+}
+
+source product_delta_0 : product_core_0
+{
+ type = pgsql
+ sql_host = localhost
+ sql_user = postgres
+ sql_pass =
+ sql_db = shopqi_test
+ sql_query_pre =
+ sql_query_pre = SET TIME ZONE 'UTC'
+ sql_query = SELECT "products"."id" * 3::INT8 + 2 AS "id" , "products"."title" AS "title", "products"."body_html" AS "body_html", "products"."product_type" AS "product_type", "products"."vendor" AS "vendor", array_to_string(array_accum(COALESCE("product_variants"."option1", '0')), ' ') AS "option1", array_to_string(array_accum(COALESCE("product_variants"."option2", '0')), ' ') AS "option2", array_to_string(array_accum(COALESCE("product_variants"."option3", '0')), ' ') AS "option3", array_to_string(array_accum(COALESCE("product_variants"."sku", '0')), ' ') AS "sku", "products"."id" AS "sphinx_internal_id", 0 AS "sphinx_deleted", 485965105 AS "class_crc", "products"."shop_id" AS "shop_id" FROM "products" LEFT OUTER JOIN "product_variants" ON "product_variants"."product_id" = "products"."id" WHERE ("products"."id" >= $start AND "products"."id" <= $end AND "products"."delta" = TRUE) GROUP BY "products"."id", "products"."title", "products"."body_html", "products"."product_type", "products"."vendor", "products"."id", "products"."shop_id"
+ sql_query_range = SELECT COALESCE(MIN("id"), 1::bigint), COALESCE(MAX("id"), 1::bigint) FROM "products" WHERE "products"."delta" = TRUE
+ sql_attr_uint = sphinx_internal_id
+ sql_attr_uint = sphinx_deleted
+ sql_attr_uint = class_crc
+ sql_attr_uint = shop_id
+ sql_query_info = SELECT * FROM "products" WHERE "id" = (($id - 2) / 3)
+}
+
+index product_delta : product_core
+{
+ source = product_delta_0
+ path = /home/saberma/Documents/shopqi/db/sphinx/test/product_delta
+}
+
+index product
+{
+ type = distributed
+ local = product_delta
+ local = product_core
+}
View
136 spec/requests/shop/shops_spec.rb
@@ -0,0 +1,136 @@
+# encoding: utf-8
+require 'spec_helper'
+
+describe "Shop::Shops", js:true do
+
+ #let(:user_admin) { with_resque { Factory :user_admin } }
+ let(:user_admin) { Factory :user_admin }
+
+ let(:shop) { user_admin.shop }
+
+ before(:each) { Capybara::Server.manual_host = "#{shop.permanent_domain}.lvh.me" }
+
+ after(:each) { Capybara::Server.manual_host = nil }
+
+ # 商品列表
+ describe "GET /collections/all" do
+
+ it "should list products!" do
+ visit '/'
+ click_on '商品列表'
+ page.should have_content('示例商品6')
+ end
+ end
+
+ # 首页
+ describe "GET /products" do
+
+ it "should show product" do
+ product = shop.products.where(handle: 'example-1').first
+ variant = product.variants.first
+ visit '/'
+ click_on product.title
+ page.should have_content('这是一个商品')
+ click_on 'Add to cart'
+ # 更新数量
+ within('#checkout') do
+ fill_in "updates_#{variant.id}", with: '2'
+ end
+ click_on 'Update'
+ find("#updates_#{variant.id}")[:value].should eql '2'
+ click_on 'Checkout'
+ #收货人
+ fill_in 'order[email]', with: 'mahb45@gmail.com'
+ fill_in 'order[billing_address_attributes][name]', with: '马海波'
+ select '广东省', form: 'order[billing_address_attributes][province]'
+ select '深圳市', form: 'order[billing_address_attributes][city]'
+ select '南山区', form: 'order[billing_address_attributes][district]'
+ fill_in 'order[billing_address_attributes][address1]', with: '科技园'
+ fill_in 'order[billing_address_attributes][phone]', with: '13928458888'
+ click_on '去到下一步'
+ #选择支付方式
+ page.should have_content(product.title)
+ click_on '购买'
+ page.should have_content("您的订单号为: #1001")
+ end
+
+ end
+
+ # 首页
+ describe "GET /" do
+
+ it "should list products" do
+ visit '/'
+ page.should have_content('示例商品1')
+ end
+
+ end
+
+ # 查询
+ describe "GET /search" do
+
+ before(:each) do
+ ThinkingSphinx::Test.start
+ visit '/'
+ click_on '查询'
+ end
+
+ after(:each) do
+ ThinkingSphinx::Test.stop
+ end
+
+ it "should list blog article" do
+ blog = shop.blogs.where(handle: 'latest-news').first
+ article = blog.articles.create title: '如何选购iphone'
+ ThinkingSphinx::Test.index 'article_delta'
+ click_on '查询'
+ fill_in 'q', with: '选购'
+ click_on 'Search'
+ page.should have_content(article.title)
+ end
+
+ it "should list products" do
+ fill_in 'q', with: '示例'
+ click_on 'Search'
+ page.should have_content('示例商品1')
+ end
+
+ it "should list page" do
+ fill_in 'q', with: '关于'
+ click_on 'Search'
+ page.should have_content('关于我们')
+ end
+
+ end
+
+ # 关于我们
+ describe "GET /pages" do
+
+ it "should list products!" do
+ visit '/'
+ click_on '关于我们'
+ page.should have_content('介绍您的公司')
+ end
+
+ end
+
+end
+
+# hack:支持subdomain #see: http://blog.jamesalmond.com/testing-subdomains-using-capybara
+class Capybara::Server
+ def self.manual_host=(value)
+ @manual_host = value
+ end
+
+ def self.manual_host
+ @manual_host ||= host
+ end
+
+ def url(path)
+ if path =~ /^http/
+ path
+ else
+ (Capybara.app_host || "http://#{Capybara::Server.manual_host}:#{port}") + path.to_s
+ end
+ end
+end
View
2  spec/spec_helper.rb
@@ -12,6 +12,8 @@
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/rails'
+ require 'thinking_sphinx/test'
+ ThinkingSphinx::Test.init
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Please sign in to comment.
Something went wrong with that request. Please try again.