From 0de90d487b0ce6d478a27b689b06dbf5dab2a439 Mon Sep 17 00:00:00 2001 From: albert Date: Sat, 22 Oct 2011 19:01:27 -0400 Subject: [PATCH] fixed tests --- app/models/artist.rb | 1 + app/models/forum_post.rb | 3 ++- app/models/forum_topic.rb | 3 ++- app/models/post.rb | 3 ++- app/models/user.rb | 14 +++----------- test/functional/artists_controller_test.rb | 6 +++--- test/functional/ip_bans_controller_test.rb | 2 +- test/unit/artist_test.rb | 3 +-- test/unit/pool_test.rb | 4 ++-- test/unit/post_test.rb | 4 ++-- 10 files changed, 19 insertions(+), 24 deletions(-) diff --git a/app/models/artist.rb b/app/models/artist.rb index 3a2a45e7e..6418930ff 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -13,6 +13,7 @@ class Artist < ActiveRecord::Base has_one :tag_alias, :foreign_key => "antecedent_name", :primary_key => "name" accepts_nested_attributes_for :wiki_page attr_accessible :name, :url_string, :other_names, :group_name, :wiki_page_attributes, :notes, :is_active + attr_accessible :name, :url_string, :other_names, :group_name, :wiki_page_attributes, :notes, :is_active, :as => [:member, :moderator] attr_accessible :name, :url_string, :other_names, :group_name, :wiki_page_attributes, :notes, :is_active, :is_banned, :as => :admin scope :url_match, lambda {|string| where(["id in (?)", Artist.find_all_by_url(string).map(&:id)])} scope :other_names_match, lambda {|string| where(["other_names_index @@ to_tsquery('danbooru', ?)", Artist.normalize_name(string)])} diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 730403473..0a273a64c 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -1,6 +1,7 @@ class ForumPost < ActiveRecord::Base attr_accessible :body, :topic_id - attr_accessible :body, :topic_id, :is_locked, :is_sticky, :as => [:admin, :moderator, :janitor] + attr_accessible :body, :topic_id, :as => [:member] + attr_accessible :body, :topic_id, :is_locked, :is_sticky, :as => [:admin, :moderator] belongs_to :creator, :class_name => "User" belongs_to :topic, :class_name => "ForumTopic" before_validation :initialize_creator, :on => :create diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index 1767f0f35..29b1f245b 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -1,6 +1,7 @@ class ForumTopic < ActiveRecord::Base attr_accessible :title, :original_post_attributes - attr_accessible :title, :original_post_attributes, :is_sticky, :is_locked, :as => [:admin, :moderator, :janitor] + attr_accessible :title, :original_post_attributes, :as => [:member] + attr_accessible :title, :original_post_attributes, :is_sticky, :is_locked, :as => [:admin, :moderator] belongs_to :creator, :class_name => "User" belongs_to :updater, :class_name => "User" has_many :posts, :class_name => "ForumPost", :order => "forum_posts.id asc", :foreign_key => "topic_id", :dependent => :destroy diff --git a/app/models/post.rb b/app/models/post.rb index 51e5d9294..64832df52 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -31,7 +31,8 @@ class Post < ActiveRecord::Base validates_presence_of :parent, :if => lambda {|rec| !rec.parent_id.nil?} validate :validate_parent_does_not_have_a_parent attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at, :parent_id - attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at, :parent_id, :is_rating_locked, :is_note_locked, :as => [:admin, :moderator, :janitor] + attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at, :parent_id, :as => [:member] + attr_accessible :source, :rating, :tag_string, :old_tag_string, :last_noted_at, :parent_id, :is_rating_locked, :is_note_locked, :as => [:admin, :moderator] scope :pending, where(["is_pending = ?", true]) scope :pending_or_flagged, where(["(is_pending = ? OR is_flagged = ?)", true, true]) scope :undeleted, where(["is_deleted = ?", false]) diff --git a/app/models/user.rb b/app/models/user.rb index 2b96a69d2..58448929d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,6 +15,7 @@ class User < ActiveRecord::Base attr_accessor :password, :old_password attr_accessible :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size + attr_accessible :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :as => [:moderator, :member] attr_accessible :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :level, :as => :admin validates_length_of :name, :within => 2..100, :on => :create validates_format_of :name, :with => /\A[^\s:]+\Z/, :on => :create, :message => "cannot have whitespace or colons" @@ -217,19 +218,10 @@ class User < ActiveRecord::Base def role case level - when Levels::MEMBER + when Levels::MEMBER, Levels::PRIVILEGED, Levels::CONTRIBUTOR :member - when Levels::PRIVILEGED - :privileged - - when Levels::CONTRIBUTOR - :contributor - - when Levels::JANITOR - :janitor - - when Levels::MODERATOR + when Levels::MODERATOR, Levels::JANITOR :moderator when Levels::ADMIN diff --git a/test/functional/artists_controller_test.rb b/test/functional/artists_controller_test.rb index 73d11fd5d..e5c5a5293 100644 --- a/test/functional/artists_controller_test.rb +++ b/test/functional/artists_controller_test.rb @@ -44,9 +44,9 @@ class ArtistsControllerTest < ActionController::TestCase 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)) + @artist.reload + assert_equal("xxx", @artist.name) + assert_redirected_to(artist_path(@artist)) end should "revert an artist" do diff --git a/test/functional/ip_bans_controller_test.rb b/test/functional/ip_bans_controller_test.rb index 27513ddec..984d58728 100644 --- a/test/functional/ip_bans_controller_test.rb +++ b/test/functional/ip_bans_controller_test.rb @@ -48,7 +48,7 @@ class IpBansControllerTest < ActionController::TestCase should "destroy an ip ban" do assert_difference("IpBan.count", -1) do - post :destroy, {:id => @ip_ban.id}, {:user_id => @admin.id} + post :destroy, {:id => @ip_ban.id, :format => "js"}, {:user_id => @admin.id} end end end diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index 2cd6bf03a..208ec71d2 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -18,8 +18,7 @@ class ArtistTest < ActiveSupport::TestCase setup do @post = Factory.create(:post, :tag_string => "aaa") @artist = Factory.create(:artist, :name => "aaa") - @artist.reload - @artist.update_attributes(:is_banned => true, :as => :admin) + @artist.update_attributes({:is_banned => true}, :as => :admin) @post.reload end diff --git a/test/unit/pool_test.rb b/test/unit/pool_test.rb index 73a7bd22d..cfffc2977 100644 --- a/test/unit/pool_test.rb +++ b/test/unit/pool_test.rb @@ -15,11 +15,11 @@ class PoolTest < ActiveSupport::TestCase context "A name" do setup do - @pool = Factory.create(:pool) + @pool = Factory.create(:pool, :name => "xxx") end should "be mapped to a pool id" do - assert_equal(@pool.id, Pool.name_to_id(@pool.name)) + assert_equal(@pool.id, Pool.name_to_id("xxx")) end end diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 7b0da7918..eac99a32f 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -584,9 +584,9 @@ class PostTest < ActiveSupport::TestCase post1 = Factory.create(:post) post2 = Factory.create(:post) post3 = Factory.create(:post) - pool = Factory.create(:pool) + pool = Factory.create(:pool, :name => "xxx") post1.add_pool!(pool) - relation = Post.tag_match("pool:#{pool.name}") + relation = Post.tag_match("pool:xxx") assert_equal(1, relation.count) assert_equal(post1.id, relation.first.id) end