Permalink
Browse files

topic controller.

  • Loading branch information...
ruseel committed Nov 14, 2012
1 parent 7f270be commit e1f52f994b0ef9034faa1fd1d885262219e1d126
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+// Place all the styles related to the topics controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,21 @@
+class TopicsController < ApplicationController
+ def index
+ @topics = Topic.all
+ end
+
+ def new
+ end
+
+ def create
+ @topic = Topic.new(params[:topic])
+ if @topic.save
+ redirect_to @topic, notice: 'Topic was created'
+ end
+ end
+
+ def edit
+ end
+
+ def destroy
+ end
+end
@@ -0,0 +1,2 @@
+module TopicsHelper
+end
View
@@ -21,7 +21,12 @@ def parent=(p)
def set_boardish
if self.boardish.nil?
t = self.class.last_root_topic
- self.boardish = (t ? t.boardish : Boardish.new(nil)).inc_at_depth(0)
+ if t.nil? || t.boardish.nil?
+ b = Boardish.new(nil)
+ else
+ b = t.boardish
+ end
+ self.boardish = b.inc_at_depth(0)
end
end
@@ -0,0 +1,2 @@
+<h1>Topics#create</h1>
+<p>Find me in app/views/topics/create.html.erb</p>
@@ -0,0 +1,2 @@
+<h1>Topics#destroy</h1>
+<p>Find me in app/views/topics/destroy.html.erb</p>
@@ -0,0 +1,2 @@
+<h1>Topics#edit</h1>
+<p>Find me in app/views/topics/edit.html.erb</p>
@@ -0,0 +1,2 @@
+<h1>Topics#index</h1>
+<p>Find me in app/views/topics/index.html.erb</p>
@@ -0,0 +1,2 @@
+<h1>Topics#new</h1>
+<p>Find me in app/views/topics/new.html.erb</p>
View
@@ -1,4 +1,6 @@
Rboard::Application.routes.draw do
+ resources :topics
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
@@ -1,2 +1,5 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+one:
+ subject: fixture_one
+ body: body of one
@@ -0,0 +1,37 @@
+require 'test_helper'
+
+class TopicsControllerTest < ActionController::TestCase
+ setup do
+ @topic = topics(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:topics)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should get create" do
+ assert_difference('Topic.count') do
+ post :create, topic: { subject: @topic.subject, body: @topic.body }
+ end
+
+ assert_redirected_to topic_path(assigns(:topic))
+ end
+
+ test "should get edit" do
+ get :edit, id: @topic
+ assert_response :success
+ end
+
+ test "should get destroy" do
+ delete :destroy, id: @topic
+ assert_response :success
+ end
+
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class TopicsHelperTest < ActionView::TestCase
+end
View
@@ -45,6 +45,6 @@ def admin
assert_equal Boardish.from_array([1, 7, 7]), one.boardish
assert_equal Boardish.from_array([1, 6, 7]), one_one.boardish
- assert_equal ["two", "two_one", "one", "one_one"], subjects
+ assert_equal ["two", "two_one", "one", "one_one", "fixture_one"], subjects
end
end

0 comments on commit e1f52f9

Please sign in to comment.