wiki page func test
This commit is contained in:
@@ -1,25 +1,49 @@
|
||||
class WikiPagesController < ApplicationController
|
||||
respond_to :html, :xml, :json
|
||||
before_filter :member_only, :except => [:index, :show]
|
||||
before_filter :moderator_only, :only => [:destroy]
|
||||
|
||||
def new
|
||||
@wiki_page = WikiPage.new
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
|
||||
def edit
|
||||
@wiki_page = WikiPage.find(params[:id])
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
|
||||
def index
|
||||
@search = WikiPage.search(params[:search])
|
||||
@wiki_pages = @search.paginate(:page => params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
@wiki_page = WikiPage.find(params[:id])
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
|
||||
def create
|
||||
@wiki_page = WikiPage.create(params[:wiki_page])
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
|
||||
def update
|
||||
@wiki_page = WikiPage.find(params[:id])
|
||||
@wiki_page.update_attributes(params[:wiki_page])
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@wiki_page = WikiPage.find(params[:id])
|
||||
@wiki_page.destroy
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
|
||||
def revert
|
||||
@wiki_page = WikiPage.find(params[:id])
|
||||
@version = WikiPageVersion.find(params[:version_id])
|
||||
@wiki_page.revert_to!(@version)
|
||||
respond_with(@wiki_page)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ class WikiPage < ActiveRecord::Base
|
||||
scope :titled, lambda {|title| where(["title = ?", title.downcase.tr(" ", "_")])}
|
||||
has_one :tag, :foreign_key => "name", :primary_key => "title"
|
||||
has_one :artist, :foreign_key => "name", :primary_key => "title"
|
||||
has_many :versions, :class_name => "WikiPageVersion"
|
||||
has_many :versions, :class_name => "WikiPageVersion", :dependent => :destroy
|
||||
|
||||
def self.build_relation(options = {})
|
||||
relation = where()
|
||||
|
||||
0
app/views/wiki_pages/edit.html.erb
Normal file
0
app/views/wiki_pages/edit.html.erb
Normal file
0
app/views/wiki_pages/index.html.erb
Normal file
0
app/views/wiki_pages/index.html.erb
Normal file
0
app/views/wiki_pages/new.html.erb
Normal file
0
app/views/wiki_pages/new.html.erb
Normal file
0
app/views/wiki_pages/show.html.erb
Normal file
0
app/views/wiki_pages/show.html.erb
Normal file
@@ -1,8 +1,91 @@
|
||||
require 'test_helper'
|
||||
|
||||
class WikiPagesControllerTest < ActionController::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
context "The wiki pages controller" do
|
||||
setup do
|
||||
@user = Factory.create(:user)
|
||||
@mod = Factory.create(:moderator_user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
Factory.create(:wiki_page, :title => "abc")
|
||||
end
|
||||
|
||||
should "list all wiki_pages" do
|
||||
get :index
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "list all wiki_pages (with search)" do
|
||||
get :index, {:search => {:title_matches => "abc"}}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "show action" do
|
||||
setup do
|
||||
@wiki_page = Factory.create(:wiki_page)
|
||||
end
|
||||
|
||||
should "render" do
|
||||
get :show, {:id => @wiki_page.id}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "create a wiki_page" do
|
||||
assert_difference("WikiPage.count", 1) do
|
||||
post :create, {:wiki_page => {:title => "abc", :body => "abc"}}, {:user_id => @user.id}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
setup do
|
||||
@wiki_page = Factory.create(:wiki_page)
|
||||
end
|
||||
|
||||
should "update a wiki_page" do
|
||||
post :update, {:id => @wiki_page.id, :wiki_page => {:body => "xyz"}}, {:user_id => @user.id}
|
||||
@wiki_page.reload
|
||||
assert_equal("xyz", @wiki_page.body)
|
||||
end
|
||||
end
|
||||
|
||||
context "destroy action" do
|
||||
setup do
|
||||
@wiki_page = Factory.create(:wiki_page)
|
||||
end
|
||||
|
||||
should "destroy a wiki_page" do
|
||||
assert_difference("WikiPage.count", -1) do
|
||||
post :destroy, {:id => @wiki_page.id}, {:user_id => @mod.id}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "revert action" do
|
||||
setup do
|
||||
@wiki_page = Factory.create(:wiki_page, :body => "1")
|
||||
@wiki_page.update_attributes(:body => "1 2")
|
||||
@wiki_page.update_attributes(:body => "1 2 3")
|
||||
end
|
||||
|
||||
should "revert to a previous version" do
|
||||
version = @wiki_page.versions(true).last
|
||||
assert_equal("1", version.body)
|
||||
post :revert, {:id => @wiki_page.id, :version_id => version.id}
|
||||
@wiki_page.reload
|
||||
assert_equal("1", @wiki_page.body)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user