Browse files

fixed #194.

  • Loading branch information...
1 parent b315955 commit a96c69242db855a1e5a27595c1da5a6d9a0a07fe @saberma committed Oct 18, 2011
View
1 .rspec
@@ -1 +1,2 @@
--colour
+--drb
View
2 app/assets/javascripts/backbone/controllers/products.js.coffee
@@ -45,7 +45,7 @@ App.Controllers.Products = Backbone.Controller.extend
Utils.Tag.init 'product_tags_text'
#显示上传图片的form
- $('.show-upload-link').click ->
+ $('#upload-label .show-upload-link').click ->
$(this).hide()
$("#upload-area").toggle()
View
3 app/controllers/admin/photos_controller.rb
@@ -14,7 +14,8 @@ def destroy
end
def create
- photo.position = photos.blank? ? 0 : photos.last.position + 1
+ position = photos.blank? ? 0 : photos.last.position + 1 # 注意:一调用photo,则photos就包含photo对象了
+ photo.position = position
photo.save
flash[:notice] = notice_msg
redirect_to product_path(product)
View
2 app/views/admin/photos/destroy.js.haml
@@ -1,2 +1,2 @@
-$("#image-show-area").html("#{escape_javascript(render partial:'products/upload_photos',locals:{product: product})}" );
+$("#image-show-area").html("#{escape_javascript(render partial:'admin/products/upload_photos',locals:{product: product})}" );
msg('#{flash[:notice]}');
View
BIN spec/factories/data/products/iphone4.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
30 spec/requests/products_spec.rb
@@ -410,6 +410,7 @@
end
+ ##### 查看 #####
describe "GET /products/id" do
context "(with two products)" do
@@ -419,6 +420,35 @@
psp
end
+ describe '#photo' do
+
+ before :each do
+ visit product_path(iphone4)
+ end
+
+ it 'should be upload' do
+ find('#upload-label .show-upload-link').click # 上传按钮
+ attach_file 'add-file', Rails.root.join('spec', 'factories', 'data', 'products', 'iphone4.jpg')
+ page.should have_content('新增成功!')
+ within '#image_list' do
+ page.should have_xpath('./li[1]') # 显示图片
+ end
+ end
+
+ it 'should be destroy', focus: true do
+ find('#upload-label .show-upload-link').click # 上传按钮
+ attach_file 'add-file', Rails.root.join('spec', 'factories', 'data', 'products', 'iphone4.jpg')
+ page.execute_script("window.confirm = function(msg) { return true; }")
+ page.should have_css('#image_list')
+ within '#image_list' do
+ find('.image-delete').click
+ end
+ page.should have_content('删除成功!')
+ page.should have_no_css('#image_list')
+ end
+
+ end
+
describe '#edit' do
it 'should save title' do
View
1 spec/spec_helper.rb
@@ -12,6 +12,7 @@
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/rails'
+ Capybara.default_wait_time = 5
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.

0 comments on commit a96c692

Please sign in to comment.