Skip to content

Commit

Permalink
Merge pull request #45 from zendesk/roman/fix-validation
Browse files Browse the repository at this point in the history
Fixed validation order
  • Loading branch information
sandlerr committed Feb 9, 2014
2 parents b1bd36b + 55913c6 commit 61444ab
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 11 deletions.
25 changes: 16 additions & 9 deletions lib/zendesk_apps_support/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ def initialize(dir)
def validate
[].tap do |errors|

errors << Validations::Package.call(self)
errors << Validations::Manifest.call(self)
errors << Validations::Translations.call(self)

if has_location?
errors << Validations::Source.call(self)
errors << Validations::Templates.call(self)
errors << Validations::Stylesheets.call(self)
end
if has_manifest?
errors << Validations::Package.call(self)
errors << Validations::Translations.call(self)

if has_location?
errors << Validations::Source.call(self)
errors << Validations::Templates.call(self)
errors << Validations::Stylesheets.call(self)
end

if has_requirements?
errors << Validations::Requirements.call(self)
if has_requirements?
errors << Validations::Requirements.call(self)
end
end

errors.flatten!
Expand Down Expand Up @@ -98,6 +101,10 @@ def customer_css
customer_css = File.exist?(css_file) ? File.read(css_file) : ""
end

def has_manifest?
File.exist?(File.join(root, "manifest.json"))
end

def has_location?
manifest_json[:location]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ h1 {
span {
color: green;
}
}
}
2 changes: 1 addition & 1 deletion spec/app/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"app": {
"name": "Buddha Machine"
"name": "Buddha Machine"
}
}
6 changes: 6 additions & 0 deletions spec/app_nomanifest/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
h1 {
color: red;
span {
color: green;
}
}
12 changes: 12 additions & 0 deletions spec/app_nomanifest/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(function() {

return {
events: {
'app.activated':'doSomething'
},

doSomething: function() {
}
};

}());
Binary file added spec/app_nomanifest/assets/logo-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spec/app_nomanifest/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions spec/app_nomanifest/templates/layout.hdbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<header>
<span class="logo"/>
<h3>{{setting "name"}}</h3>
</header>
<section data-main/>
<footer>
<a href="mailto:{{author.email}}">
{{author.name}}
</a>
</footer>
</div>
5 changes: 5 additions & 0 deletions spec/app_nomanifest/translations/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"app": {
"name": "Buddha Machine"
}
}
7 changes: 7 additions & 0 deletions spec/package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
it 'should return all the files within the app folder excluding files in tmp folder' do
@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)
end

it 'should error out when manifest is missing' do
@package = ZendeskAppsSupport::Package.new('spec/app_nomanifest')
err = @package.validate
err.first.class.should == ZendeskAppsSupport::Validations::ValidationError
err.first.to_s.should == 'Could not find manifest.json'
end
end

describe 'template_files' do
Expand Down

0 comments on commit 61444ab

Please sign in to comment.