fixes #145: add test function for janitor trials
This commit is contained in:
27
app/assets/javascripts/janitor_trials.js
Normal file
27
app/assets/javascripts/janitor_trials.js
Normal file
@@ -0,0 +1,27 @@
|
||||
(function() {
|
||||
Danbooru.JanitorTrials = {};
|
||||
|
||||
Danbooru.JanitorTrials.initialize_all = function() {
|
||||
$("#c-janitor-trials input[value=Test]").click(function(e) {
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "/janitor_trials/test.json",
|
||||
data: {
|
||||
janitor_trial: {
|
||||
user_name: $("#janitor_trial_user_name").val()
|
||||
}
|
||||
},
|
||||
success: function(data) {
|
||||
$("#test-results").html(data);
|
||||
}
|
||||
});
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
Danbooru.JanitorTrials.initialize_all();
|
||||
});
|
||||
@@ -37,4 +37,8 @@ class JanitorTrialsController < ApplicationController
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def test
|
||||
@tester = JanitorTrialTester.new(params[:janitor_trial][:user_name])
|
||||
end
|
||||
end
|
||||
|
||||
21
app/logical/janitor_trial_tester.rb
Normal file
21
app/logical/janitor_trial_tester.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class JanitorTrialTester
|
||||
attr_reader :user
|
||||
|
||||
def initialize(user_name)
|
||||
@user = User.find_by_name(user_name)
|
||||
end
|
||||
|
||||
def test
|
||||
if user.nil?
|
||||
"User not found"
|
||||
elsif user.created_at > 1.month.ago
|
||||
"User signed up within the past month"
|
||||
elsif user.favorites.count < 100
|
||||
"User has fewer than 100 favorites"
|
||||
elsif user.feedback.negative.count > 0
|
||||
"User has negative feedback"
|
||||
else
|
||||
"No issues found"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5,7 +5,10 @@
|
||||
<%= simple_form_for(@janitor_trial) do |f| %>
|
||||
<%= f.input :user_name %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<%= f.button :submit, "Test" %>
|
||||
<% end %>
|
||||
|
||||
<p id="test-results"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
1
app/views/janitor_trials/test.json.erb
Normal file
1
app/views/janitor_trials/test.json.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= raw @tester.test.to_json %>
|
||||
@@ -66,6 +66,9 @@ Danbooru::Application.routes.draw do
|
||||
end
|
||||
end
|
||||
resources :janitor_trials do
|
||||
collection do
|
||||
get :test
|
||||
end
|
||||
member do
|
||||
put :promote
|
||||
put :demote
|
||||
|
||||
Reference in New Issue
Block a user