fix theme assets tests

This commit is contained in:
Didier Lafforgue 2012-02-28 11:25:51 +01:00
parent 520b68104b
commit a2308787f1
6 changed files with 38 additions and 22 deletions

View File

@ -49,7 +49,7 @@ class Locomotive.Views.ThemeAssets.FormView extends Locomotive.Views.Shared.Form
@$('input#theme_asset_performing_plain_text').val(false)
else
@$('#file-selector').slideUp 'normal', =>
@$('#text-selector').slideDown()
@$('#text-selector').slideDown 'normal', => @editor.refresh()
@model.set(performing_plain_text: true)
@$('#theme_asset_performing_plain_text').val(true)

View File

@ -4,6 +4,13 @@ class Locomotive.Views.ThemeAssets.EditView extends Locomotive.Views.ThemeAssets
save: (event) ->
@save_in_ajax event, on_success: (response, xhr) =>
window.response = response
window.xhr = xhr
help = @$('.inner > p.help')
help.find('b').html(response.dimensions)
help.find('a').html(response.url).attr('href', response.url)
help.find('a').html(response.url).attr('href', response.url)
window.editor = @editor
if response.plain_text?
@editor.setValue response.plain_text

View File

@ -99,6 +99,8 @@ module Locomotive
:tempfile => StringIO.new(sanitized_source),
:filename => "#{self.plain_text_name}.#{self.stylesheet? ? 'css' : 'js'}"
})
@plain_text = sanitized_source # no need to reset the plain_text instance variable to have the last version
end
def to_liquid
@ -106,7 +108,7 @@ module Locomotive
end
def as_json(options = {})
Locomotive::ThemeAssetPresenter.new(self).as_json
Locomotive::ThemeAssetPresenter.new(self, options).as_json
end
def self.all_grouped_by_folder(site)

View File

@ -1,7 +1,7 @@
module Locomotive
class ThemeAssetPresenter < BasePresenter
delegate :content_type, :folder, :to => :source
delegate :content_type, :folder, :plain_text, :to => :source
def local_path
self.source.local_path(true)
@ -24,7 +24,16 @@ module Locomotive
end
def included_methods
super + %w(content_type folder local_path url size dimensions updated_at)
default_list = %w(content_type folder local_path url size dimensions updated_at)
default_list += %w(plain_text) if plain_text?
super + default_list
end
private
def plain_text?
# FIXME: self.options contains all the options passed by the responder
self.options[:template] == 'update' && self.source.errors.empty? && self.source.stylesheet_or_javascript?
end
end

View File

@ -35,12 +35,12 @@ Scenario: Updating a stylesheet
Given a stylesheet asset named "application"
When I go to theme assets
And I follow "application.css"
And I fill in "theme_asset[plain_text]" with "Lorem ipsum (updated)"
And I change the theme asset code to "Lorem ipsum (updated)"
And I press "Save"
Then I should see "File was successfully updated."
And I should see "Editing application.css"
And I should see "application.css"
And I should see "Lorem ipsum (updated)" as theme asset code
And I should see "Lorem ipsum (updated)" as the theme asset code
Scenario: Uploading a javascript
When I go to theme assets
@ -52,15 +52,14 @@ Scenario: Uploading a javascript
And I should see "Code"
And I should see "javascripts/test/application.js"
# @javascript
# Scenario: Updating a javascript
# Given a javascript asset named "application"
# When I go to theme assets
# And I follow "application.js"
# And I change the asset code with
# And I fill in "theme_asset[plain_text]" with "Lorem ipsum (updated)"
# And I press "Save"
# Then I should see "File was successfully updated."
@javascript
Scenario: Updating a javascript
Given a javascript asset named "application"
When I go to theme assets
And I follow "application.js"
And I change the theme asset code to "Lorem ipsum (updated)"
And I press "Save"
Then I should see "File was successfully updated."
Scenario: Uploading an image which already exists
When I go to theme assets

View File

@ -34,13 +34,12 @@ end
# other stuff
# change the template
# When /^I change the theme asset code to "([^"]*)"$/ do |page_template|
# page.evaluate_script "window.application_view.view.model.set({ 'raw_template': '#{page_template}' })"
# end
When /^I change the theme asset code to "([^"]*)"$/ do |plain_text|
page.evaluate_script "window.application_view.view.editor.setValue('#{plain_text}')"
end
Then /^I should see "([^"]*)" as theme asset code$/ do |code|
find(:css, "#theme_asset_plain_text").text.should == code
Then /^I should see "([^"]*)" as the theme asset code$/ do |code|
find(:css, "#theme_asset_plain_text").value.should == code
end
Then /^I should see a delete image button$/ do