'
html << DText.parse_inline(flag.reason).html_safe
- if CurrentUser.is_janitor?
+ if CurrentUser.is_moderator?
html << ' - ' + link_to_user(flag.creator)
end
diff --git a/app/logical/anonymous_user.rb b/app/logical/anonymous_user.rb
index 91f1d6260..8d44c5ec0 100644
--- a/app/logical/anonymous_user.rb
+++ b/app/logical/anonymous_user.rb
@@ -108,6 +108,10 @@ class AnonymousUser
false
end
+ def can_approve_posts?
+ false
+ end
+
def blacklisted_tags
""
end
diff --git a/app/models/artist.rb b/app/models/artist.rb
index 9d8a69f1f..913323874 100644
--- a/app/models/artist.rb
+++ b/app/models/artist.rb
@@ -329,7 +329,7 @@ class Artist < ActiveRecord::Base
end
def other_names_match(string)
- if string =~ /\*/ && CurrentUser.user.is_builder?
+ if string =~ /\*/ && CurrentUser.is_builder?
where("other_names ILIKE ? ESCAPE E'\\\\'", string.to_escaped_for_sql_like)
else
where("other_names_index @@ to_tsquery('danbooru', E?)", Artist.normalize_name(string).to_escaped_for_tsquery)
@@ -352,7 +352,7 @@ class Artist < ActiveRecord::Base
def any_name_matches(name)
stripped_name = normalize_name(name).to_escaped_for_sql_like
- if name =~ /\*/ && CurrentUser.user.is_builder?
+ if name =~ /\*/ && CurrentUser.is_builder?
where("(name LIKE ? ESCAPE E'\\\\' OR other_names LIKE ? ESCAPE E'\\\\')", stripped_name, stripped_name)
else
name_for_tsquery = normalize_name(name).to_escaped_for_tsquery
@@ -479,6 +479,6 @@ class Artist < ActiveRecord::Base
end
def visible?
- !is_banned? || CurrentUser.user.is_janitor?
+ !is_banned? || CurrentUser.is_moderator?
end
end
diff --git a/app/models/bulk_update_request.rb b/app/models/bulk_update_request.rb
index 3d68f4c2e..dbed01292 100644
--- a/app/models/bulk_update_request.rb
+++ b/app/models/bulk_update_request.rb
@@ -61,7 +61,7 @@ class BulkUpdateRequest < ActiveRecord::Base
end
def editable?(user)
- user_id == user.id || user.is_janitor?
+ user_id == user.id || user.is_builder?
end
def create_forum_topic
diff --git a/app/models/comment.rb b/app/models/comment.rb
index f8cbc35ff..fae80c47a 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -165,7 +165,7 @@ class Comment < ActiveRecord::Base
end
def editable_by?(user)
- creator_id == user.id || user.is_janitor?
+ creator_id == user.id || user.is_moderator?
end
def hidden_attributes
diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb
index 2e57ec473..846f2a102 100644
--- a/app/models/forum_post.rb
+++ b/app/models/forum_post.rb
@@ -92,7 +92,7 @@ class ForumPost < ActiveRecord::Base
end
def validate_topic_is_unlocked
- return if CurrentUser.user.is_janitor?
+ return if CurrentUser.user.is_moderator?
return if topic.nil?
if topic.is_locked?
@@ -110,7 +110,7 @@ class ForumPost < ActiveRecord::Base
end
def editable_by?(user)
- creator_id == user.id || user.is_janitor?
+ creator_id == user.id || user.is_moderator?
end
def update_topic_updated_at_on_create
diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb
index c6f0a8b91..c6108cb3f 100644
--- a/app/models/forum_topic.rb
+++ b/app/models/forum_topic.rb
@@ -119,7 +119,7 @@ class ForumTopic < ActiveRecord::Base
include SubscriptionMethods
def editable_by?(user)
- creator_id == user.id || user.is_janitor?
+ creator_id == user.id || user.is_moderator?
end
def initialize_is_deleted
diff --git a/app/models/janitor_trial.rb b/app/models/janitor_trial.rb
index 2b1927172..d9b3e022d 100644
--- a/app/models/janitor_trial.rb
+++ b/app/models/janitor_trial.rb
@@ -1,6 +1,5 @@
class JanitorTrial < ActiveRecord::Base
belongs_to :user
- before_create :initialize_original_level
after_create :send_dmail
after_create :promote_user
validates_presence_of :user
@@ -54,10 +53,6 @@ class JanitorTrial < ActiveRecord::Base
self.creator_id = CurrentUser.id
end
- def initialize_original_level
- self.original_level = user.level
- end
-
def user_name
user.try(:name)
end
@@ -67,13 +62,14 @@ class JanitorTrial < ActiveRecord::Base
end
def send_dmail
- body = "You have been selected as a test janitor. You can now approve pending posts and have access to the moderation interface. You should reacquaint yourself with the [[howto:upload]] guide to make sure you understand the site rules.\n\nOver the next several weeks your approvals will be monitored. If the majority of them are not quality uploads you will fail the trial period and be demoted back to your original level. You will also receive a negative user record indicating you previously attempted and failed a test janitor trial.\n\nThere is a minimum quota of 1 approval a month to indicate that you are being active. Remember, the goal isn't to approve as much as possible. It's to filter out borderline-quality art.\n\nIf you have any questions please respond to this message."
+ body = "You have been selected as a test janitor. You can now approve pending posts and have access to the moderation interface. You should reacquaint yourself with the [[howto:upload]] guide to make sure you understand the site rules.\n\nOver the next several weeks your approvals will be monitored. If the majority of them are not quality uploads you will fail the trial period and lose your approval privileges. You will also receive a negative user record indicating you previously attempted and failed a test janitor trial.\n\nThere is a minimum quota of 1 approval a month to indicate that you are being active. Remember, the goal isn't to approve as much as possible. It's to filter out borderline-quality art.\n\nIf you have any questions please respond to this message."
Dmail.create_split(:title => "Test Janitor Trial Period", :body => body, :to_id => user_id)
end
def promote_user
- user.promote_to!(User::Levels::JANITOR, :skip_dmail => true)
+ user.can_approve_posts = true
+ user.save
end
def create_feedback
@@ -88,8 +84,9 @@ class JanitorTrial < ActiveRecord::Base
end
def demote!
+ user.can_approve_posts = false
+ user.save
update_attribute(:status, "inactive")
- user.update_column(:level, original_level)
self.create_feedback
end
diff --git a/app/models/pool.rb b/app/models/pool.rb
index 6636b84b6..a9fde03bb 100644
--- a/app/models/pool.rb
+++ b/app/models/pool.rb
@@ -207,7 +207,7 @@ class Pool < ActiveRecord::Base
end
def deletable_by?(user)
- user.is_janitor?
+ user.is_moderator?
end
def create_mod_action_for_delete
diff --git a/app/models/post_flag.rb b/app/models/post_flag.rb
index 339b558ea..5a819d438 100644
--- a/app/models/post_flag.rb
+++ b/app/models/post_flag.rb
@@ -46,11 +46,11 @@ class PostFlag < ActiveRecord::Base
q = q.reason_matches(params[:reason_matches])
end
- if params[:creator_id].present? && (CurrentUser.user.is_janitor? || params[:creator_id].to_i == CurrentUser.user.id)
+ if params[:creator_id].present? && (CurrentUser.is_moderator? || params[:creator_id].to_i == CurrentUser.user.id)
q = q.where("creator_id = ?", params[:creator_id].to_i)
end
- if params[:creator_name].present? && CurrentUser.user.is_janitor?
+ if params[:creator_name].present? && CurrentUser.is_moderator?
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].mb_chars.downcase.strip.tr(" ", "_"))
end
@@ -84,7 +84,7 @@ class PostFlag < ActiveRecord::Base
end
def validate_creator_is_not_limited
- if CurrentUser.is_janitor?
+ if CurrentUser.can_approve_posts?
# do nothing
elsif creator.created_at > 1.week.ago
errors[:creator] << "cannot flag within the first week of sign up"
diff --git a/app/models/tag.rb b/app/models/tag.rb
index 7435c7498..78922e18a 100644
--- a/app/models/tag.rb
+++ b/app/models/tag.rb
@@ -2,7 +2,7 @@ class Tag < ActiveRecord::Base
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|favgroup|-fav|fav|ordfav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|-parent|child|pixiv_id|pixiv"
SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm"
attr_accessible :category, :as => [:moderator, :janitor, :contributor, :gold, :member, :anonymous, :default, :builder, :admin]
- attr_accessible :is_locked, :as => [:moderator, :janitor, :admin]
+ attr_accessible :is_locked, :as => [:moderator, :admin]
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
module ApiMethods
diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb
index f5f6e5bd7..64fa993df 100644
--- a/app/models/tag_alias.rb
+++ b/app/models/tag_alias.rb
@@ -224,7 +224,7 @@ class TagAlias < ActiveRecord::Base
def deletable_by?(user)
return true if user.is_admin?
- return true if is_pending? && user.is_janitor?
+ return true if is_pending? && user.can_approve_posts?
return true if is_pending? && user.id == creator_id
return false
end
diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb
index 7acb79760..534b09763 100644
--- a/app/models/tag_implication.rb
+++ b/app/models/tag_implication.rb
@@ -207,7 +207,7 @@ class TagImplication < ActiveRecord::Base
def deletable_by?(user)
return true if user.is_admin?
- return true if is_pending? && user.is_janitor?
+ return true if is_pending? && user.is_builder?
return true if is_pending? && user.id == creator_id
return false
end
diff --git a/app/models/user.rb b/app/models/user.rb
index fcb9aacdf..5143e552a 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -29,7 +29,8 @@ class User < ActiveRecord::Base
:style_usernames => 0x0200,
:enable_auto_complete => 0x0400,
:show_deleted_children => 0x0800,
- :has_saved_searches => 0x1000
+ :has_saved_searches => 0x1000,
+ :can_approve_posts => 0x2000
}
attr_accessor :password, :old_password
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index e25d9250a..b90d643f4 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -9,7 +9,7 @@ class WikiPage < ActiveRecord::Base
belongs_to :updater, :class_name => "User"
validates_uniqueness_of :title, :case_sensitive => false
validates_presence_of :title
- validate :validate_locker_is_janitor
+ validate :validate_locker_is_moderator
validate :validate_not_locked
attr_accessible :title, :body, :is_locked, :other_names
has_one :tag, :foreign_key => "name", :primary_key => "title"
@@ -112,15 +112,15 @@ class WikiPage < ActiveRecord::Base
titled(title).select("title, id").first
end
- def validate_locker_is_janitor
- if is_locked_changed? && !CurrentUser.is_janitor?
- errors.add(:is_locked, "can be modified by janitors only")
+ def validate_locker_is_moderator
+ if is_locked_changed? && !CurrentUser.is_moderator?
+ errors.add(:is_locked, "can be modified by moderators only")
return false
end
end
def validate_not_locked
- if is_locked? && !CurrentUser.is_janitor?
+ if is_locked? && !CurrentUser.is_moderator?
errors.add(:is_locked, "and cannot be updated")
return false
end
@@ -230,7 +230,7 @@ class WikiPage < ActiveRecord::Base
end
def visible?
- artist.blank? || !artist.is_banned? || CurrentUser.user.is_janitor?
+ artist.blank? || !artist.is_banned? || CurrentUser.is_moderator?
end
def other_names_array
diff --git a/app/models/wiki_page_version.rb b/app/models/wiki_page_version.rb
index dbf269bce..14d35f9f8 100644
--- a/app/models/wiki_page_version.rb
+++ b/app/models/wiki_page_version.rb
@@ -40,7 +40,7 @@ class WikiPageVersion < ActiveRecord::Base
end
def visible?
- artist.blank? || !artist.is_banned? || CurrentUser.user.is_janitor?
+ artist.blank? || !artist.is_banned? || CurrentUser.is_moderator?
end
def other_names_array
diff --git a/app/views/artist_commentary_versions/index.html.erb b/app/views/artist_commentary_versions/index.html.erb
index d53ed82d6..91e2c5124 100644
--- a/app/views/artist_commentary_versions/index.html.erb
+++ b/app/views/artist_commentary_versions/index.html.erb
@@ -8,7 +8,7 @@
Post
Original
Translated
- <% if CurrentUser.is_janitor? %>
+ <% if CurrentUser.is_moderator? %>
IP Address
<% end %>
Edited By
@@ -30,7 +30,7 @@
<%= h(commentary_version.translated_title) %>
<%= h(commentary_version.translated_description) %>
- <% if CurrentUser.is_janitor? %>
+ <% if CurrentUser.is_moderator? %>
<% end %>
- <% if CurrentUser.is_janitor? %>
+ <% if CurrentUser.is_moderator? %>
<%= link_to "Delete", wiki_page_path(@wiki_page), :remote => true, :method => :delete, :data => {:confirm => "Are you sure you want to delete this wiki page?"} %>
<% end %>
<% end %>
diff --git a/db/migrate/20150629235905_remove_not_null_on_janitor_trials.rb b/db/migrate/20150629235905_remove_not_null_on_janitor_trials.rb
new file mode 100644
index 000000000..88209fd48
--- /dev/null
+++ b/db/migrate/20150629235905_remove_not_null_on_janitor_trials.rb
@@ -0,0 +1,5 @@
+class RemoveNotNullOnJanitorTrials < ActiveRecord::Migration
+ def change
+ change_column :janitor_trials, :original_level, :integer, :null => true
+ end
+end
diff --git a/db/structure.sql b/db/structure.sql
index 0592e90c1..df8953e33 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -668,8 +668,7 @@ CREATE TABLE artist_versions (
url_string text,
is_banned boolean DEFAULT false NOT NULL,
created_at timestamp without time zone,
- updated_at timestamp without time zone,
- normalized_url_string text
+ updated_at timestamp without time zone
);
@@ -979,6 +978,40 @@ CREATE SEQUENCE dmails_id_seq
ALTER SEQUENCE dmails_id_seq OWNED BY dmails.id;
+--
+-- Name: favorite_groups; Type: TABLE; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE TABLE favorite_groups (
+ id integer NOT NULL,
+ name text NOT NULL,
+ creator_id integer NOT NULL,
+ post_ids text DEFAULT ''::text NOT NULL,
+ post_count integer DEFAULT 0 NOT NULL,
+ created_at timestamp without time zone,
+ updated_at timestamp without time zone
+);
+
+
+--
+-- Name: favorite_groups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE favorite_groups_id_seq
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+
+--
+-- Name: favorite_groups_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE favorite_groups_id_seq OWNED BY favorite_groups.id;
+
+
--
-- Name: favorites; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
@@ -2190,7 +2223,7 @@ CREATE TABLE janitor_trials (
id integer NOT NULL,
creator_id integer NOT NULL,
user_id integer NOT NULL,
- original_level integer NOT NULL,
+ original_level integer,
created_at timestamp without time zone,
updated_at timestamp without time zone,
status character varying(255) DEFAULT 'active'::character varying NOT NULL
@@ -3346,6 +3379,13 @@ ALTER TABLE ONLY dmail_filters ALTER COLUMN id SET DEFAULT nextval('dmail_filter
ALTER TABLE ONLY dmails ALTER COLUMN id SET DEFAULT nextval('dmails_id_seq'::regclass);
+--
+-- Name: id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY favorite_groups ALTER COLUMN id SET DEFAULT nextval('favorite_groups_id_seq'::regclass);
+
+
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
@@ -4412,6 +4452,14 @@ ALTER TABLE ONLY dmails
ADD CONSTRAINT dmails_pkey PRIMARY KEY (id);
+--
+-- Name: favorite_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
+--
+
+ALTER TABLE ONLY favorite_groups
+ ADD CONSTRAINT favorite_groups_pkey PRIMARY KEY (id);
+
+
--
-- Name: favorites_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
@@ -4915,6 +4963,20 @@ CREATE INDEX index_dmails_on_message_index ON dmails USING gin (message_index);
CREATE INDEX index_dmails_on_owner_id ON dmails USING btree (owner_id);
+--
+-- Name: index_favorite_groups_on_creator_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE INDEX index_favorite_groups_on_creator_id ON favorite_groups USING btree (creator_id);
+
+
+--
+-- Name: index_favorite_groups_on_lower_name; Type: INDEX; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE INDEX index_favorite_groups_on_lower_name ON favorite_groups USING btree (lower(name));
+
+
--
-- Name: index_favorites_0_on_post_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
@@ -6672,6 +6734,13 @@ CREATE INDEX index_posts_on_last_noted_at ON posts USING btree (last_noted_at);
CREATE UNIQUE INDEX index_posts_on_md5 ON posts USING btree (md5);
+--
+-- Name: index_posts_on_mpixels; Type: INDEX; Schema: public; Owner: -; Tablespace:
+--
+
+CREATE INDEX index_posts_on_mpixels ON posts USING btree (((((image_width * image_height))::numeric / 1000000.0)));
+
+
--
-- Name: index_posts_on_parent_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
@@ -7179,10 +7248,6 @@ INSERT INTO schema_migrations (version) VALUES ('20141017231608');
INSERT INTO schema_migrations (version) VALUES ('20141120045943');
-INSERT INTO schema_migrations (version) VALUES ('20141203230229');
-
-INSERT INTO schema_migrations (version) VALUES ('20150116013315');
-
INSERT INTO schema_migrations (version) VALUES ('20150119191042');
INSERT INTO schema_migrations (version) VALUES ('20150120005624');
@@ -7193,3 +7258,7 @@ INSERT INTO schema_migrations (version) VALUES ('20150403224949');
INSERT INTO schema_migrations (version) VALUES ('20150613010904');
+INSERT INTO schema_migrations (version) VALUES ('20150623191904');
+
+INSERT INTO schema_migrations (version) VALUES ('20150629235905');
+
diff --git a/script/fixes/033_enable_can_approve_posts_flag.rb b/script/fixes/033_enable_can_approve_posts_flag.rb
new file mode 100644
index 000000000..d041dd04c
--- /dev/null
+++ b/script/fixes/033_enable_can_approve_posts_flag.rb
@@ -0,0 +1,13 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment'))
+
+ActiveRecord::Base.connection.execute("set statement_timeout = 0")
+
+CurrentUser.user = User.admins.first
+CurrentUser.ip_addr = "127.0.0.1"
+
+User.where("level >= ?", User::Levels::JANITOR).find_each do |user|
+ user.can_approve_posts = true
+ user.save
+end
diff --git a/test/controllers/user_upgrades_controller_test.rb b/test/controllers/user_upgrades_controller_test.rb
index 8816a5e08..cb2115382 100644
--- a/test/controllers/user_upgrades_controller_test.rb
+++ b/test/controllers/user_upgrades_controller_test.rb
@@ -1,34 +1,36 @@
require 'test_helper'
class UserUpgradesControllerTest < ActionController::TestCase
- setup do
- @admin = FactoryGirl.create(:admin_user)
- @user = FactoryGirl.create(:user)
- end
-
- context "#create" do
+ if Danbooru.config.coinbase_secret
setup do
- @encrypted = ActiveSupport::MessageEncryptor.new(Danbooru.config.coinbase_secret).encrypt_and_sign("#{@user.id},#{User::Levels::GOLD}")
+ @admin = FactoryGirl.create(:admin_user)
+ @user = FactoryGirl.create(:user)
end
- context "for basic -> gold" do
- should "promote the account" do
- post :create, {:order => {:status => "completed", :custom => @encrypted}}
+ context "#create" do
+ setup do
+ @encrypted = ActiveSupport::MessageEncryptor.new(Danbooru.config.coinbase_secret).encrypt_and_sign("#{@user.id},#{User::Levels::GOLD}")
+ end
+
+ context "for basic -> gold" do
+ should "promote the account" do
+ post :create, {:order => {:status => "completed", :custom => @encrypted}}
+ assert_response :success
+ @user.reload
+ assert_equal(User::Levels::GOLD, @user.level)
+ end
+ end
+ end
+
+ context "#new" do
+ setup do
+ Coinbase::Client.any_instance.stubs(:create_button).returns(OpenStruct.new)
+ end
+
+ should "render" do
+ get :new, {}, {:user_id => @user.id}
assert_response :success
- @user.reload
- assert_equal(User::Levels::GOLD, @user.level)
end
end
end
-
- context "#new" do
- setup do
- Coinbase::Client.any_instance.stubs(:create_button).returns(OpenStruct.new)
- end
-
- should "render" do
- get :new, {}, {:user_id => @user.id}
- assert_response :success
- end
- end
end
diff --git a/test/factories/user.rb b/test/factories/user.rb
index 12b37cfc7..929664412 100644
--- a/test/factories/user.rb
+++ b/test/factories/user.rb
@@ -34,14 +34,17 @@ FactoryGirl.define do
factory(:janitor_user) do
level 35
+ can_approve_posts true
end
factory(:moderator_user) do
level 40
+ can_approve_posts true
end
factory(:admin_user) do
level 50
+ can_approve_posts true
end
end
end
diff --git a/test/functional/janitor_trials_controller_test.rb b/test/functional/janitor_trials_controller_test.rb
index b8d78349a..25e274d46 100644
--- a/test/functional/janitor_trials_controller_test.rb
+++ b/test/functional/janitor_trials_controller_test.rb
@@ -36,7 +36,7 @@ class JanitorTrialsControllerTest < ActionController::TestCase
should "promote the janitor trial" do
post :promote, {:id => @janitor_trial.id}, {:user_id => @admin.id}
@user.reload
- assert(@user.is_janitor?)
+ assert(@user.can_approve_posts?)
@janitor_trial.reload
assert_equal(false, @janitor_trial.active?)
end
@@ -50,7 +50,7 @@ class JanitorTrialsControllerTest < ActionController::TestCase
should "demote the janitor trial" do
post :demote, {:id => @janitor_trial.id}, {:user_id => @admin.id}
@user.reload
- assert(!@user.is_janitor?)
+ assert(!@user.can_approve_posts?)
@janitor_trial.reload
assert_equal(false, @janitor_trial.active?)
end
diff --git a/test/functional/posts_controller_test.rb b/test/functional/posts_controller_test.rb
index 0c4ae7629..11b98bb3e 100644
--- a/test/functional/posts_controller_test.rb
+++ b/test/functional/posts_controller_test.rb
@@ -4,6 +4,7 @@ class PostsControllerTest < ActionController::TestCase
context "The posts controller" do
setup do
@user = FactoryGirl.create(:user)
+ @api_key = ApiKey.generate!(@user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@post = FactoryGirl.create(:post, :uploader_id => @user.id, :tag_string => "aaaa")
@@ -19,7 +20,6 @@ class PostsControllerTest < ActionController::TestCase
context "passing the api limit" do
setup do
User.any_instance.stubs(:api_hourly_limit).returns(5)
- ApiKey.generate!(@user)
end
should "work" do
@@ -35,30 +35,30 @@ class PostsControllerTest < ActionController::TestCase
context "using http basic auth" do
should "succeed for password matches" do
- @basic_auth_string = "Basic #{::Base64.encode64("#{@user.name}:#{@user.bcrypt_cookie_password_hash}")}"
+ @basic_auth_string = "Basic #{::Base64.encode64("#{@user.name}:#{@api_key.key}")}"
@request.env['HTTP_AUTHORIZATION'] = @basic_auth_string
get :index, {:format => "json"}
assert_response :success
end
- # should "fail for password mismatches" do
- # @basic_auth_string = "Basic #{::Base64.encode64("#{@user.name}:badpassword")}"
- # @request.env['HTTP_AUTHORIZATION'] = @basic_auth_string
- # get :index, {:format => "json"}
- # assert_response 403
- # end
+ should "fail for password mismatches" do
+ @basic_auth_string = "Basic #{::Base64.encode64("#{@user.name}:badpassword")}"
+ @request.env['HTTP_AUTHORIZATION'] = @basic_auth_string
+ get :index, {:format => "json"}
+ assert_response 401
+ end
end
context "using the api_key parameter" do
should "succeed for password matches" do
- get :index, {:format => "json", :login => @user.name, :api_key => @user.bcrypt_cookie_password_hash}
+ get :index, {:format => "json", :login => @user.name, :api_key => @api_key.key}
assert_response :success
end
- # should "fail for password mismatches" do
- # get :index, {:format => "json", :login => @user.name, :api_key => "bad"}
- # assert_response 403
- # end
+ should "fail for password mismatches" do
+ get :index, {:format => "json", :login => @user.name, :api_key => "bad"}
+ assert_response 401
+ end
end
context "using the password_hash parameter" do
diff --git a/test/unit/janitor_trial_test.rb b/test/unit/janitor_trial_test.rb
index a2cf89146..282fc56d1 100644
--- a/test/unit/janitor_trial_test.rb
+++ b/test/unit/janitor_trial_test.rb
@@ -22,10 +22,10 @@ class JanitorTrialTest < ActiveSupport::TestCase
end
end
- should "toggle the janitor flag on the user" do
+ should "toggle the can_approve_posts flag on the user" do
janitor_trial = JanitorTrial.create(:user_id => @user.id)
@user.reload
- assert(@user.is_janitor?)
+ assert(@user.can_approve_posts?)
end
end
@@ -39,6 +39,12 @@ class JanitorTrialTest < ActiveSupport::TestCase
@janitor_trial.demote!
end
end
+
+ should "revoke approval privileges" do
+ @janitor_trial.demote!
+ @user.reload
+ assert_equal(false, @user.can_approve_posts?)
+ end
end
context "upon promotion" do
diff --git a/test/unit/tag_test.rb b/test/unit/tag_test.rb
index 04196035a..5959e9a7b 100644
--- a/test/unit/tag_test.rb
+++ b/test/unit/tag_test.rb
@@ -102,9 +102,9 @@ class TagTest < ActiveSupport::TestCase
MEMCACHE.flush_all
end
- should "be lockable by a janitor" do
+ should "be lockable by a moderator" do
@tag = FactoryGirl.create(:tag)
- @tag.update_attributes({:is_locked => true}, :as => :janitor)
+ @tag.update_attributes({:is_locked => true}, :as => :moderator)
@tag.reload
assert_equal(true, @tag.is_locked?)
end
diff --git a/test/unit/wiki_page_test.rb b/test/unit/wiki_page_test.rb
index 31a08a721..84beb690d 100644
--- a/test/unit/wiki_page_test.rb
+++ b/test/unit/wiki_page_test.rb
@@ -14,25 +14,25 @@ class WikiPageTest < ActiveSupport::TestCase
context "A wiki page" do
context "that is locked" do
should "not be editable by a member" do
- CurrentUser.user = FactoryGirl.create(:janitor_user)
+ CurrentUser.user = FactoryGirl.create(:moderator_user)
@wiki_page = FactoryGirl.create(:wiki_page, :is_locked => true)
CurrentUser.user = FactoryGirl.create(:user)
@wiki_page.update_attributes(:body => "hello")
assert_equal(["Is locked and cannot be updated"], @wiki_page.errors.full_messages)
end
- should "be editable by a janitor" do
- CurrentUser.user = FactoryGirl.create(:janitor_user)
+ should "be editable by a moderator" do
+ CurrentUser.user = FactoryGirl.create(:moderator_user)
@wiki_page = FactoryGirl.create(:wiki_page, :is_locked => true)
- CurrentUser.user = FactoryGirl.create(:janitor_user)
+ CurrentUser.user = FactoryGirl.create(:moderator_user)
@wiki_page.update_attributes(:body => "hello")
assert_equal([], @wiki_page.errors.full_messages)
end
end
- context "updated by a janitor" do
+ context "updated by a moderator" do
setup do
- @user = FactoryGirl.create(:janitor_user)
+ @user = FactoryGirl.create(:moderator_user)
CurrentUser.user = @user
@wiki_page = FactoryGirl.create(:wiki_page)
end
@@ -53,7 +53,7 @@ class WikiPageTest < ActiveSupport::TestCase
should "not allow the is_locked attribute to be updated" do
@wiki_page.update_attributes(:is_locked => true)
- assert_equal(["Is locked can be modified by janitors only", "Is locked and cannot be updated"], @wiki_page.errors.full_messages)
+ assert_equal(["Is locked can be modified by moderators only", "Is locked and cannot be updated"], @wiki_page.errors.full_messages)
@wiki_page.reload
assert_equal(false, @wiki_page.is_locked?)
end