Skip to content

Commit

Permalink
fixed rspec error.
Browse files Browse the repository at this point in the history
  • Loading branch information
saberma committed Feb 2, 2012
1 parent e24b1a9 commit 0749017
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/shop.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def plan_unlimited?
end end


def storage # 已占用的容量(如要支持windows可修改为循环获取目录大小) def storage # 已占用的容量(如要支持windows可修改为循环获取目录大小)
Rails.cache.fetch(self.storage_cache_key, expires_in: 5.minutes) do smart_fetch(self.storage_cache_key, expires_in: 5.minutes) do
`du -sm #{self.path} | awk '{print $1}'`.to_i # 以M为单位 `du -sm #{self.path} | awk '{print $1}'`.to_i # 以M为单位
end end
end end
Expand Down
10 changes: 10 additions & 0 deletions config/initializers/add_method_to_ruby.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ def as_json(options={})


Carmen.default_locale = :cn Carmen.default_locale = :cn


# 修正:DEPRECATION WARNING: Setting :expires_in on read has been deprecated in favor of setting it on write
def smart_fetch(name, options = {}, &blk)
in_cache = Rails.cache.fetch(name)
return in_cache if in_cache
if block_given?
val = yield
Rails.cache.write(name, val, options)
return val
end
end


#增加subdomain属性 #增加subdomain属性
#rails 3.1默认支持subdomain和domain #rails 3.1默认支持subdomain和domain
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/admin/assets_controller_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@


let(:file_path) { Rails.root.join('spec', 'factories', 'data', 'themes') } let(:file_path) { Rails.root.join('spec', 'factories', 'data', 'themes') }


before do
post :upload, key: 'assets/product.jpg', theme_id: theme.id, id: 0, qqfile: Rack::Test::UploadedFile.new(File.join(file_path, 'product.jpg'))
end

describe 'ie' do # 支持ie浏览器上传 describe 'ie' do # 支持ie浏览器上传


it 'should be success' do it 'should be success' do
post :upload, key: 'assets/product.jpg', theme_id: theme.id, id: 0, qqfile: Rack::Test::UploadedFile.new(File.join(file_path, 'product.jpg'))
response.should be_success response.should be_success
response.content_type.should eql 'text/html' # context_type不为'text/html'时,ie会将json作为文件下载 response.content_type.should eql 'text/html' # context_type不为'text/html'时,ie会将json作为文件下载
end end
Expand All @@ -51,7 +48,10 @@


before { Rails.cache.write(shop.storage_cache_key, 101) } before { Rails.cache.write(shop.storage_cache_key, 101) }


after { Rails.cache.delete(shop.storage_cache_key) }

it 'should be fail' do it 'should be fail' do
post :upload, key: 'assets/product.jpg', theme_id: theme.id, id: 0, qqfile: Rack::Test::UploadedFile.new(File.join(file_path, 'product.jpg'))
JSON(response.body)['storage_full'].should be_true JSON(response.body)['storage_full'].should be_true
end end


Expand Down
8 changes: 7 additions & 1 deletion spec/controllers/admin/themes_controller_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
shop.themes.install theme_dark # 原主题会置为[未发布]状态 shop.themes.install theme_dark # 原主题会置为[未发布]状态
end end


it 'should be duplicate' do it 'should be success' do
expect do expect do
put :duplicate, id: theme.id put :duplicate, id: theme.id
JSON(response.body)['shop_theme']['role'].should eql 'unpublished' JSON(response.body)['shop_theme']['role'].should eql 'unpublished'
Expand All @@ -50,6 +50,8 @@


before { Rails.cache.write(shop.storage_cache_key, 101) } before { Rails.cache.write(shop.storage_cache_key, 101) }


after { Rails.cache.delete(shop.storage_cache_key) }

it 'should be fail' do it 'should be fail' do
put :duplicate, id: theme.id put :duplicate, id: theme.id
JSON(response.body)['storage_full'].should eql true JSON(response.body)['storage_full'].should eql true
Expand Down Expand Up @@ -127,6 +129,8 @@


before { Rails.cache.write(shop.storage_cache_key, 101) } before { Rails.cache.write(shop.storage_cache_key, 101) }


after { Rails.cache.delete(shop.storage_cache_key) }

it 'should be fail' do it 'should be fail' do
raw_attach_file File.join(zip_path, 'woodland-missing-templates-index.zip') raw_attach_file File.join(zip_path, 'woodland-missing-templates-index.zip')
post :upload, qqfile: 'woodland.zip' post :upload, qqfile: 'woodland.zip'
Expand Down Expand Up @@ -169,6 +173,8 @@


before { Rails.cache.write(shop.storage_cache_key, 101) } before { Rails.cache.write(shop.storage_cache_key, 101) }


after { Rails.cache.delete(shop.storage_cache_key) }

it 'should be fail' do it 'should be fail' do
post :install, handle: theme_slate.handle, style_handle: theme_slate.style_handle post :install, handle: theme_slate.handle, style_handle: theme_slate.style_handle
JSON(response.body)['error'].should_not be_blank JSON(response.body)['error'].should_not be_blank
Expand Down

0 comments on commit 0749017

Please sign in to comment.