prettifying forum views

This commit is contained in:
Skud
2013-02-13 15:55:16 +11:00
parent de85a6dcce
commit ef236befcd
9 changed files with 52 additions and 83 deletions

View File

@@ -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'

View File

@@ -1,4 +1,4 @@
%h1 Editing forum
- content_for :title, "Editing forum"
= render 'form'

View File

@@ -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

View File

@@ -1,4 +1,4 @@
%h1 New forum
- content_for :title, "New Forum"
= render 'form'

View File

@@ -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'

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 <p>" 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