mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-18 21:56:55 -04:00
post in (or not in) a forum
This commit is contained in:
@@ -29,6 +29,7 @@ class PostsController < ApplicationController
|
||||
# GET /posts/new.json
|
||||
def new
|
||||
@post = Post.new
|
||||
@forum = Forum.find_by_id(params[:forum_id]) || Forum.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.haml
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Post < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :author_date_subject, use: :slugged
|
||||
attr_accessible :body, :subject, :author_id
|
||||
attr_accessible :body, :subject, :author_id, :forum_id
|
||||
belongs_to :author, :class_name => 'Member'
|
||||
belongs_to :forum
|
||||
has_many :comments, :dependent => :destroy
|
||||
|
||||
@@ -6,14 +6,18 @@
|
||||
- @post.errors.full_messages.each do |msg|
|
||||
%li= msg
|
||||
|
||||
.field
|
||||
= f.label :author_id
|
||||
= f.number_field :author_id
|
||||
.field
|
||||
= f.label :subject
|
||||
= f.text_field :subject
|
||||
.field
|
||||
= f.label :body
|
||||
= f.text_area :body
|
||||
.actions
|
||||
= f.submit 'Save'
|
||||
|
||||
= label_tag :post, "Subject"
|
||||
= f.text_field :subject, :class => 'input-block-level'
|
||||
= label_tag :body, "What's going on in your food garden?"
|
||||
= f.text_area :body, :rows => 12, :class => 'input-block-level'
|
||||
|
||||
- if @post.forum || @forum
|
||||
- forum = @post.forum || @forum
|
||||
%p
|
||||
This post will be posted in the forum
|
||||
=link_to forum.name, forum
|
||||
.field
|
||||
= f.hidden_field :forum_id, :value => forum.id
|
||||
|
||||
= f.submit "Post", :class => 'btn'
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
= content_for :title, "Edit post"
|
||||
|
||||
= form_for @post do |f|
|
||||
= label_tag :subject, "Subject"
|
||||
= f.text_field :subject, :class => 'input-block-level'
|
||||
= f.text_area :body, :rows => 12, :class => 'input-block-level'
|
||||
= f.submit "Post"
|
||||
=render 'form'
|
||||
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
= content_for :title, "Post a post"
|
||||
= content_for :title, @forum.name ? "Post in #{@forum.name}" : "Post something"
|
||||
|
||||
=render 'form'
|
||||
|
||||
= form_for @post, :url => { :action => "create" } do |f|
|
||||
%fieldset
|
||||
= label_tag :post, "Subject"
|
||||
= f.text_field :subject, :class => 'input-block-level'
|
||||
= label_tag :body, "What's going on in your food garden?"
|
||||
= f.text_area :body, :rows => 12, :class => 'input-block-level'
|
||||
= f.submit "Post", :class => 'btn'
|
||||
|
||||
@@ -39,6 +39,17 @@ describe PostsController do
|
||||
get :new, {}
|
||||
assigns(:post).should be_a_new(Post)
|
||||
end
|
||||
|
||||
it "picks up forum from params" do
|
||||
forum = FactoryGirl.create(:forum)
|
||||
get :new, {:forum_id => forum.id}
|
||||
assigns(:forum).should eq(forum)
|
||||
end
|
||||
|
||||
it "doesn't die if no forum specified" do
|
||||
get :new, {}
|
||||
assigns(:forum).should be_a_new(Forum)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET edit" do
|
||||
|
||||
@@ -10,4 +10,8 @@ describe "forums/show" do
|
||||
rendered.should contain @forum.description
|
||||
rendered.should contain @forum.owner.to_s
|
||||
end
|
||||
|
||||
it 'links to new post with the forum id' do
|
||||
assert_select "a[href=#{new_post_path(:forum_id => @forum.id)}]"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,5 +19,33 @@ describe "posts/edit" do
|
||||
assert_select "textarea#post_body", :name => "post[body]"
|
||||
end
|
||||
end
|
||||
|
||||
it 'no hidden forum field' do
|
||||
assert_select "input#post_forum_id[type=hidden]", false
|
||||
end
|
||||
|
||||
it 'no forum mentioned' do
|
||||
rendered.should_not contain "This post will be posted in the forum"
|
||||
end
|
||||
|
||||
context "forum specified" do
|
||||
before(:each) do
|
||||
@forum = assign(:forum, FactoryGirl.create(:forum))
|
||||
assign(:post, FactoryGirl.create( :post,
|
||||
:forum => @forum,
|
||||
:author => @author
|
||||
))
|
||||
render
|
||||
end
|
||||
|
||||
it 'creates a hidden field' do
|
||||
assert_select "input#post_forum_id[type=hidden][value=#{@forum.id}]"
|
||||
end
|
||||
|
||||
it 'tells the user what forum it will be posted in' do
|
||||
rendered.should contain "This post will be posted in the forum #{@forum.name}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,15 +4,41 @@ describe "posts/new" do
|
||||
before(:each) do
|
||||
@author = FactoryGirl.create(:member)
|
||||
assign(:post, FactoryGirl.create(:post, :author => @author))
|
||||
assign(:forum, Forum.new)
|
||||
sign_in @author
|
||||
controller.stub(:current_user) { @author }
|
||||
render
|
||||
end
|
||||
|
||||
it "renders new post form" do
|
||||
render
|
||||
assert_select "form", :action => posts_path, :method => "post" do
|
||||
assert_select "input#post_subject", :name => "post[subject]"
|
||||
assert_select "textarea#post_body", :name => "post[body]"
|
||||
end
|
||||
end
|
||||
|
||||
it 'no hidden forum field' do
|
||||
assert_select "input#post_forum_id[type=hidden]", false
|
||||
end
|
||||
|
||||
it 'no forum mentioned' do
|
||||
rendered.should_not contain "This post will be posted in the forum"
|
||||
end
|
||||
|
||||
context "forum specified" do
|
||||
before(:each) do
|
||||
@forum = assign(:forum, FactoryGirl.create(:forum))
|
||||
assign(:post, FactoryGirl.create(:post, :forum => @forum))
|
||||
render
|
||||
end
|
||||
|
||||
it 'creates a hidden field' do
|
||||
assert_select "input#post_forum_id[type=hidden][value=#{@forum.id}]"
|
||||
end
|
||||
|
||||
it 'tells the user what forum it will be posted in' do
|
||||
rendered.should contain "This post will be posted in the forum #{@forum.name}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user