diff --git a/app/views/forums/_form.html.haml b/app/views/forums/_form.html.haml index 05c4d5538..116af4f2e 100644 --- a/app/views/forums/_form.html.haml +++ b/app/views/forums/_form.html.haml @@ -1,4 +1,4 @@ -= form_for @forum do |f| += form_for @forum, :html => { :class => 'form-horizontal' } do |f| - if @forum.errors.any? #error_explanation %h2= "#{pluralize(@forum.errors.count, "error")} prohibited this forum from being saved:" @@ -6,14 +6,14 @@ - @forum.errors.full_messages.each do |msg| %li= msg - .field - = f.label :name - = f.text_field :name - .field - = f.label :description - = f.text_area :description - .field - = f.label :owner_id - = f.number_field :owner_id - .actions - = f.submit 'Save' + .control-group + = f.label :name, :class => 'control-label' + .controls= f.text_field :name, :class => 'input-block-level' + .control-group + = f.label :description, :class => 'control-label' + .controls= f.text_area :description, :rows => 6, :class => 'input-block-level' + .control-group + = f.label :owner_id, :class => 'control-label' + .controls= collection_select(:forum, :owner_id, Member.all, :id, :login_name) + .form-actions + = f.submit 'Save', :class => 'btn' diff --git a/app/views/forums/edit.html.haml b/app/views/forums/edit.html.haml index 88c265f45..f334a2092 100644 --- a/app/views/forums/edit.html.haml +++ b/app/views/forums/edit.html.haml @@ -1,4 +1,4 @@ -%h1 Editing forum +- content_for :title, "Editing forum" = render 'form' diff --git a/app/views/forums/index.html.haml b/app/views/forums/index.html.haml index aac289aae..2da64d0ad 100644 --- a/app/views/forums/index.html.haml +++ b/app/views/forums/index.html.haml @@ -1,23 +1,12 @@ -%h1 Listing forums +- content_for :title, "Forums" -%table - %tr - %th Name - %th Description - %th Owner - %th - %th - %th - - - @forums.each do |forum| - %tr - %td= forum.name - %td= forum.description - %td= forum.owner_id - %td= link_to 'Show', forum - %td= link_to 'Edit', edit_forum_path(forum) - %td= link_to 'Destroy', forum, method: :delete, data: { confirm: 'Are you sure?' } - -%br - -= link_to 'New Forum', new_forum_path +- @forums.each do |forum| + .well + %h2= forum.name + %p + Owner: + =link_to forum.owner, forum.owner + %div + :markdown + #{ strip_tags(forum.description) } + %p= link_to "Visit forum", forum diff --git a/app/views/forums/new.html.haml b/app/views/forums/new.html.haml index 45a9dc26a..59e6ef782 100644 --- a/app/views/forums/new.html.haml +++ b/app/views/forums/new.html.haml @@ -1,4 +1,4 @@ -%h1 New forum +- content_for :title, "New Forum" = render 'form' diff --git a/app/views/forums/show.html.haml b/app/views/forums/show.html.haml index 8f2f1eacb..6cd636e19 100644 --- a/app/views/forums/show.html.haml +++ b/app/views/forums/show.html.haml @@ -1,15 +1,20 @@ +- content_for :title, @forum.name + %p#notice= notice %p - %b Name: - = @forum.name -%p - %b Description: = @forum.description %p - %b Owner: - = @forum.owner_id + This forum is run by + = link_to @forum.owner, @forum.owner -= link_to 'Edit', edit_forum_path(@forum) -\| -= link_to 'Back', forums_path +%h2 Posts + +- if @forum.posts.length > 0 + - @forum.posts.each do |post| + = render :partial => "posts/single", :locals => { :post => post, :subject => true } + +- else + %p No posts yet. + +%p=link_to "Post something", new_post_path(:forum_id => @forum.id), :class => 'btn' diff --git a/spec/views/forums/edit.html.haml_spec.rb b/spec/views/forums/edit.html.haml_spec.rb index d957b9adc..306f3bbf0 100644 --- a/spec/views/forums/edit.html.haml_spec.rb +++ b/spec/views/forums/edit.html.haml_spec.rb @@ -16,7 +16,7 @@ describe "forums/edit" do assert_select "form", :action => forums_path(@forum), :method => "post" do assert_select "input#forum_name", :name => "forum[name]" assert_select "textarea#forum_description", :name => "forum[description]" - assert_select "input#forum_owner_id", :name => "forum[owner_id]" + assert_select "select#forum_owner_id", :name => "forum[owner_id]" end end end diff --git a/spec/views/forums/index.html.haml_spec.rb b/spec/views/forums/index.html.haml_spec.rb index f45bdedd4..273fad99f 100644 --- a/spec/views/forums/index.html.haml_spec.rb +++ b/spec/views/forums/index.html.haml_spec.rb @@ -2,25 +2,12 @@ require 'spec_helper' describe "forums/index" do before(:each) do - assign(:forums, [ - stub_model(Forum, - :name => "Name", - :description => "MyText", - :owner_id => 1 - ), - stub_model(Forum, - :name => "Name", - :description => "MyText", - :owner_id => 1 - ) - ]) + @forum1 = FactoryGirl.create(:forum) + assign(:forums, [ @forum1, @forum1 ]) + render end it "renders a list of forums" do - render - # Run the generator again with the --webrat flag if you want to use webrat matchers - assert_select "tr>td", :text => "Name".to_s, :count => 2 - assert_select "tr>td", :text => "MyText".to_s, :count => 2 - assert_select "tr>td", :text => 1.to_s, :count => 2 + assert_select "h2", :text => @forum1.name, :count => 2 end end diff --git a/spec/views/forums/new.html.haml_spec.rb b/spec/views/forums/new.html.haml_spec.rb index 63b4bac34..bfda7bfa1 100644 --- a/spec/views/forums/new.html.haml_spec.rb +++ b/spec/views/forums/new.html.haml_spec.rb @@ -2,21 +2,15 @@ require 'spec_helper' describe "forums/new" do before(:each) do - assign(:forum, stub_model(Forum, - :name => "MyString", - :description => "MyText", - :owner_id => 1 - ).as_new_record) + @forum = assign(:forum, FactoryGirl.create(:forum)) + render end it "renders new forum form" do - render - - # Run the generator again with the --webrat flag if you want to use webrat matchers assert_select "form", :action => forums_path, :method => "post" do assert_select "input#forum_name", :name => "forum[name]" assert_select "textarea#forum_description", :name => "forum[description]" - assert_select "input#forum_owner_id", :name => "forum[owner_id]" + assert_select "select#forum_owner_id", :name => "forum[owner_id]" end end end diff --git a/spec/views/forums/show.html.haml_spec.rb b/spec/views/forums/show.html.haml_spec.rb index 96ac62921..e41265a67 100644 --- a/spec/views/forums/show.html.haml_spec.rb +++ b/spec/views/forums/show.html.haml_spec.rb @@ -2,18 +2,12 @@ require 'spec_helper' describe "forums/show" do before(:each) do - @forum = assign(:forum, stub_model(Forum, - :name => "Name", - :description => "MyText", - :owner_id => 1 - )) + @forum = assign(:forum, FactoryGirl.create(:forum)) + render end - it "renders attributes in
" do - render - # Run the generator again with the --webrat flag if you want to use webrat matchers - rendered.should match(/Name/) - rendered.should match(/MyText/) - rendered.should match(/1/) + it "renders attributes" do + rendered.should contain @forum.description + rendered.should contain @forum.owner.to_s end end