aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/refinery/admin/blog/posts_controller.rb10
-rw-r--r--app/views/refinery/admin/blog/posts/_form.html.erb9
-rw-r--r--config/locales/en.yml2
-rw-r--r--spec/requests/refinery/admin/blog/posts_spec.rb30
4 files changed, 44 insertions, 7 deletions
diff --git a/app/controllers/refinery/admin/blog/posts_controller.rb b/app/controllers/refinery/admin/blog/posts_controller.rb
index 8b3816d..4645f3f 100644
--- a/app/controllers/refinery/admin/blog/posts_controller.rb
+++ b/app/controllers/refinery/admin/blog/posts_controller.rb
@@ -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',
diff --git a/app/views/refinery/admin/blog/posts/_form.html.erb b/app/views/refinery/admin/blog/posts/_form.html.erb
index 822ec8a..f20c0cc 100644
--- a/app/views/refinery/admin/blog/posts/_form.html.erb
+++ b/app/views/refinery/admin/blog/posts/_form.html.erb
@@ -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} %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 9222d11..3aa2b68 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -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:
diff --git a/spec/requests/refinery/admin/blog/posts_spec.rb b/spec/requests/refinery/admin/blog/posts_spec.rb
index 08fbab9..53372b1 100644
--- a/spec/requests/refinery/admin/blog/posts_spec.rb
+++ b/spec/requests/refinery/admin/blog/posts_spec.rb
@@ -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