Skip to content

Commit

Permalink
Merge branch 'hotfix/view-smart-collections-error'
Browse files Browse the repository at this point in the history
  • Loading branch information
saberma committed Aug 15, 2012
2 parents f16b2da + 19bd763 commit 446525b
Show file tree
Hide file tree
Showing 22 changed files with 98 additions and 30 deletions.
Expand Up @@ -31,7 +31,7 @@ App.Views.Product.Show.Edit = Backbone.View.extend
product_type: @$("input[name='product_type']").val(),
vendor: @$("input[name='vendor']").val(),
tags_text: @$("input[name='tags_text']").val(),
collection_ids: _.map @$("input[name='product[collection_ids][]']:checked"), (input) ->
custom_collection_ids: _.map @$("input[name='product[custom_collection_ids][]']:checked"), (input) ->
input.value
},
success: (model, resp) ->
Expand Down
Expand Up @@ -11,7 +11,7 @@ App.Views.Product.Show.Show = Backbone.View.extend
attrs = _.clone @model.attributes
attrs['options'] = @model.options
attrs['tags'] = StringUtils.to_a attrs.tags_text
collections = _.map @model.attributes.collection_ids, (id) ->
collections = _.map @model.attributes.custom_collection_ids, (id) ->
collection =
id: id
title: $("#collection_#{id}").next('label').text()
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/products_controller.rb
Expand Up @@ -14,7 +14,7 @@ class Admin::ProductsController < Admin::AppController
expose(:product_json) do
product.to_json({
include: { options: { methods: [:value, :first, :last], except: [ :created_at, :updated_at ] },photos: {methods: :icon} },
methods: [:tags_text, :collection_ids],
methods: [:tags_text, :custom_collection_ids],
except: [ :created_at, :updated_at ]
})
end
Expand Down Expand Up @@ -103,7 +103,7 @@ def duplicate
new_product = product.dup
new_product.variants = product.variants.map(&:dup)
new_product.options = product.options.map(&:dup).each{|o| o.position = nil } # Fixed: #159 position不为空导致排序报错
new_product.collection_products = product.collection_products.map(&:dup)
new_product.custom_collection_products = product.custom_collection_products.map(&:dup)
new_product.tags_text = product.tags_text
new_product.update_attributes title: params[:new_title]
render json: {id: new_product.id}
Expand Down
15 changes: 8 additions & 7 deletions app/models/product.rb
Expand Up @@ -2,15 +2,16 @@
class Product < ActiveRecord::Base
include Models::Handle
belongs_to :shop
has_many :photos , dependent: :destroy , order: 'position asc'
has_many :variants , dependent: :destroy , class_name: 'ProductVariant' , order: 'position asc'
has_many :options , dependent: :destroy , class_name: 'ProductOption' , order: 'position asc'
has_many :collection_products, dependent: :destroy , class_name: 'CustomCollectionProduct'
has_many :collections , class_name: 'CustomCollection', through: :collection_products , source: :custom_collection
has_and_belongs_to_many :tags, order: 'id asc'
has_many :photos , dependent: :destroy , order: 'position asc'
has_many :variants , dependent: :destroy , class_name: 'ProductVariant' , order: 'position asc'
has_many :options , dependent: :destroy , class_name: 'ProductOption' , order: 'position asc'
has_many :custom_collection_products, dependent: :destroy , class_name: 'CustomCollectionProduct'
has_many :custom_collections , class_name: 'CustomCollection', through: :custom_collection_products , source: :custom_collection
has_many :smart_collection_products , dependent: :destroy , class_name: 'SmartCollectionProduct'
has_and_belongs_to_many :tags , order: 'id asc'
# 标签
attr_accessor :tags_text,:images
attr_accessible :handle, :title, :published, :body_html, :price, :product_type, :vendor, :tags_text, :images, :photos_attributes, :variants_attributes, :options_attributes, :collection_ids
attr_accessible :handle, :title, :published, :body_html, :price, :product_type, :vendor, :tags_text, :images, :photos_attributes, :variants_attributes, :options_attributes, :custom_collection_ids

scope :published, where(published: true)

Expand Down
8 changes: 7 additions & 1 deletion app/models/shop_theme.rb
Expand Up @@ -273,7 +273,7 @@ def asset_relative_path(asset) # s/files/1/theme/1/assets/checkout.css

begin # 当前theme所在URL
def asset_url(name) # s/files/1/theme/1/assets/checkout.css
"/#{self.asset_relative_path(name)}?#{File.mtime(self.asset_path(name)).to_i}"
"/#{self.asset_relative_path(name)}?#{self.asset_timestamp(name)}"
end
end

Expand Down Expand Up @@ -304,6 +304,12 @@ def asset_path(asset) # data/shops/1/themes/1/assets/checkout.css.liquid
asset_path_without_liquid asset
end

def asset_timestamp(name) # 1328060092
File.mtime(self.asset_path(name)).to_i
rescue
'' # file deleted
end

def asset_path_without_liquid(asset) # data/shops/1/themes/1/assets/favicon.ico
File.join path, 'assets', asset
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Expand Up @@ -3,7 +3,7 @@ class User < ActiveRecord::Base
extend ActiveHash::Associations::ActiveRecordExtensions

belongs_to :shop
has_many :articles , dependent: :destroy
has_many :articles
has_many :permissions , dependent: :destroy

# Include default devise modules. Others available are:
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/products/_collection.html.haml
@@ -1,3 +1,3 @@
%li.product-edit-collection
=check_box_tag 'product[collection_ids][]', collection.id, product.collections.include?(collection) || (collection.handle == 'frontpage' and collection.products.size.zero?), id: "collection_#{collection.id}"
=check_box_tag 'product[custom_collection_ids][]', collection.id, product.custom_collections.include?(collection) || (collection.handle == 'frontpage' and collection.products.size.zero?), id: "collection_#{collection.id}"
%label(for="collection_#{collection.id}")=collection.title
2 changes: 1 addition & 1 deletion app/views/admin/shop_theme_settings/show.html.haml
@@ -1,7 +1,7 @@
%h2#title 主题外观配置
#action-links
%ul
%li.template-editor=link_to "模板编辑器", theme_assets_path(shop.theme)
%li.template-editor=link_to "模板编辑器", theme_assets_path(theme)
=render "shared/noscript"
=render "shared/upgrade_ie"
%form#theme_settings_form(action="#" onsubmit="return false")
Expand Down
@@ -0,0 +1,9 @@
class RemoveDestroyedSmartCollectionProduct < ActiveRecord::Migration
def up
SmartCollection
SmartCollectionProduct.all.select{|smart_collection_product| smart_collection_product.product.nil? }.map(&:destroy)
end

def down
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120810144404) do
ActiveRecord::Schema.define(:version => 20120815032021) do

create_table "active_admin_comments", :force => true do |t|
t.integer "resource_id", :null => false
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/shop/collections_controller_spec.rb
Expand Up @@ -16,7 +16,7 @@

let(:smart_collection_low_price){ Factory(:smart_collection_low_price,handle: 'low_price', shop: shop)}

let(:iphone4) { Factory :iphone4, shop: shop, collections: [frontpage_collection] }
let(:iphone4) { Factory :iphone4, shop: shop, custom_collections: [frontpage_collection] }

before :each do
request.host = "#{shop.primary_domain.host}"
Expand Down Expand Up @@ -145,11 +145,11 @@

context '#show_with_tag' do # 结合标签过滤集合商品

let(:iphone4) { Factory :iphone4, shop: shop, collections: [frontpage_collection], tags_text: '手机, 游戏机, 带拍照功能' }
let(:iphone4) { Factory :iphone4, shop: shop, custom_collections: [frontpage_collection], tags_text: '手机, 游戏机, 带拍照功能' }

let(:psp) { Factory :psp, shop: shop, collections: [frontpage_collection], tags_text: '游戏机, 带拍照功能' }
let(:psp) { Factory :psp, shop: shop, custom_collections: [frontpage_collection], tags_text: '游戏机, 带拍照功能' }

let(:leika) { Factory :leika, shop: shop, collections: [frontpage_collection], tags_text: '相机, 带拍照功能' }
let(:leika) { Factory :leika, shop: shop, custom_collections: [frontpage_collection], tags_text: '相机, 带拍照功能' }

before do
[iphone4, psp]
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/shop/products_controller_spec.rb
Expand Up @@ -14,7 +14,7 @@

let(:frontpage_collection) { shop.custom_collections.where(handle: 'frontpage').first }

let(:iphone4) { Factory :iphone4, shop: shop, collections: [frontpage_collection] }
let(:iphone4) { Factory :iphone4, shop: shop, custom_collections: [frontpage_collection] }

before :each do
request.host = "#{shop.primary_domain.host}"
Expand Down
6 changes: 6 additions & 0 deletions spec/factories/smart_collections.rb
Expand Up @@ -6,6 +6,12 @@
body_html "低价商品"
end

factory :smart_collection_default, parent: :smart_collection do
rules_attributes [
{column: 'title', relation: 'equals', condition: ''}
]
end

factory :smart_collection_low_price, parent: :smart_collection do
rules_attributes [
{column: 'variants_price', relation: 'less_than', condition: 100}
Expand Down
4 changes: 2 additions & 2 deletions spec/liquids/collections_drop_spec.rb
Expand Up @@ -9,9 +9,9 @@

let(:smart_collection_low_price){ Factory(:smart_collection_low_price, shop: shop)}

let(:iphone4) { Factory :iphone4, shop: shop, collections: [frontpage_collection] }
let(:iphone4) { Factory :iphone4, shop: shop, custom_collections: [frontpage_collection] }

let(:psp) { Factory :psp, shop: shop, collections: [frontpage_collection] }
let(:psp) { Factory :psp, shop: shop, custom_collections: [frontpage_collection] }

let(:collections_drop) { CollectionsDrop.new(shop) }

Expand Down
2 changes: 1 addition & 1 deletion spec/liquids/paginate_filter_spec.rb
Expand Up @@ -9,7 +9,7 @@

let(:collection_drop) { CollectionDrop.new(collection) }

let(:iphone4) { Factory :iphone4, shop: shop, collections: [collection] }
let(:iphone4) { Factory :iphone4, shop: shop, custom_collections: [collection] }

context '#default_pagination' do

Expand Down
2 changes: 1 addition & 1 deletion spec/liquids/tag_filter_spec.rb
Expand Up @@ -58,7 +58,7 @@

let(:collection) { shop.custom_collections.where(handle: 'frontpage').first }

let(:iphone4) { Factory :iphone4, shop: shop, collections: [collection], tags_text: '智能 手机 待机时间长' }
let(:iphone4) { Factory :iphone4, shop: shop, custom_collections: [collection], tags_text: '智能 手机 待机时间长' }

it "should get link to tag url" do
variant = "{{ tag | link_to_tag: tag }}"
Expand Down
2 changes: 1 addition & 1 deletion spec/models/custom_collection_spec.rb
Expand Up @@ -36,7 +36,7 @@

let(:frontpage_collection) { shop.custom_collections.where(handle: 'frontpage').first }

let(:iphone4) { Factory :iphone4, shop: shop, collections: [frontpage_collection] }
let(:iphone4) { Factory :iphone4, shop: shop, custom_collections: [frontpage_collection] }

context 'create' do

Expand Down
19 changes: 19 additions & 0 deletions spec/models/shop_theme_spec.rb
Expand Up @@ -164,6 +164,25 @@

end

describe 'Asset' do

context 'path' do

context 'do not exist' do # 468

it 'should not raise error' do
theme = shop.themes.install theme_slate
expect do
theme.asset_url('deleted_image')
end.not_to raise_error
end

end

end

end

describe 'link path' do

# capistrano部署时会将current 链接到 release_path 目录,但FileUtils.ln_s不能指向release_path,旧有release_path会随时被删除
Expand Down
27 changes: 27 additions & 0 deletions spec/models/smart_collection_spec.rb
Expand Up @@ -5,6 +5,10 @@

let(:shop) { Factory(:user).shop }

let(:iphone4) { FactoryGirl.create :iphone4, shop: shop }

let(:smart_collection) { FactoryGirl.create :smart_collection_default, shop: shop }

context '#create' do

context '(without handle)' do
Expand All @@ -26,4 +30,27 @@

end

describe '#465' do

context 'product destroyed' do

before do
iphone4
smart_collection
end

describe 'collection_products' do

it "should be destroy" do
expect do
iphone4.destroy
end.to change(SmartCollectionProduct, :count).by(-1)
end

end

end

end

end
2 changes: 1 addition & 1 deletion spec/requests/shop/shops_searches_spec.rb
Expand Up @@ -8,7 +8,7 @@

let(:frontpage_collection) { shop.custom_collections.where(handle: 'frontpage').first }

let(:iphone4) { Factory :iphone4, shop: shop, collections: [frontpage_collection] }
let(:iphone4) { Factory :iphone4, shop: shop, custom_collections: [frontpage_collection] }

# 查询(需要启动全文检索服务) RAILS_ENV=test bundle exec rake sunspot:solr:run
describe "GET /search", searchable: true do
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/shop/shops_spec.rb
Expand Up @@ -18,7 +18,7 @@

let(:frontpage_collection) { shop.custom_collections.where(handle: 'frontpage').first }

let(:iphone4) { Factory :iphone4, shop: shop, collections: [frontpage_collection] }
let(:iphone4) { Factory :iphone4, shop: shop, custom_collections: [frontpage_collection] }

let(:payment) { Factory :payment, shop: shop }

Expand Down
4 changes: 2 additions & 2 deletions spec/requests/smart_collections_spec.rb
Expand Up @@ -47,8 +47,8 @@
context '#465' do

before do
psp.destroy
iphone4 # id 不为 1
psp.destroy # 保证 id=1 的记录不存在
iphone4 # id = 2
smart_collection # new(product_id: product) product_id 都会被置为 1;要使用 new(product_id: product.id)
end

Expand Down

0 comments on commit 446525b

Please sign in to comment.