Skip to content

Commit

Permalink
data_file as an activemodel so we can have easy sweet validations
Browse files Browse the repository at this point in the history
  • Loading branch information
arnab committed Mar 23, 2012
1 parent 76761ce commit edd4906
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 21 deletions.
13 changes: 13 additions & 0 deletions app/assets/stylesheets/custom.css.scss
Expand Up @@ -117,3 +117,16 @@ input, textarea, select, .uneditable-input {
margin-bottom: 15px; margin-bottom: 15px;
@include box_sizing; @include box_sizing;
} }

#error_explanation {
color:#f00;
ul {
list-style: none;
margin: 0 0 18px 0;
}
}

.field_with_errors {
@extend .control-group;
@extend .error;
}
10 changes: 10 additions & 0 deletions app/helpers/data_files_helper.rb
@@ -1,2 +1,12 @@
module DataFilesHelper module DataFilesHelper
def example_input_file_link
'https://raw.github.com/lschallenges/data-engineering/master/example_input.tab'
end

def data_file_label_content_with_link
raw(
"Please upload a tab-delimited file, like " +
"<a href='#{example_input_file_link}'>this</a>."
)
end
end end
6 changes: 2 additions & 4 deletions app/views/data_files/new.html.haml
Expand Up @@ -4,11 +4,9 @@
.row .row
.span6.offset4 .span6.offset4
= form_for(@data_file) do |f| = form_for(@data_file) do |f|
= render 'shared/error_messages', :object => f.object
.span6 .span6
= f.label :data, 'Please upload a tab-delimited file' = f.label :data, data_file_label_content_with_link
%span.help-block
example:
= link_to 'here', 'https://raw.github.com/lschallenges/data-engineering/master/example_input.tab'
= f.file_field :data, :class => 'input-xlarge' = f.file_field :data, :class => 'input-xlarge'
.span6 .span6
= f.submit "Upload", :class => "btn btn-large btn-primary" = f.submit "Upload", :class => "btn btn-large btn-primary"
9 changes: 9 additions & 0 deletions app/views/shared/_error_messages.html.haml
@@ -0,0 +1,9 @@
- if object.errors.any?
#error_explanation
.alert.alert-error
The form contains
= pluralize(object.errors.count, "error")
\.
%ul
- object.errors.full_messages.each do |msg|
%li= msg
1 change: 0 additions & 1 deletion features/file_upload.feature
Expand Up @@ -8,7 +8,6 @@ Scenario: Home Page should be the file import page
Then I should see "Import Your Data" Then I should see "Import Your Data"
Then I should see a "Upload" button Then I should see a "Upload" button


@wip
Scenario: Not uploading a file Scenario: Not uploading a file
When I go to the file import page When I go to the file import page
And I click "Upload" And I click "Upload"
Expand Down
2 changes: 1 addition & 1 deletion features/step_definitions/common_steps.rb
Expand Up @@ -22,7 +22,7 @@
end end


Then /^I should see (\d+) validation errors?$/ do |num| Then /^I should see (\d+) validation errors?$/ do |num|
expected_str = "The file contains #{num} error" expected_str = "The form contains #{num} error"
expected_str += "s" if num.to_i > 1 expected_str += "s" if num.to_i > 1
page.should have_content(expected_str) page.should have_content(expected_str)
end end
Expand Down
15 changes: 0 additions & 15 deletions spec/helpers/data_files_helper_spec.rb

This file was deleted.

5 changes: 5 additions & 0 deletions spec/models/data_file_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe DataFile do
it_should_behave_like "ActiveModel"
end
19 changes: 19 additions & 0 deletions spec/support/active_model_lint.rb
@@ -0,0 +1,19 @@
# From https://gist.github.com/639089

shared_examples_for "ActiveModel" do
require 'test/unit/assertions'
require 'active_model/lint'
include Test::Unit::Assertions
include ActiveModel::Lint::Tests

# to_s is to support ruby-1.9
ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
example m.gsub('_',' ') do
send m
end
end

def model
subject
end
end

0 comments on commit edd4906

Please sign in to comment.