Merge pull request #157 from substantial/add_author_attribution

Add author attribution
This commit is contained in:
Philip Arndt 2011-12-14 15:47:22 -08:00
commit cc316ceb5b
4 changed files with 44 additions and 7 deletions

View file

@ -34,6 +34,10 @@ module Refinery
render :json => @tags.flatten
end
def new
@blog_post = ::Refinery::Blog::Post.new(:author => current_refinery_user)
end
def create
# if the position field exists, set this object as last object, given the conditions of this class.
if Refinery::Blog::Post.column_names.include?("position")
@ -42,12 +46,6 @@ module Refinery
})
end
if Refinery::Blog::Post.column_names.include?("user_id")
params[:blog_post].merge!({
:user_id => current_refinery_user.id
})
end
if (@blog_post = Refinery::Blog::Post.create(params[:blog_post])).valid?
(request.xhr? ? flash.now : flash).notice = t(
'refinery.crudify.created',

View file

@ -89,6 +89,15 @@
<%= f.text_field :custom_url, :class => "widest" %>
</div>
<div class='field'>
<span class='label_with_help'>
<%= f.label :user_id, t('.author') %>
<%= refinery_help_tag t('.author_help') %>
<br/>
<%= f.collection_select :user_id, ::Refinery::User.all, :id, :username %>
</span>
</div>
</div>
<div class='hemisquare right_side'>
<%= render :partial => '/seo_meta/form', :locals => {:form => f} %>

View file

@ -41,6 +41,8 @@ en:
published_at: Publish Date
custom_url: Custom Url
custom_url_help: Generate the url for the blog post from this text instead of the title.
author: Author
author_help: Set which user this post will show as the author.
copy_body: Copy Post Body to Teaser
copy_body_help: Copies the post body to the teaser. Leave teaser blank to let Refinery automatically make the teaser.
index:

View file

@ -48,7 +48,7 @@ module Refinery
end
it "should belong to me" do
::Refinery::Blog::Post.first.author.login.should eq(::Refinery::User.last.login)
::Refinery::Blog::Post.first.author.should eq(::Refinery::User.last)
end
it "should save categories" do
@ -139,5 +139,33 @@ module Refinery
end
end
end
context "with multiple users" do
let!(:other_guy) { Factory(:refinery_user, :username => "Other Guy") }
describe "create blog post with alternate author" do
before(:each) do
visit refinery_admin_blog_posts_path
click_link "Create new post"
fill_in "Title", :with => "This is some other guy's blog post"
fill_in "blog_post_body", :with => "I totally didn't write it."
click_link "Advanced Options"
select other_guy.username, :from => "Author"
click_button "Save"
end
it "should succeed" do
page.should have_content("was successfully added.")
end
it "belongs to another user" do
::Refinery::Blog::Post.last.author.should eq(other_guy)
end
end
end
end
end