Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 5 commits
  • 25 files changed
  • 0 comments
  • 1 contributor

Showing 25 changed files with 382 additions and 6 deletions. Show diff stats Hide diff stats

  1. +3 0  app/assets/javascripts/boards.js.coffee
  2. +3 0  app/assets/stylesheets/boards.css.scss
  3. +69 0 app/assets/stylesheets/scaffolds.css.scss
  4. +83 0 app/controllers/boards_controller.rb
  5. +2 1  app/controllers/topics_controller.rb
  6. +2 0  app/helpers/boards_helper.rb
  7. +5 0 app/models/board.rb
  8. +2 1  app/models/topic.rb
  9. +29 0 app/views/boards/_form.html.erb
  10. +6 0 app/views/boards/edit.html.erb
  11. +27 0 app/views/boards/index.html.erb
  12. +5 0 app/views/boards/new.html.erb
  13. +20 0 app/views/boards/show.html.erb
  14. +4 0 config/routes.rb
  15. +11 0 db/migrate/20121121022941_create_boards.rb
  16. +5 0 db/migrate/20121121023435_add_board_id_to_topic.rb
  17. +10 1 db/schema.rb
  18. +12 0 test/fixtures/boards.yml
  19. +6 1 test/fixtures/topics.yml
  20. +49 0 test/functional/boards_controller_test.rb
  21. +2 1  test/functional/topics_controller_test.rb
  22. +8 0 test/integration/board_flow_test.rb
  23. +7 0 test/unit/board_test.rb
  24. +4 0 test/unit/helpers/boards_helper_test.rb
  25. +8 1 test/unit/topic_test.rb
3  app/assets/javascripts/boards.js.coffee
... ... @@ -0,0 +1,3 @@
  1 +# Place all the behaviors and hooks related to the matching controller here.
  2 +# All this logic will automatically be available in application.js.
  3 +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3  app/assets/stylesheets/boards.css.scss
... ... @@ -0,0 +1,3 @@
  1 +// Place all the styles related to the boards controller here.
  2 +// They will automatically be included in application.css.
  3 +// You can use Sass (SCSS) here: http://sass-lang.com/
69 app/assets/stylesheets/scaffolds.css.scss
... ... @@ -0,0 +1,69 @@
  1 +body {
  2 + background-color: #fff;
  3 + color: #333;
  4 + font-family: verdana, arial, helvetica, sans-serif;
  5 + font-size: 13px;
  6 + line-height: 18px;
  7 +}
  8 +
  9 +p, ol, ul, td {
  10 + font-family: verdana, arial, helvetica, sans-serif;
  11 + font-size: 13px;
  12 + line-height: 18px;
  13 +}
  14 +
  15 +pre {
  16 + background-color: #eee;
  17 + padding: 10px;
  18 + font-size: 11px;
  19 +}
  20 +
  21 +a {
  22 + color: #000;
  23 + &:visited {
  24 + color: #666;
  25 + }
  26 + &:hover {
  27 + color: #fff;
  28 + background-color: #000;
  29 + }
  30 +}
  31 +
  32 +div {
  33 + &.field, &.actions {
  34 + margin-bottom: 10px;
  35 + }
  36 +}
  37 +
  38 +#notice {
  39 + color: green;
  40 +}
  41 +
  42 +.field_with_errors {
  43 + padding: 2px;
  44 + background-color: red;
  45 + display: table;
  46 +}
  47 +
  48 +#error_explanation {
  49 + width: 450px;
  50 + border: 2px solid red;
  51 + padding: 7px;
  52 + padding-bottom: 0;
  53 + margin-bottom: 20px;
  54 + background-color: #f0f0f0;
  55 + h2 {
  56 + text-align: left;
  57 + font-weight: bold;
  58 + padding: 5px 5px 5px 15px;
  59 + font-size: 12px;
  60 + margin: -7px;
  61 + margin-bottom: 0px;
  62 + background-color: #c00;
  63 + color: #fff;
  64 + }
  65 + ul li {
  66 + font-size: 12px;
  67 + list-style: square;
  68 + }
  69 +}
83 app/controllers/boards_controller.rb
... ... @@ -0,0 +1,83 @@
  1 +class BoardsController < ApplicationController
  2 + # GET /boards
  3 + # GET /boards.json
  4 + def index
  5 + @boards = Board.all
  6 +
  7 + respond_to do |format|
  8 + format.html # index.html.erb
  9 + format.json { render json: @boards }
  10 + end
  11 + end
  12 +
  13 + # GET /boards/1
  14 + # GET /boards/1.json
  15 + def show
  16 + @board = Board.find(params[:id])
  17 +
  18 + respond_to do |format|
  19 + format.html # show.html.erb
  20 + format.json { render json: @board }
  21 + end
  22 + end
  23 +
  24 + # GET /boards/new
  25 + # GET /boards/new.json
  26 + def new
  27 + @board = Board.new
  28 +
  29 + respond_to do |format|
  30 + format.html # new.html.erb
  31 + format.json { render json: @board }
  32 + end
  33 + end
  34 +
  35 + # GET /boards/1/edit
  36 + def edit
  37 + @board = Board.find(params[:id])
  38 + end
  39 +
  40 + # POST /boards
  41 + # POST /boards.json
  42 + def create
  43 + @board = Board.new(params[:board])
  44 +
  45 + respond_to do |format|
  46 + if @board.save
  47 + format.html { redirect_to @board, notice: 'Board was successfully created.' }
  48 + format.json { render json: @board, status: :created, location: @board }
  49 + else
  50 + format.html { render action: "new" }
  51 + format.json { render json: @board.errors, status: :unprocessable_entity }
  52 + end
  53 + end
  54 + end
  55 +
  56 + # PUT /boards/1
  57 + # PUT /boards/1.json
  58 + def update
  59 + @board = Board.find(params[:id])
  60 +
  61 + respond_to do |format|
  62 + if @board.update_attributes(params[:board])
  63 + format.html { redirect_to @board, notice: 'Board was successfully updated.' }
  64 + format.json { head :no_content }
  65 + else
  66 + format.html { render action: "edit" }
  67 + format.json { render json: @board.errors, status: :unprocessable_entity }
  68 + end
  69 + end
  70 + end
  71 +
  72 + # DELETE /boards/1
  73 + # DELETE /boards/1.json
  74 + def destroy
  75 + @board = Board.find(params[:id])
  76 + @board.destroy
  77 +
  78 + respond_to do |format|
  79 + format.html { redirect_to boards_url }
  80 + format.json { head :no_content }
  81 + end
  82 + end
  83 +end
3  app/controllers/topics_controller.rb
@@ -2,7 +2,8 @@ class TopicsController < ApplicationController
2 2 helper_method :depth_mark
3 3
4 4 def index
5   - @topics = Topic.all
  5 + @board = Board.find(params[:board_id])
  6 + @topics = @board.topics
6 7 end
7 8
8 9 def show
2  app/helpers/boards_helper.rb
... ... @@ -0,0 +1,2 @@
  1 +module BoardsHelper
  2 +end
5 app/models/board.rb
... ... @@ -0,0 +1,5 @@
  1 +class Board < ActiveRecord::Base
  2 + attr_accessible :acronym, :description, :name
  3 +
  4 + has_many :topics
  5 +end
3  app/models/topic.rb
... ... @@ -1,8 +1,9 @@
1 1 class Topic < ActiveRecord::Base
  2 + belongs_to :board
2 3 belongs_to :admin
3 4 has_many :comments
4 5
5   - attr_accessible :body, :subject, :parent
  6 + attr_accessible :body, :subject, :parent, :board
6 7 before_save :set_boardish
7 8
8 9 composed_of :boardish,
29 app/views/boards/_form.html.erb
... ... @@ -0,0 +1,29 @@
  1 +<%= form_for(@board) do |f| %>
  2 + <% if @board.errors.any? %>
  3 + <div id="error_explanation">
  4 + <h2><%= pluralize(@board.errors.count, "error") %> prohibited this board from being saved:</h2>
  5 +
  6 + <ul>
  7 + <% @board.errors.full_messages.each do |msg| %>
  8 + <li><%= msg %></li>
  9 + <% end %>
  10 + </ul>
  11 + </div>
  12 + <% end %>
  13 +
  14 + <div class="field">
  15 + <%= f.label :name %><br />
  16 + <%= f.text_field :name %>
  17 + </div>
  18 + <div class="field">
  19 + <%= f.label :acronym %><br />
  20 + <%= f.text_field :acronym %>
  21 + </div>
  22 + <div class="field">
  23 + <%= f.label :description %><br />
  24 + <%= f.text_area :description %>
  25 + </div>
  26 + <div class="actions">
  27 + <%= f.submit %>
  28 + </div>
  29 +<% end %>
6 app/views/boards/edit.html.erb
... ... @@ -0,0 +1,6 @@
  1 +<h1>Editing board</h1>
  2 +
  3 +<%= render 'form' %>
  4 +
  5 +<%= link_to 'Show', @board %> |
  6 +<%= link_to 'Back', boards_path %>
27 app/views/boards/index.html.erb
... ... @@ -0,0 +1,27 @@
  1 +<h1>Listing boards</h1>
  2 +
  3 +<table>
  4 + <tr>
  5 + <th>Name</th>
  6 + <th>Acronym</th>
  7 + <th>Description</th>
  8 + <th></th>
  9 + <th></th>
  10 + <th></th>
  11 + </tr>
  12 +
  13 +<% @boards.each do |board| %>
  14 + <tr>
  15 + <td><%= board.name %></td>
  16 + <td><%= board.acronym %></td>
  17 + <td><%= board.description %></td>
  18 + <td><%= link_to 'Show', board %></td>
  19 + <td><%= link_to 'Edit', edit_board_path(board) %></td>
  20 + <td><%= link_to 'Destroy', board, method: :delete, data: { confirm: 'Are you sure?' } %></td>
  21 + </tr>
  22 +<% end %>
  23 +</table>
  24 +
  25 +<br />
  26 +
  27 +<%= link_to 'New Board', new_board_path %>
5 app/views/boards/new.html.erb
... ... @@ -0,0 +1,5 @@
  1 +<h1>New board</h1>
  2 +
  3 +<%= render 'form' %>
  4 +
  5 +<%= link_to 'Back', boards_path %>
20 app/views/boards/show.html.erb
... ... @@ -0,0 +1,20 @@
  1 +<p id="notice"><%= notice %></p>
  2 +
  3 +<p>
  4 + <b>Name:</b>
  5 + <%= @board.name %>
  6 +</p>
  7 +
  8 +<p>
  9 + <b>Acronym:</b>
  10 + <%= @board.acronym %>
  11 +</p>
  12 +
  13 +<p>
  14 + <b>Description:</b>
  15 + <%= @board.description %>
  16 +</p>
  17 +
  18 +
  19 +<%= link_to 'Edit', edit_board_path(@board) %> |
  20 +<%= link_to 'Back', boards_path %>
4 config/routes.rb
... ... @@ -1,4 +1,8 @@
1 1 Rboard::Application.routes.draw do
  2 + resources :boards do
  3 + resources :topics
  4 + end
  5 +
2 6 resources :topics
3 7 resources :comments
4 8
11 db/migrate/20121121022941_create_boards.rb
... ... @@ -0,0 +1,11 @@
  1 +class CreateBoards < ActiveRecord::Migration
  2 + def change
  3 + create_table :boards do |t|
  4 + t.string :name
  5 + t.string :acronym
  6 + t.text :description
  7 +
  8 + t.timestamps
  9 + end
  10 + end
  11 +end
5 db/migrate/20121121023435_add_board_id_to_topic.rb
... ... @@ -0,0 +1,5 @@
  1 +class AddBoardIdToTopic < ActiveRecord::Migration
  2 + def change
  3 + add_column :topics, :board_id, :integer
  4 + end
  5 +end
11 db/schema.rb
@@ -11,7 +11,7 @@
11 11 #
12 12 # It's strongly recommended to check this file into your version control system.
13 13
14   -ActiveRecord::Schema.define(:version => 20121114072129) do
  14 +ActiveRecord::Schema.define(:version => 20121121023435) do
15 15
16 16 create_table "admins", :force => true do |t|
17 17 t.string "email"
@@ -21,6 +21,14 @@
21 21 t.datetime "updated_at", :null => false
22 22 end
23 23
  24 + create_table "boards", :force => true do |t|
  25 + t.string "name"
  26 + t.string "acronym"
  27 + t.text "description"
  28 + t.datetime "created_at", :null => false
  29 + t.datetime "updated_at", :null => false
  30 + end
  31 +
24 32 create_table "comments", :force => true do |t|
25 33 t.string "topic_id"
26 34 t.text "body"
@@ -35,6 +43,7 @@
35 43 t.integer "boardish"
36 44 t.datetime "created_at", :null => false
37 45 t.datetime "updated_at", :null => false
  46 + t.integer "board_id"
38 47 end
39 48
40 49 end
12 test/fixtures/boards.yml
... ... @@ -0,0 +1,12 @@
  1 +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
  2 +
  3 +one:
  4 + name: one
  5 + acronym: one
  6 + description: first board
  7 +
  8 +two:
  9 + name: two
  10 + acronym: two
  11 + description: first board
  12 +
7 test/fixtures/topics.yml
@@ -2,4 +2,9 @@
2 2
3 3 one:
4 4 subject: fixture_one
5   - body: body of one
  5 + body: body of one
  6 +
  7 +topic_belongs_to_board_two:
  8 + subject: topic_belongs_to_board_two
  9 + body: some body
  10 + board: two
49 test/functional/boards_controller_test.rb
... ... @@ -0,0 +1,49 @@
  1 +require 'test_helper'
  2 +
  3 +class BoardsControllerTest < ActionController::TestCase
  4 + setup do
  5 + @board = boards(:one)
  6 + end
  7 +
  8 + test "should get index" do
  9 + get :index
  10 + assert_response :success
  11 + assert_not_nil assigns(:boards)
  12 + end
  13 +
  14 + test "should get new" do
  15 + get :new
  16 + assert_response :success
  17 + end
  18 +
  19 + test "should create board" do
  20 + assert_difference('Board.count') do
  21 + post :create, board: { acronym: @board.acronym, description: @board.description, name: @board.name }
  22 + end
  23 +
  24 + assert_redirected_to board_path(assigns(:board))
  25 + end
  26 +
  27 + test "should show board" do
  28 + get :show, id: @board
  29 + assert_response :success
  30 + end
  31 +
  32 + test "should get edit" do
  33 + get :edit, id: @board
  34 + assert_response :success
  35 + end
  36 +
  37 + test "should update board" do
  38 + put :update, id: @board, board: { acronym: @board.acronym, description: @board.description, name: @board.name }
  39 + assert_redirected_to board_path(assigns(:board))
  40 + end
  41 +
  42 + test "should destroy board" do
  43 + assert_difference('Board.count', -1) do
  44 + delete :destroy, id: @board
  45 + end
  46 +
  47 + assert_redirected_to boards_path
  48 + end
  49 +end
3  test/functional/topics_controller_test.rb
@@ -3,10 +3,11 @@
3 3 class TopicsControllerTest < ActionController::TestCase
4 4 setup do
5 5 @topic = topics(:one)
  6 + @board = boards(:one)
6 7 end
7 8
8 9 test "should get index" do
9   - get :index
  10 + get :index, board_id: @board
10 11 assert_response :success
11 12 assert_not_nil assigns(:topics)
12 13 end
8 test/integration/board_flow_test.rb
... ... @@ -0,0 +1,8 @@
  1 +require 'test_helper'
  2 +
  3 +class BoardFlowTest < ActionDispatch::IntegrationTest
  4 + test "get url topics of boards(:one) " do
  5 + get board_topics_path(boards(:one))
  6 + assert_equal 0, assigns(:topics).size
  7 + end
  8 +end
7 test/unit/board_test.rb
... ... @@ -0,0 +1,7 @@
  1 +require 'test_helper'
  2 +
  3 +class BoardTest < ActiveSupport::TestCase
  4 + # test "the truth" do
  5 + # assert true
  6 + # end
  7 +end
4 test/unit/helpers/boards_helper_test.rb
... ... @@ -0,0 +1,4 @@
  1 +require 'test_helper'
  2 +
  3 +class BoardsHelperTest < ActionView::TestCase
  4 +end
9 test/unit/topic_test.rb
@@ -3,6 +3,13 @@
3 3 class TopicTest < ActiveSupport::TestCase
4 4 setup do
5 5 @topic = topics(:one)
  6 + @board = boards(:one)
  7 + end
  8 +
  9 + test "topic belongs to board" do
  10 + Topic.create(subject: @topic.subject, body: @topic.body, board: @board)
  11 +
  12 + assert_equal 1, boards(:two).topics.count
6 13 end
7 14
8 15 test "create new topic without parent" do
@@ -60,6 +67,6 @@ class TopicTest < ActiveSupport::TestCase
60 67 one_two_one=Topic.create(subject: "one_two_one", body: "one_two_one", parent: one_two)
61 68
62 69 subjects = Topic.all.map(&:subject)
63   - assert_equal %w(two two_one one one_one one_one_one one_two one_two_one one_three fixture_one), subjects
  70 + assert_equal %w(two two_one one one_one one_one_one one_two one_two_one one_three topic_belongs_to_board_two fixture_one), subjects
64 71 end
65 72 end

No commit comments for this range

Something went wrong with that request. Please try again.