zendesk_apps_support 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,9 +27,11 @@ en:
27
27
  invalid_hidden_parameter:
28
28
  one: ! '%{invalid_params} is set to hidden and cannot be required.'
29
29
  other: ! '%{invalid_params} are set to hidden and cannot be required.'
30
- parameters_not_an_array: App Parameters must be an array.
30
+ parameters_not_an_array: App parameters must be an array.
31
+ duplicate_parameters: ! 'Duplicate app parameters defined: %{duplicate_parameters}'
31
32
  translation:
32
33
  invalid_locale: ! '%{file} is not a valid locale. Only two- and three-letter
33
34
  ISO 639 language codes are allowed.'
34
35
  not_json: ! '%{file} is not valid JSON. %{errors}'
35
36
  not_json_object: ! '%{file} is not a JSON object.'
37
+ stylesheet_error: ! 'Sass error: %{sass_error}'
@@ -67,6 +67,10 @@ parts:
67
67
  key: "txt.apps.admin.error.app_build.parameters_not_an_array"
68
68
  title: "App builder job: app parameters must be an array"
69
69
  value: "App parameters must be an array."
70
+ - translation:
71
+ key: "txt.apps.admin.error.app_build.duplicate_parameters"
72
+ title: "App builder job: duplicate parameters error"
73
+ value: "Duplicate app parameters defined: %{duplicate_parameters}"
70
74
  - translation:
71
75
  key: "txt.apps.admin.error.app_build.translation.invalid_locale"
72
76
  title: "App builder job: invalid locale file name"
@@ -79,3 +83,7 @@ parts:
79
83
  key: "txt.apps.admin.error.app_build.translation.not_json_object"
80
84
  title: "App builder job: translation file is not a JSON object"
81
85
  value: "%{file} is not a JSON object."
86
+ - translation:
87
+ key: "txt.apps.admin.error.app_build.stylesheet_error"
88
+ title: "App builder job: invalid stylesheet syntax"
89
+ value: "Sass error: %{sass_error}"
@@ -16,5 +16,6 @@ module ZendeskAppsSupport
16
16
  autoload :Templates, 'zendesk_apps_support/validations/templates'
17
17
  autoload :Translations, 'zendesk_apps_support/validations/translations'
18
18
  autoload :JSHintValidationError, 'zendesk_apps_support/validations/validation_error'
19
+ autoload :Stylesheets, 'zendesk_apps_support/validations/stylesheets'
19
20
  end
20
21
  end
@@ -18,7 +18,8 @@ module ZendeskAppsSupport
18
18
  Validations::Manifest.call(self) +
19
19
  Validations::Source.call(self) +
20
20
  Validations::Templates.call(self) +
21
- Validations::Translations.call(self)
21
+ Validations::Translations.call(self) +
22
+ Validations::Stylesheets.call(self)
22
23
  end
23
24
 
24
25
  def files
@@ -65,11 +66,14 @@ module ZendeskAppsSupport
65
66
  )
66
67
  end
67
68
 
69
+ def customer_css
70
+ css_file = File.join(root, 'app.css')
71
+ customer_css = File.exist?(css_file) ? File.read(css_file) : ""
72
+ end
73
+
68
74
  private
69
75
 
70
76
  def compiled_templates(app_id, asset_url_prefix)
71
- css_file = File.join(root, "app.css")
72
- customer_css = File.exist?(css_file) ? File.read(css_file) : ""
73
77
  compiled_css = ZendeskAppsSupport::StylesheetCompiler.new(DEFAULT_SCSS + customer_css, app_id, asset_url_prefix).compile
74
78
 
75
79
  templates = begin
@@ -19,7 +19,7 @@ module ZendeskAppsSupport
19
19
  errors << missing_keys_error(manifest)
20
20
  errors << default_locale_error(manifest, package)
21
21
  errors << invalid_location_error(manifest)
22
- errors << parameters_must_be_an_array(manifest)
22
+ errors << parameters_error(manifest)
23
23
  errors << invalid_hidden_parameter_error(manifest)
24
24
  errors.compact!
25
25
  end
@@ -29,11 +29,17 @@ module ZendeskAppsSupport
29
29
 
30
30
  private
31
31
 
32
- def parameters_must_be_an_array(manifest)
32
+ def parameters_error(manifest)
33
33
  return unless manifest['parameters']
34
34
 
35
35
  unless manifest['parameters'].kind_of?(Array)
36
- ValidationError.new(:parameters_not_an_array)
36
+ return ValidationError.new(:parameters_not_an_array)
37
+ end
38
+
39
+ para_names = manifest['parameters'].collect{|para| para['name']}
40
+ duplicate_parameters = para_names.select {|name| para_names.count(name) > 1}.uniq
41
+ unless duplicate_parameters.empty?
42
+ return ValidationError.new(:duplicate_parameters, :duplicate_parameters => duplicate_parameters)
37
43
  end
38
44
  end
39
45
 
@@ -0,0 +1,32 @@
1
+ require 'zendesk_apps_support/stylesheet_compiler'
2
+
3
+ module ZendeskAppsSupport
4
+ module Validations
5
+ module Stylesheets
6
+
7
+ class << self
8
+
9
+ def call(package)
10
+ if css_error = validate_styles(package.customer_css)
11
+ [css_error]
12
+ else
13
+ []
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def validate_styles(css)
20
+ compiler = ZendeskAppsSupport::StylesheetCompiler.new(css, nil, nil)
21
+ begin
22
+ compiler.compile
23
+ rescue Sass::SyntaxError => e
24
+ return ValidationError.new(:stylesheet_error, :sass_error => e.message)
25
+ end
26
+ nil
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -12,6 +12,12 @@ describe ZendeskAppsSupport::Validations::Manifest do
12
12
  valid_fields.merge(overrides)
13
13
  end
14
14
 
15
+ def create_package(parameter_hash)
16
+ params = default_required_params(parameter_hash)
17
+ manifest = mock('AppFile', :relative_path => 'manifest.json', :read => JSON.dump(params))
18
+ mock('Package', :files => [manifest])
19
+ end
20
+
15
21
  it 'should have an error when manifest.json is missing' do
16
22
  files = [mock('AppFile', :relative_path => 'abc.json')]
17
23
  package = mock('Package', :files => files)
@@ -84,7 +90,7 @@ describe ZendeskAppsSupport::Validations::Manifest do
84
90
  errors.first().to_s.should =~ /^manifest is not proper JSON/
85
91
  end
86
92
 
87
- context 'with invalid parameter type' do
93
+ context 'with invalid parameters' do
88
94
 
89
95
  before do
90
96
  ZendeskAppsSupport::Validations::Manifest.stub(:default_locale_error)
@@ -99,12 +105,8 @@ describe ZendeskAppsSupport::Validations::Manifest do
99
105
  }
100
106
  }
101
107
 
102
- params = default_required_params(parameter_hash)
103
- manifest = mock('AppFile', :relative_path => 'manifest.json', :read => JSON.dump(params))
104
- package = mock('Package', :files => [manifest])
105
-
106
- errors = ZendeskAppsSupport::Validations::Manifest.call(package)
107
- errors.map(&:to_s).should == ['App Parameters must be an array.']
108
+ errors = ZendeskAppsSupport::Validations::Manifest.call(create_package(parameter_hash))
109
+ errors.map(&:to_s).should == ['App parameters must be an array.']
108
110
  end
109
111
 
110
112
  it "doesn't have an error with an array of app parameters" do
@@ -115,20 +117,31 @@ describe ZendeskAppsSupport::Validations::Manifest do
115
117
  }]
116
118
  }
117
119
 
118
- params = default_required_params(parameter_hash)
119
- manifest = mock('AppFile', :relative_path => 'manifest.json', :read => JSON.dump(params))
120
- package = mock('Package', :files => [manifest])
121
-
122
- errors = ZendeskAppsSupport::Validations::Manifest.call(package)
120
+ errors = ZendeskAppsSupport::Validations::Manifest.call(create_package(parameter_hash))
123
121
  errors.should be_empty
124
122
  end
125
123
 
126
124
  it 'behaves when the manifest does not have parameters' do
127
- manifest = mock('AppFile', :relative_path => 'manifest.json', :read => JSON.dump(default_required_params))
128
- package = mock('Package', :files => [manifest])
129
-
130
- errors = ZendeskAppsSupport::Validations::Manifest.call(package)
125
+ errors = ZendeskAppsSupport::Validations::Manifest.call(create_package(default_required_params))
131
126
  errors.should be_empty
132
127
  end
128
+
129
+ it 'shows error when duplicate parameters are defined' do
130
+ parameter_hash = {
131
+ 'parameters' => [
132
+ {
133
+ 'name' => 'url',
134
+ 'type' => 'string'
135
+ },
136
+ {
137
+ 'name' => 'url',
138
+ 'type' => 'string'
139
+ }
140
+ ]
141
+ }
142
+
143
+ errors = ZendeskAppsSupport::Validations::Manifest.call(create_package(parameter_hash))
144
+ errors.map(&:to_s).should == ['Duplicate app parameters defined: ["url"]']
145
+ end
133
146
  end
134
147
  end
@@ -0,0 +1,34 @@
1
+ require 'zendesk_apps_support'
2
+
3
+ describe ZendeskAppsSupport::Validations::Stylesheets do
4
+ it 'does not return errors if there is no custom css' do
5
+
6
+ package = stub(:customer_css => "")
7
+ ZendeskAppsSupport::Validations::Stylesheets.call(package).should be_empty
8
+ end
9
+
10
+ it 'does not return errors for valid css' do
11
+ valid_css = <<-CSS
12
+ .my-class {
13
+ border: solid 1px black;
14
+ }
15
+ CSS
16
+ package = stub(:customer_css => valid_css)
17
+
18
+ errors = ZendeskAppsSupport::Validations::Stylesheets.call(package)
19
+ errors.should be_empty
20
+ end
21
+
22
+ it 'returns style sheet validation error for invalid css' do
23
+ invalid_css = <<-CSS
24
+ .my-class {
25
+ border: }
26
+ }
27
+ CSS
28
+ package = stub(:customer_css => invalid_css)
29
+
30
+ errors = ZendeskAppsSupport::Validations::Stylesheets.call(package)
31
+ errors.count.should == 1
32
+ errors.first.to_s.should match /Sass error: Invalid CSS after.*/
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk_apps_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-04-22 00:00:00.000000000 Z
14
+ date: 2013-05-16 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: i18n
@@ -143,6 +143,7 @@ files:
143
143
  - lib/zendesk_apps_support/stylesheet_compiler.rb
144
144
  - lib/zendesk_apps_support/validations/manifest.rb
145
145
  - lib/zendesk_apps_support/validations/source.rb
146
+ - lib/zendesk_apps_support/validations/stylesheets.rb
146
147
  - lib/zendesk_apps_support/validations/templates.rb
147
148
  - lib/zendesk_apps_support/validations/translations.rb
148
149
  - lib/zendesk_apps_support/validations/validation_error.rb
@@ -165,6 +166,7 @@ files:
165
166
  - spec/validations/jshint_error_spec.rb
166
167
  - spec/validations/manifest_spec.rb
167
168
  - spec/validations/source_spec.rb
169
+ - spec/validations/stylesheets_spec.rb
168
170
  - spec/validations/templates_spec.rb
169
171
  - spec/validations/translations_spec.rb
170
172
  - spec/validations/validation_serialization_spec.rb
@@ -208,6 +210,7 @@ test_files:
208
210
  - spec/validations/jshint_error_spec.rb
209
211
  - spec/validations/manifest_spec.rb
210
212
  - spec/validations/source_spec.rb
213
+ - spec/validations/stylesheets_spec.rb
211
214
  - spec/validations/templates_spec.rb
212
215
  - spec/validations/translations_spec.rb
213
216
  - spec/validations/validation_serialization_spec.rb