zendesk_apps_support 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/LICENSE +13 -0
  2. data/README.md +3 -0
  3. data/config/locales/en.yml +26 -0
  4. data/config/locales/translations/zendesk_apps_support.yml +54 -0
  5. data/lib/zendesk_apps_support.rb +20 -0
  6. data/lib/zendesk_apps_support/app_file.rb +42 -0
  7. data/lib/zendesk_apps_support/app_version.rb +68 -0
  8. data/lib/zendesk_apps_support/default_styles.scss +21 -0
  9. data/lib/zendesk_apps_support/engine.rb +11 -0
  10. data/lib/zendesk_apps_support/i18n.rb +28 -0
  11. data/lib/zendesk_apps_support/package.rb +100 -0
  12. data/lib/zendesk_apps_support/sass_functions.rb +22 -0
  13. data/lib/zendesk_apps_support/src.js.erb +24 -0
  14. data/lib/zendesk_apps_support/stylesheet_compiler.rb +25 -0
  15. data/lib/zendesk_apps_support/validations/manifest.rb +48 -0
  16. data/lib/zendesk_apps_support/validations/source.rb +43 -0
  17. data/lib/zendesk_apps_support/validations/templates.rb +20 -0
  18. data/lib/zendesk_apps_support/validations/translations.rb +38 -0
  19. data/lib/zendesk_apps_support/validations/validation_error.rb +103 -0
  20. data/spec/app/app.css +6 -0
  21. data/spec/app/app.js +12 -0
  22. data/spec/app/assets/logo-small.png +0 -0
  23. data/spec/app/assets/logo.png +0 -0
  24. data/spec/app/manifest.json +11 -0
  25. data/spec/app/templates/layout.hdbs +11 -0
  26. data/spec/app/translations/en.json +5 -0
  27. data/spec/app_file_spec.rb +27 -0
  28. data/spec/app_version_spec.rb +61 -0
  29. data/spec/i18n_spec.rb +22 -0
  30. data/spec/package_spec.rb +84 -0
  31. data/spec/validations/jshint_error_spec.rb +17 -0
  32. data/spec/validations/manifest_spec.rb +39 -0
  33. data/spec/validations/source_spec.rb +21 -0
  34. data/spec/validations/templates_spec.rb +13 -0
  35. data/spec/validations/translations_spec.rb +58 -0
  36. data/spec/validations/validation_serialization_spec.rb +96 -0
  37. metadata +212 -0
@@ -0,0 +1,84 @@
1
+ require 'zendesk_apps_support'
2
+
3
+ describe ZendeskAppsSupport::Package do
4
+
5
+ before do
6
+ @package = ZendeskAppsSupport::Package.new('spec/app')
7
+ end
8
+
9
+ describe 'files' do
10
+ it 'should return all the files within the app folder excluding files in tmp folder' do
11
+ @package.files.map(&:relative_path).should == %w(app.css app.js assets/logo-small.png assets/logo.png manifest.json templates/layout.hdbs translations/en.json)
12
+ end
13
+ end
14
+
15
+ describe 'template_files' do
16
+ it 'should return all the files in the templates folder within the app folder' do
17
+ @package.template_files.map(&:relative_path).should == %w(templates/layout.hdbs)
18
+ end
19
+ end
20
+
21
+ describe 'translation_files' do
22
+ it 'should return all the files in the translations folder within the app folder' do
23
+ @package.translation_files.map(&:relative_path).should == %w(translations/en.json)
24
+ end
25
+ end
26
+
27
+ describe 'manifest_json' do
28
+ it 'should return manifest json' do
29
+ manifest = @package.manifest_json
30
+ manifest[:name].should == 'ABC'
31
+ manifest[:author][:name].should == 'John Smith'
32
+ manifest[:author][:email].should == 'john@example.com'
33
+ manifest[:defaultLocale].should == 'en'
34
+ manifest[:private].should == true
35
+ manifest[:location].should == 'ticket_sidebar'
36
+ manifest[:frameworkVersion].should == '0.5'
37
+ end
38
+ end
39
+
40
+ describe 'readified_js' do
41
+ it 'should generate js ready for installation' do
42
+ js = @package.readified_js(nil, 0, 'http://localhost:4567')
43
+ expected =<<HERE
44
+ (function() {
45
+ with( require('apps/framework/app_scope') ) {
46
+
47
+ var source = (function() {
48
+
49
+ return {
50
+ events: {
51
+ 'app.activated':'doSomething'
52
+ },
53
+
54
+ doSomething: function() {
55
+ }
56
+ };
57
+
58
+ }());
59
+ ;
60
+
61
+ ZendeskApps["ABC"] = ZendeskApps.defineApp(source)
62
+ .reopenClass({ location: "ticket_sidebar" })
63
+ .reopen({
64
+ assetUrlPrefix: "http://localhost:4567",
65
+ appClassName: "app-0",
66
+ author: {
67
+ name: "John Smith",
68
+ email: "john@example.com"
69
+ },
70
+ translations: {"app":{\"name\":\"Buddha Machine\"}},
71
+ templates: {"layout":"<style>\\n.app-0 header {\\n border-bottom: 1px dotted #cccccc;\\n margin-bottom: 12px; }\\n .app-0 header h3 {\\n line-height: 30px; }\\n .app-0 header hr {\\n margin-top: 0; }\\n .app-0 header .logo {\\n background: transparent url(\\"http://localhost:4567/logo-small.png\\") no-repeat;\\n background-size: 25px 25px;\\n float: right;\\n height: 25px;\\n width: 25px; }\\n .app-0 header .app-warning-icon {\\n cursor: pointer;\\n float: right;\\n margin-left: 2px;\\n padding: 5px; }\\n.app-0 h3 {\\n font-size: 14px; }\\n.app-0 footer {\\n background: none;\\n border: 0; }\\n.app-0 h1 {\\n color: red; }\\n .app-0 h1 span {\\n color: green; }\\n</style>\\n<header>\\n <span class=\\"logo\\"/>\\n <h3>{{setting \\"name\\"}}</h3>\\n</header>\\n<section data-main/>\\n<footer>\\n <a href=\\"mailto:{{author.email}}\\">\\n {{author.name}}\\n </a>\\n</footer>\\n</div>"},
72
+ frameworkVersion: "0.5"
73
+ });
74
+
75
+ }
76
+
77
+ ZendeskApps["ABC"].install({"id": 0, "app_id": 0, "settings": {\"title\":\"ABC\"}});
78
+
79
+ }());
80
+ HERE
81
+ js.should == expected
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,17 @@
1
+ require 'zendesk_apps_support'
2
+
3
+ describe ZendeskAppsSupport::Validations::JSHintValidationError do
4
+
5
+ let(:filename) { 'foo.js' }
6
+
7
+ context 'with nil errors' do
8
+
9
+ let(:errors) { [ nil, { 'line' => 12, 'reason' => 'eval is evil' }, nil ] }
10
+ let(:error) { ZendeskAppsSupport::Validations::JSHintValidationError.new(filename, errors) }
11
+
12
+ it 'ignores nil errors' do
13
+ error.to_s.should =~ /eval is evil/
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,39 @@
1
+ require 'zendesk_apps_support'
2
+ require 'json'
3
+
4
+ describe ZendeskAppsSupport::Validations::Manifest do
5
+
6
+ it 'should have an error when manifest.json is missing' do
7
+ files = [mock('AppFile', :relative_path => 'abc.json')]
8
+ package = mock('Package', :files => files)
9
+ errors = ZendeskAppsSupport::Validations::Manifest.call(package)
10
+
11
+ errors.first().to_s.should eql 'Could not find manifest.json'
12
+ end
13
+
14
+ it 'should have an error when required field is missing' do
15
+ manifest = mock('AppFile', :relative_path => 'manifest.json', :read => "{}")
16
+ package = mock('Package', :files => [manifest])
17
+ errors = ZendeskAppsSupport::Validations::Manifest.call(package)
18
+
19
+ errors.first().to_s.should eql 'Missing required fields in manifest: author, defaultLocale, location, frameworkVersion'
20
+ end
21
+
22
+ it 'should have an error when the defaultLocale is invalid' do
23
+ manifest = { 'defaultLocale' => 'pt-BR' }
24
+ manifest_file = mock('AppFile', :relative_path => 'manifest.json', :read => JSON.dump(manifest))
25
+ package = mock('Package', :files => [manifest_file])
26
+ errors = ZendeskAppsSupport::Validations::Manifest.call(package)
27
+
28
+ locale_error = errors.find { |e| e.to_s =~ /defaultLocale/ }
29
+ locale_error.should_not be_nil
30
+ end
31
+
32
+ it 'should have an error when manifest is not a valid json' do
33
+ manifest = mock('AppFile', :relative_path => 'manifest.json', :read => "}")
34
+ package = mock('Package', :files => [manifest])
35
+ errors = ZendeskAppsSupport::Validations::Manifest.call(package)
36
+
37
+ errors.first().to_s.should =~ /^manifest is not proper JSON/
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ require 'zendesk_apps_support'
2
+
3
+ describe ZendeskAppsSupport::Validations::Source do
4
+
5
+ it 'should have an error when app.js is missing' do
6
+ files = [mock('AppFile', :relative_path => 'abc.js')]
7
+ package = mock('Package', :files => files)
8
+ errors = ZendeskAppsSupport::Validations::Source.call(package)
9
+
10
+ errors.first().to_s.should eql 'Could not find app.js'
11
+ end
12
+
13
+ it 'should have a jslint error when missing semicolon' do
14
+ source = mock('AppFile', :relative_path => 'app.js', :read => "var a = 1")
15
+ package = mock('Package', :files => [source])
16
+ errors = ZendeskAppsSupport::Validations::Source.call(package)
17
+
18
+ errors.first().to_s.should eql "JSHint error in app.js: \n L1: Missing semicolon."
19
+ end
20
+
21
+ end
@@ -0,0 +1,13 @@
1
+ require 'zendesk_apps_support'
2
+
3
+ describe ZendeskAppsSupport::Validations::Templates do
4
+
5
+ it 'should have a jslint error when missing semicolon' do
6
+ template = mock('AppFile', :relative_path => 'layout.hdbs', :read => "<style>")
7
+ package = mock('Package', :template_files => [template])
8
+ errors = ZendeskAppsSupport::Validations::Templates.call(package)
9
+
10
+ errors.first().to_s.should eql "<style> tag in layout.hdbs. Use an app.css file instead."
11
+ end
12
+
13
+ end
@@ -0,0 +1,58 @@
1
+ require 'zendesk_apps_support'
2
+ require 'json'
3
+
4
+ describe ZendeskAppsSupport::Validations::Translations do
5
+
6
+ let(:package) { mock('Package', :files => translation_files) }
7
+ subject { ZendeskAppsSupport::Validations::Translations.call(package) }
8
+
9
+ context 'when there are no translation files' do
10
+ let(:translation_files) { [] }
11
+ it 'should be valid' do
12
+ subject.should be_empty
13
+ end
14
+ end
15
+
16
+ context 'when there is file with invalid JSON' do
17
+ let(:translation_files) do
18
+ [ mock('AppFile', :relative_path => 'translations/en.json', :read => '}') ]
19
+ end
20
+
21
+ it 'should report the error' do
22
+ subject.length.should == 1
23
+ subject[0].to_s.should =~ /JSON/
24
+ end
25
+ end
26
+
27
+ context 'when there is file with JSON representing a non-Object' do
28
+ let(:translation_files) do
29
+ [ mock('AppFile', :relative_path => 'translations/en.json', :read => '"foo bar"') ]
30
+ end
31
+
32
+ it 'should report the error' do
33
+ subject.length.should == 1
34
+ subject[0].to_s.should =~ /JSON/
35
+ end
36
+ end
37
+
38
+ context 'when there is a file with an invalid locale for a name' do
39
+ let(:translation_files) do
40
+ [ mock('AppFile', :relative_path => 'translations/en-US.json', :read => '{}') ]
41
+ end
42
+
43
+ it 'should report the error' do
44
+ subject.length.should == 1
45
+ subject[0].to_s.should =~ /locale/
46
+ end
47
+ end
48
+
49
+ context 'when there is a file with a valid locale containing valid JSON' do
50
+ let(:translation_files) do
51
+ [ mock('AppFile', :relative_path => 'translations/en.json', :read => '{}') ]
52
+ end
53
+
54
+ it 'should be valid' do
55
+ subject.length.should == 0
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,96 @@
1
+ require 'zendesk_apps_support'
2
+ require 'json'
3
+
4
+ describe ZendeskAppsSupport::Validations::ValidationError do
5
+
6
+ ValidationError = ZendeskAppsSupport::Validations::ValidationError
7
+
8
+ it 'symbolizes the keys in its data' do
9
+ error = ValidationError.new(:foo, 'bar' => 'baz')
10
+ error.data[:bar].should == 'baz'
11
+ end
12
+
13
+ describe '#to_json' do
14
+ let(:key) { 'foo.bar' }
15
+ let(:data) { { 'baz' => 'quux' } }
16
+ let(:error) { ValidationError.new(key, data) }
17
+ subject { error.to_json }
18
+
19
+ it do
20
+ should == {
21
+ 'class' => error.class.to_s,
22
+ 'key' => error.key,
23
+ 'data' => error.data
24
+ }.to_json
25
+ end
26
+ end
27
+
28
+ describe '.from_hash' do
29
+
30
+ subject { ValidationError.from_hash(hash) }
31
+
32
+ context 'for a generic error' do
33
+ let(:hash) do
34
+ {
35
+ 'class' => 'ZendeskAppsSupport::Validations::ValidationError',
36
+ 'key' => 'foo.bar.baz',
37
+ 'data' => { 'quux' => 'yargle' }
38
+ }
39
+ end
40
+
41
+ it { should be_a(ValidationError) }
42
+
43
+ its(:key) { should == 'foo.bar.baz' }
44
+
45
+ its(:data) { should == { :quux => 'yargle' } }
46
+ its(:data) { should}
47
+ end
48
+
49
+ context 'for a JSHint error' do
50
+ let(:hash) do
51
+ {
52
+ 'class' => 'ZendeskAppsSupport::Validations::JSHintValidationError',
53
+ 'file' => 'foo.js',
54
+ 'jshint_errors' => [ { 'line' => 55, 'reason' => 'Yuck' } ]
55
+ }
56
+ end
57
+
58
+ it { should be_a(ZendeskAppsSupport::Validations::JSHintValidationError) }
59
+
60
+ its(:key) { should == :jshint }
61
+
62
+ its(:jshint_errors) do
63
+ should == [ { 'line' => 55, 'reason' => 'Yuck' } ]
64
+ end
65
+ end
66
+
67
+ context 'for a non-ValidationError hash' do
68
+ let(:hash) do
69
+ {
70
+ :foo => 'bar'
71
+ }
72
+ end
73
+
74
+ it 'raises a DeserializationError' do
75
+ lambda { subject }.should raise_error(ValidationError::DeserializationError)
76
+ end
77
+ end
78
+
79
+ end
80
+
81
+ describe '.from_json' do
82
+
83
+ it 'decodes a JSON hash and passes it to .from_hash' do
84
+ ValidationError.should_receive(:from_hash).with('foo' => 'bar')
85
+ ValidationError.from_json(MultiJson.encode({ 'foo' => 'bar' }))
86
+ end
87
+
88
+ it 'raises a DeserializationError when passed non-JSON' do
89
+ lambda {
90
+ ValidationError.from_json('}}}')
91
+ }.should raise_error(ValidationError::DeserializationError)
92
+ end
93
+
94
+ end
95
+
96
+ end
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zendesk_apps_support
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - James A. Rosen
9
+ - Kenshiro Nakagawa
10
+ - Shajith Chacko
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2013-01-14 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: i18n
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: multi_json
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: sass
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ - !ruby/object:Gem::Dependency
65
+ name: json
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ type: :runtime
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ - !ruby/object:Gem::Dependency
81
+ name: erubis
82
+ requirement: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: jshintrb
98
+ requirement: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.1.6
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - '='
110
+ - !ruby/object:Gem::Version
111
+ version: 0.1.6
112
+ - !ruby/object:Gem::Dependency
113
+ name: rspec
114
+ requirement: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ description: Support to help you develop Zendesk Apps.
129
+ email:
130
+ - dev@zendesk.com
131
+ executables: []
132
+ extensions: []
133
+ extra_rdoc_files: []
134
+ files:
135
+ - lib/zendesk_apps_support/app_file.rb
136
+ - lib/zendesk_apps_support/app_version.rb
137
+ - lib/zendesk_apps_support/default_styles.scss
138
+ - lib/zendesk_apps_support/engine.rb
139
+ - lib/zendesk_apps_support/i18n.rb
140
+ - lib/zendesk_apps_support/package.rb
141
+ - lib/zendesk_apps_support/sass_functions.rb
142
+ - lib/zendesk_apps_support/src.js.erb
143
+ - lib/zendesk_apps_support/stylesheet_compiler.rb
144
+ - lib/zendesk_apps_support/validations/manifest.rb
145
+ - lib/zendesk_apps_support/validations/source.rb
146
+ - lib/zendesk_apps_support/validations/templates.rb
147
+ - lib/zendesk_apps_support/validations/translations.rb
148
+ - lib/zendesk_apps_support/validations/validation_error.rb
149
+ - lib/zendesk_apps_support.rb
150
+ - config/locales/en.yml
151
+ - config/locales/translations/zendesk_apps_support.yml
152
+ - README.md
153
+ - LICENSE
154
+ - spec/app/app.css
155
+ - spec/app/app.js
156
+ - spec/app/assets/logo-small.png
157
+ - spec/app/assets/logo.png
158
+ - spec/app/manifest.json
159
+ - spec/app/templates/layout.hdbs
160
+ - spec/app/translations/en.json
161
+ - spec/app_file_spec.rb
162
+ - spec/app_version_spec.rb
163
+ - spec/i18n_spec.rb
164
+ - spec/package_spec.rb
165
+ - spec/validations/jshint_error_spec.rb
166
+ - spec/validations/manifest_spec.rb
167
+ - spec/validations/source_spec.rb
168
+ - spec/validations/templates_spec.rb
169
+ - spec/validations/translations_spec.rb
170
+ - spec/validations/validation_serialization_spec.rb
171
+ homepage: http://github.com/zendesk/zendesk_apps_support
172
+ licenses: []
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ none: false
185
+ requirements:
186
+ - - ! '>='
187
+ - !ruby/object:Gem::Version
188
+ version: 1.3.6
189
+ requirements: []
190
+ rubyforge_project:
191
+ rubygems_version: 1.8.24
192
+ signing_key:
193
+ specification_version: 3
194
+ summary: Support to help you develop Zendesk Apps.
195
+ test_files:
196
+ - spec/app/app.css
197
+ - spec/app/app.js
198
+ - spec/app/assets/logo-small.png
199
+ - spec/app/assets/logo.png
200
+ - spec/app/manifest.json
201
+ - spec/app/templates/layout.hdbs
202
+ - spec/app/translations/en.json
203
+ - spec/app_file_spec.rb
204
+ - spec/app_version_spec.rb
205
+ - spec/i18n_spec.rb
206
+ - spec/package_spec.rb
207
+ - spec/validations/jshint_error_spec.rb
208
+ - spec/validations/manifest_spec.rb
209
+ - spec/validations/source_spec.rb
210
+ - spec/validations/templates_spec.rb
211
+ - spec/validations/translations_spec.rb
212
+ - spec/validations/validation_serialization_spec.rb