additional functional tests, some controller fixes

This commit is contained in:
albert
2010-12-01 18:50:04 -05:00
parent 39dd2e277a
commit 976a25a6c6
19 changed files with 185 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
class ArtistsController < ApplicationController
before_filter :member_only
before_filter :member_only, :except => [:index, :show]
def new
@artist = Artist.new_with_defaults(params)
@@ -48,7 +48,8 @@ class ArtistsController < ApplicationController
def revert
@artist = Artist.find(params[:id])
@artist.revert_to!(params[:version])
@version = ArtistVersion.find(params[:version_id])
@artist.revert_to!(@version)
redirect_to artist_path(@artist), :notice => "Artist updated"
end
end

View File

@@ -20,6 +20,8 @@ class BansController < ApplicationController
def create
@ban = Ban.new(params[:ban])
@ban.banner_id = CurrentUser.id
if @ban.save
redirect_to ban_path(@ban), :notice => "Ban created"
else
@@ -39,5 +41,6 @@ class BansController < ApplicationController
def destroy
@ban = Ban.find(params[:id])
@ban.destroy
redirect_to bans_path, :notice => "Ban destroyed"
end
end

View File

@@ -19,8 +19,7 @@ class CommentsController < ApplicationController
@comment.save
respond_with(@comment) do |format|
format.html do
flash[:notice] = "Comment posted"
redirect_to posts_path(@comment.post)
redirect_to post_path(@comment.post), :notice => "Comment posted"
end
format.js

View File

@@ -7,6 +7,7 @@ class Artist < ActiveRecord::Base
belongs_to :creator, :class_name => "User"
has_many :members, :class_name => "Artist", :foreign_key => "group_name", :primary_key => "name"
has_many :urls, :dependent => :destroy, :class_name => "ArtistUrl"
has_many :versions, :order => "artist_versions.id", :class_name => "ArtistVersion"
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
has_one :tag_alias, :foreign_key => "antecedent_name", :primary_key => "name"
accepts_nested_attributes_for :wiki_page

View File

@@ -38,6 +38,14 @@ class Ban < ActiveRecord::Base
end
end
def user_name
user ? user.name : nil
end
def user_name=(username)
self.user_id = User.name_to_id(username)
end
def duration=(dur)
self.expires_at = dur.to_i.days.from_now
@duration = dur

View File

@@ -11,7 +11,7 @@
</thead>
<tbody>
<% @artists.each do |artist| %>
<% content_tag(:tr, :id => "artist-#{artist.id}") do %>
<%= content_tag(:tr, :id => "artist-#{artist.id}") do %>
<td>
<%= link_to "P", posts_path(:tags => artist.name), :title => "Find posts for artist" %>
<%= link_to "E", edit_artist_path(artist), :title => "Edit artist" %>

View File

@@ -1,7 +1,7 @@
<div class="bans">
<div class="new">
<h1>Edit Ban</h1>
<%= render "form", :locals => {:ban => @ban} %>
<%= render :partial => "form", :locals => {:ban => @ban} %>
</div>
</div>

View File

@@ -12,7 +12,7 @@
<tbody>
<% @bans.each do |ban| %>
<tr id="ban-<%= ban.id %>">
<td><%= ban.user_name %></td>
<td><%= ban.user.name %></td>
<td><%= ban.expires_at %></td>
<td><%= ban.reason %></td>
<td>

View File

@@ -1,7 +1,7 @@
<div class="bans">
<div class="new">
<h1>New Ban</h1>
<%= render "form", :locals => {:ban => @ban} %>
<%= render :partial => "form", :locals => {:ban => @ban} %>
</div>
</div>

View File

@@ -2,7 +2,7 @@
<div class="show">
<h1>Show Ban</h1>
<ul>
<li><strong>User</strong>: <%= @ban.user_name %></li>
<li><strong>User</strong>: <%= @ban.user.name %></li>
<li><strong>Expires</strong>: <%= @ban.expires_at %></li>
<li><strong>Reason</strong>: <%= @ban.reason %></li>
</ul>

View File

@@ -0,0 +1,3 @@
<% if @error %>
alert(<%= escape_javascript(@error.to_s) %>);
<% end %>

View File

@@ -1,3 +0,0 @@
if @error
page.alert(@error.to_s)
end

View File

@@ -5,7 +5,7 @@
<div class="preview">
<%= link_to(image_tag(post.preview_file_url), post_path(post)) %>
</div>
<%= render "comments/partials/index/list", :locals => {:post => post, :comments => post.comments.recent.reverse, :show_header => true} %>
<%= render :partial => "comments/partials/index/list", :locals => {:post => post, :comments => post.comments.recent.reverse, :show_header => true} %>
<div class="clearfix"></div>
</div>
<% end %>

View File

@@ -1,6 +1,6 @@
Factory.define(:ban) do |f|
f.user {|x| x.association(:user)}
f.banner {|x| x.association(:admin_user)}
f.reason {Faker::Lorem.words}
f.reason {Faker::Lorem.words.join(" ")}
f.duration 60
end

View File

@@ -1,5 +1,5 @@
Factory.define(:comment) do |f|
f.post {|x| x.association(:post)}
f.body {Faker::Lorem.sentences}
f.body {Faker::Lorem.sentences.join(" ")}
f.score 0
end

View File

@@ -1,8 +1,59 @@
require 'test_helper'
class ArtistsControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
context "An artists controller" do
setup do
CurrentUser.user = Factory.create(:user)
CurrentUser.ip_addr = "127.0.0.1"
@artist = Factory.create(:artist)
@user = Factory.create(:user)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "render the new page" do
get :new, {}, {:user_id => @user.id}
assert_response :success
end
should "render the edit page" do
get :edit, {:id => @artist.id}, {:user_id => @user.id}
assert_response :success
end
should "render the show page" do
get :show, {:id => @artist.id}
assert_response :success
end
should "render the index page" do
get :index
assert_response :success
end
should "create an artist" do
assert_difference("Artist.count", 1) do
post :create, {:artist => Factory.attributes_for(:artist)}, {:user_id => @user.id}
end
artist = Artist.last
assert_redirected_to(artist_path(artist))
end
should "update an artist" do
post :update, {:id => @artist.id, :artist => {:name => "xxx"}}, {:user_id => @user.id}
artist = Artist.last
assert_equal("xxx", artist.name)
assert_redirected_to(artist_path(artist))
end
should "revert an artist" do
@artist.update_attributes(:name => "xyz")
@artist.update_attributes(:name => "abc")
version = @artist.versions.first
post :revert, {:id => @artist.id, :version_id => version.id}
end
end
end

View File

@@ -1,8 +1,59 @@
require 'test_helper'
class BansControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
context "A bans controller" do
setup do
CurrentUser.user = Factory.create(:user)
CurrentUser.ip_addr = "127.0.0.1"
@ban = Factory.create(:ban)
@user = Factory.create(:moderator_user)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "render the new page" do
get :new, {}, {:user_id => @user.id}
assert_response :success
end
should "render the edit page" do
get :edit, {:id => @ban.id}, {:user_id => @user.id}
assert_response :success
end
should "render the show page" do
get :show, {:id => @ban.id}
assert_response :success
end
should "render the index page" do
get :index
assert_response :success
end
should "create a ban" do
assert_difference("Ban.count", 1) do
post :create, {:ban => Factory.attributes_for(:ban)}, {:user_id => @user.id}
end
ban = Ban.last
assert_redirected_to(ban_path(ban))
end
should "update a ban" do
post :update, {:id => @ban.id, :ban => {:reason => "xxx"}}, {:user_id => @user.id}
ban = Ban.last
assert_equal("xxx", ban.reason)
assert_redirected_to(ban_path(ban))
end
should "destroy a ban" do
assert_difference("Ban.count", -1) do
post :destroy, {:id => @ban.id}, {:user_id => @user.id}
end
assert_redirected_to(bans_path)
end
end
end

View File

@@ -1,8 +1,24 @@
require 'test_helper'
class CommentVotesControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
context "A comment votes controller" do
setup do
CurrentUser.user = Factory.create(:user)
CurrentUser.ip_addr = "127.0.0.1"
@comment = Factory.create(:comment)
@user = Factory.create(:user)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "create a vote" do
assert_difference("CommentVote.count", 1) do
post :create, {:format => "js", :comment_id => @comment.id}, {:user_id => @user.id}
assert_response :success
end
end
end
end

View File

@@ -1,8 +1,36 @@
require 'test_helper'
class CommentsControllerTest < ActionController::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
context "A comments controller" do
setup do
CurrentUser.user = Factory.create(:user)
CurrentUser.ip_addr = "127.0.0.1"
@comment = Factory.create(:comment)
@user = Factory.create(:moderator_user)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "render the index page" do
get :index
assert_response :success
end
should "update a comment" do
post :update, {:id => @comment.id, :comment => {:body => "abc"}}, {:user_id => @comment.creator_id}
assert_redirected_to comment_path(@comment)
end
should "create a comment" do
p = Factory.create(:post)
assert_difference("Comment.count", 1) do
post :create, {:comment => Factory.attributes_for(:comment, :post_id => p.id)}, {:user_id => @user.id}
end
comment = Comment.last
assert_redirected_to post_path(comment.post)
end
end
end