Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'contribution-upload'

  • Loading branch information...
commit 4d3c00a0c9bb0d92e9637a942a437f276b7c0ac4 2 parents 8d45304 + af87b82
@jpowers jpowers authored
View
31 app/assets/stylesheets/site.css.scss
@@ -1021,25 +1021,26 @@
font-size: .9em;
color: #696969;
}
- .item-attachments {
- @include proxima-bold;
- margin-top: 8px;
- margin-bottom: 1em;
- font-size: .9em;
- color: #696969;
- background: $lightgrey;
- padding: 1em;
- width: 100%;
- h4 {
- font-size: 1em;
- color: $medgrey;
- margin-bottom: 2em;
- }
- }
textarea {
width: 100%;
}
}
+ .item-attachments {
+ @include proxima-bold;
+ margin-top: 8px;
+ margin-bottom: 1em;
+ font-size: .9em;
+ color: #696969;
+ background: $lightgrey;
+ padding: 1em;
+ width: 100%;
+ float: left;
+ h4 {
+ font-size: 1em;
+ color: $medgrey;
+ margin-bottom: 2em;
+ }
+ }
.side-box {
background: $darkgrey;
margin-left: 0;
View
3  app/models/contribution.rb
@@ -14,7 +14,8 @@ class Contribution < ActiveRecord::Base
validates :details, presence: true
validates :creator_id, :presence => true, :unless => Proc.new {|contribution| contribution.type == "Correction"}
- accepts_nested_attributes_for :uploads, :item_relation
+ accepts_nested_attributes_for :uploads, allow_destroy: true, reject_if: :all_blank
+ accepts_nested_attributes_for :item_relation
search_methods :user_fullname_contains
View
7 app/views/contributions/edit.html.haml
@@ -7,5 +7,12 @@
= image_tag resource.item.thumbnail, { class: 'img-polaroid' }
= simple_form_for resource do |f|
= f.input :details, as: :text, label: false
+ .file-upload
+ %h3 Additional Documents
+ = f.simple_fields_for :uploads do |upload|
+ = render 'partials/upload_fields', f: upload
+ .links-add
+ .icon-plus-circle
+ = link_to_add_association 'Add Upload', f, :uploads, class: 'add-file', partial: 'partials/upload_fields'
.submit-button
=f.button :submit, "Save changes", class: 'submit-button', id: 'thread-submit-button'
View
7 app/views/contributions/new.html.haml
@@ -15,5 +15,12 @@
= i.input :accession_no, as: :hidden, input_html: { value: resource.item_relation.accession_no }
= i.input :search, as: :hidden, input_html: { value: resource.item_relation.search }
= f.input :details, as: :text, label: false, placeholder: "Type your #{resource.type.downcase}..."
+ .file-upload
+ %p Additional Documents
+ = f.simple_fields_for :uploads do |upload|
+ = render 'partials/upload_fields', f: upload
+ .links-add
+ .icon-plus-circle
+ = link_to_add_association 'Add Upload', f, :uploads, class: 'add-file', partial: 'partials/upload_fields'
.submit-button
= f.button :submit, "Submit #{resource.type}", class: 'submit-button', id: 'thread-submit-button'
View
11 app/views/contributions/show.html.haml
@@ -8,6 +8,13 @@
.item-title
= resource.title
.item-details
- %p
- = resource.details
+ %p= resource.details
+ - unless resource.uploads.empty?
+ .item-attachments
+ %h3 Attached Documents
+ %ul.item-uploads
+ - resource.uploads.each do |upload|
+ %li.item-upload
+ %i.icon-file-alt
+ = link_to upload[:content], upload.content_url
= render 'partials/comments', resource: resource
View
2  app/views/partials/_upload_fields.html.haml
@@ -3,7 +3,7 @@
= f.input :content_cache, as: :hidden
.dummyfile
%a.fileselectbutton.btn Choose...
- %input.filename{type: 'text', name: 'filename'}
+ %input.filename{type: 'text', name: 'filename', value: f.object["content"]}
.links-remove
= link_to_remove_association '', f, :class => 'icon-minus-circle'
#alert-message
View
2  spec/features/create_comment_spec.rb
@@ -3,7 +3,7 @@
describe 'comment creation' do
let!(:question) { create(:question) }
- let(:transcription) { create(:transcription) }
+ let!(:transcription) { create(:transcription) }
let(:user) { create(:user) }
describe 'without authentication' do
View
29 spec/features/create_contribution_spec.rb
@@ -25,25 +25,46 @@
let(:user) { create(:user) }
before { sign_in(user) }
- describe "contribution creation" do
+ describe "contribution creation", js: true do
it "creates a new transcription" do
create_and_check_contribution('Transcription', test_item)
end
+ it "creates a new transcrption with a document upload" do
+ create_and_check_contribution('Transcription', test_item, true)
+ end
+
it "creates translation creation" do
create_and_check_contribution('Translation', test_item)
end
+ it "creates a new translation with a document upload" do
+ create_and_check_contribution('Transcription', test_item, true)
+ end
+
it "creates biography creation" do
create_and_check_contribution('Biography', test_item)
end
+ it "creates a new biography with a document upload" do
+ create_and_check_contribution('Transcription', test_item, true)
+ end
+
# Helper to test each contribution type
- def create_and_check_contribution(type, selected_item)
+ def create_and_check_contribution(type, selected_item, test_upload=false)
visit new_contribution_path(type: type, item: selected_item)
expect(page).to have_content("You are submitting a #{type.downcase} for: #{selected_item.name}")
fill_in "#{type.downcase}_details", with: "Contribution test"
+
+ if test_upload
+ # Since the file field doesn't have a label, attach_file can't not
+ # be used. Instead, the file path is stored manually.
+ click_on 'Add Upload'
+ page.execute_script("$('.file.optional.upload').toggle();")
+ find(".input.file.optional.#{type.downcase}_uploads_content").find('input').set("#{Rails.root}/spec/support/Montmarte.jpg")
+ end
+
click_on "Submit #{type.titleize}"
Contribution.count.should == 1
@@ -53,6 +74,10 @@ def create_and_check_contribution(type, selected_item)
expect(page).to have_content(selected_item.name)
expect(page).to have_selector("img[src$='#{selected_item.thumbnail}']")
expect(page).to have_content("Contribution test")
+ if test_upload
+ expect(page).to have_content('Attached Documents') if test_upload
+ expect(page).to have_content('Montmarte.jpg') if test_upload
+ end
visit contributions_path(type: type)
expect(page).to have_content("#{user.fullname} contributed a #{type.downcase} for #{selected_item.name}")
View
9 spec/features/create_post_spec.rb
@@ -64,18 +64,15 @@
context "with javascript" do
describe "question creation with uploads" do
let(:user) { create(:user) }
-
before { sign_in(user) }
- after { sign_out }
it "creates new uploads", js: true do
- pending('file attachment issues')
visit new_post_path
-
fill_in 'post_title', with: 'a title'
page.execute_script("editor.setValue('additional details')")
click_on 'Add Upload'
- attach_file('filename' ,'spec/support/files/cow.jpg')
+ page.execute_script("$('.file.optional.upload').toggle();")
+ find(".input.file.optional.post_uploads_content").find('input').set("#{Rails.root}/spec/support/Montmarte.jpg")
click_on 'Submit'
Question.count.should == 1
@@ -84,7 +81,7 @@
page.should have_content('a title')
page.should have_content('additional details')
- page.should have_content('cow.jpg')
+ page.should have_content('Montmarte.jpg')
end
end
end
View
28 spec/features/edit_contribution_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe 'Contribution Edit button', js: true do
+ # Create a test contribution with an item and a user
let(:test_item) { create(:item, thumbnail: 'http://s3.amazonaws.com/assets.qajarwomen.org/thumbs/it_3438.jpg?1345647766') }
let(:test_item_relation) { create(:item_relation, item: test_item)}
let(:test_user) { create :user }
@@ -11,15 +12,21 @@
visit root_path
click_on 'My Contributions'
page.find('.item-title').hover
+ click_on 'Edit'
end
it 'shows edit button' do
+ # Go back to the My Contributions page to test the edit button appears
+ visit root_path
+ click_on 'My Contributions'
+ page.find('.item-title').hover
+
find_link('Edit').should be_visible
end
it 'shows the edit page' do
- click_on 'Edit'
-
+ # Test the edit page shows buttons and the contribution text stored with the
+ # test item
current_path.should == edit_contribution_path(transcription)
expect(page).to have_selector("img[src$='#{test_item.thumbnail}']")
page.find('textarea[id="transcription_details"]').value.should == transcription.details
@@ -27,7 +34,7 @@
end
it 'updates the content' do
- click_on 'Edit'
+ # Test the contribution text is editable
page.find('textarea[id="transcription_details"]').set(' -updated- ')
click_on 'Save changes'
@@ -37,10 +44,23 @@
end
it 'validates' do
- click_on 'Edit'
+ # Test the edit page validates the edited text
page.find('textarea[id="transcription_details"]').set('')
click_on 'Save changes'
expect(page).to have_content('Can\'t be blank')
end
+
+ it 'allows a user add a file' do
+ click_on 'Add Upload'
+ page.execute_script("$('.file.optional.upload').toggle();")
+ find(".input.file.optional.transcription_uploads_content").find('input').set("#{Rails.root}/spec/support/Montmarte.jpg")
+ click_on "Save changes"
+
+ current_path.should == contribution_path(transcription)
+ expect(page).to have_content('Your transcription was successfully updated.')
+ expect(page).to have_content(transcription.details)
+ expect(page).to have_content('Attached Documents')
+ expect(page).to have_content('Montmarte.jpg')
+ end
end
View
17 spec/spec_helper.rb
@@ -64,6 +64,23 @@
Warden.test_reset!
end
+ config.after(:all) do
+ if Rails.env.test?
+ FileUtils.rm_rf(Dir["#{Rails.root}/spec/support/uploads"])
+ end
+ end
+
+ if defined?(CarrierWave)
+ CarrierWave::Uploader::Base.descendants.each do |klass|
+ next if klass.anonymous?
+ klass.class_eval do
+ def store_dir
+ "#{Rails.root}/spec/support/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+ end
+ end
+ end
+
config.include FactoryGirl::Syntax::Methods
config.include Warden::Test::Helpers
config.include WaitSteps
View
BIN  spec/support/Montmarte.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.