Skip to content

Commit

Permalink
completed publishers feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Wyma committed Oct 16, 2014
1 parent 86d3bc2 commit 2ef688a
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 17 deletions.
7 changes: 7 additions & 0 deletions app/assets/javascripts/application.js
Expand Up @@ -209,6 +209,13 @@ $(document).on('ready nested:fieldAdded', function () {
classes: default_linear_classes
});

/*
Publisher === Publisher === Publisher === Publisher === Publisher === Publisher === Publisher
*/
$('input.publishers_lookup').tokenInput("/publishers/lookup.json", {
classes: default_linear_classes
});

/*
UserTag === UserTag === UserTag === UserTag === UserTag === UserTag === UserTag
*/
Expand Down
15 changes: 15 additions & 0 deletions app/controllers/publishers_controller.rb
@@ -0,0 +1,15 @@
class PublishersController < ApplicationController
before_filter :authenticate_user!

respond_to :json

def index
respond_with Publisher.all
end

def lookup
search_data = params[:q].to_s
respond_with Publisher.only(:name).where(name:/#{search_data}/).all.map {|p| {id:p.name, name:p.name}} << {id:search_data, name:search_data}
end

end
4 changes: 2 additions & 2 deletions app/models/work.rb
Expand Up @@ -173,13 +173,13 @@ def publishers_text
def publishers_text=(value)
self.publishers.clear
value.split(",").each{|q|
self.labels << q
self.publishers << q
}
end

def tokenized_publishers
tokenized = []
self.publishers.each {|label| tokenized << {id:label, name:label}}
self.publishers.each {|publisher| tokenized << {id:publisher, name:publisher}}
tokenized.to_json
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/works/_form.haml
Expand Up @@ -7,8 +7,8 @@
%dd= form.text_field :copyright
%dt= form.label :language_code
%dd= form.text_field :language_code
%dt= form.label :publishers
%dd= form.text_field :publishers, 'data-pre' => @work.tokenized_publishers
%dt= form.label :publishers_text
%dd= form.text_field :publishers_text, 'data-pre' => @work.tokenized_publishers, class: 'publishers_lookup'
%dt= form.label :lyrics
%dd= form.text_area :lyrics, :class=>"span12"
= form.fields_for :work_wiki_links do |w|
Expand Down
4 changes: 2 additions & 2 deletions app/views/works/_info.haml
Expand Up @@ -11,8 +11,8 @@
- if @work.language_name
#{@work.language_name.slice(0,1).capitalize + @work.language_name.slice(1..-1)}
%p
= Work.human_attribute_name("publisher")
\: #{@work.publisher}
= Work.human_attribute_name("publishers")
\: #{@work.publishers.join(', ')}

%h2 #{t('credits')}
- if @work.artist_wiki_links.size == 0
Expand Down
6 changes: 6 additions & 0 deletions config/routes.rb
Expand Up @@ -10,6 +10,12 @@

devise_for :users

resources :publishers, only: :index do
collection do
get 'lookup'
end
end

resources :labels, only: :index do
collection do
get 'lookup'
Expand Down
12 changes: 8 additions & 4 deletions features/step_definitions/work_steps.rb
Expand Up @@ -67,14 +67,18 @@
end

When(/^I add some publishers$/) do
visit edit_work_path @work
@publisher = "test"
fill_in "token-input-labels", with: @publisher
select_fb_token label
raise
# find('a#confirmaddmusic').click
fill_in "token-input-work_publishers_text", with: @publisher
select_fb_token @publisher
find('input.btn-primary').click
end

Then(/^the work should have publishers$/) do
expect(page).to have_content @publisher
expect(@work.reload.publishers.size).to eq 1
expect(@work.publishers.first).to eq @publisher
publisher = Publisher.first
expect(publisher.count).to eq 1
expect(publisher.name).to eq @publisher
end
14 changes: 7 additions & 7 deletions features/work.feature
Expand Up @@ -9,7 +9,7 @@ Feature: Works
When I search for a work with the query 'title:"A house of pain"'
Then I should see a "Create It" link button
And I should not see the alphabetical index links

@javascript
Scenario: A user can preview a change before it is saved
Given a work exists
Expand All @@ -18,36 +18,36 @@ Feature: Works
Then I should see the work preview listed
And a notice showing that it is a preview
And the original work should not be touched

@javascript
Scenario: A user can update a record after a preview
Given I have already performed a preview on an existing work
When I choose to accept the update
Then the work should have the new data

@javascript
Scenario: A user can preview a new record before saving
Given a user who is logged in
When I preview a new work
Then I should see the work preview listed
And a notice showing that it is a preview
And no new work should have been created

Scenario: Anyone can report content when there is a supplementary section
Given a work with a supplementary section
When I view this work
Then the report link should be visible

Scenario: Anyone cannot report content when there is not a supplementary section
Given a work without a supplementary section
When I view this work
Then the report link should not be visible

Scenario: Anyone can report content when there is a supplementary section
Given a work with lyrics
When I view this work
Then the report link should be visible

Scenario: An email should be sent to the admin and reporter upon submitting a report
Given a work with a supplementary section
And I view this work
Expand Down

0 comments on commit 2ef688a

Please sign in to comment.