Skip to content

Commit

Permalink
Merge pull request #143 from alphagov/hide-non-actionable-feedback-in…
Browse files Browse the repository at this point in the history
…-feedex

Track and hide non-actionable feedback in Feedex
  • Loading branch information
alext committed Mar 3, 2014
2 parents b1ed36e + b5d034f commit 84366d7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
@@ -0,0 +1,6 @@
class AddActionableFlagAndReasonToAnonymousFeedback < ActiveRecord::Migration
def change
add_column :anonymous_contacts, :is_actionable, :boolean, default: true, null: false
add_column :anonymous_contacts, :reason_why_not_actionable, :string
end
end
8 changes: 5 additions & 3 deletions db/schema.rb
Expand Up @@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.


ActiveRecord::Schema.define(:version => 20140221155725) do ActiveRecord::Schema.define(:version => 20140228185036) do


create_table "anonymous_contacts", :force => true do |t| create_table "anonymous_contacts", :force => true do |t|
t.string "type" t.string "type"
Expand All @@ -24,12 +24,14 @@
t.string "user_agent" t.string "user_agent"
t.string "referrer" t.string "referrer"
t.boolean "javascript_enabled" t.boolean "javascript_enabled"
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.string "personal_information_status" t.string "personal_information_status"
t.string "slug" t.string "slug"
t.integer "service_satisfaction_rating" t.integer "service_satisfaction_rating"
t.text "user_specified_url" t.text "user_specified_url"
t.boolean "is_actionable", :default => true, :null => false
t.string "reason_why_not_actionable"
end end


end end
16 changes: 11 additions & 5 deletions lib/support/requests/anonymous/anonymous_contact.rb
Expand Up @@ -6,21 +6,23 @@ module Requests
module Anonymous module Anonymous
class AnonymousContact < ActiveRecord::Base class AnonymousContact < ActiveRecord::Base
attr_accessible :referrer, :javascript_enabled, :user_agent, :personal_information_status attr_accessible :referrer, :javascript_enabled, :user_agent, :personal_information_status
validates :referrer, url: true, allow_nil: true attr_accessible :is_actionable, :reason_why_not_actionable


before_save :detect_personal_information before_save :detect_personal_information


def requester def requester
Requester.anonymous Requester.anonymous
end end


validates :referrer, url: true, allow_nil: true
validates :details, length: { maximum: 2 ** 16 } validates :details, length: { maximum: 2 ** 16 }
validates_inclusion_of :javascript_enabled, in: [ true, false ] validates_inclusion_of :javascript_enabled, in: [ true, false ]
validates_inclusion_of :personal_information_status, in: [ "suspected", "absent" ], allow_nil: true validates_inclusion_of :personal_information_status, in: [ "suspected", "absent" ], allow_nil: true
validates_inclusion_of :is_actionable, in: [ true, false ]
validates_presence_of :reason_why_not_actionable, unless: "is_actionable"


def self.free_of_personal_info scope :free_of_personal_info, where(personal_information_status: "absent")
where(personal_information_status: "absent") scope :only_actionable, where(is_actionable: true)
end


def path def path
URI(url).path URI(url).path
Expand All @@ -31,7 +33,11 @@ def path
end end


def self.find_all_starting_with_path(path) def self.find_all_starting_with_path(path)
where("url is not null and url like ?", "%" + path + "%").free_of_personal_info.order("created_at desc").select { |pr| pr.path && pr.path.start_with?(path) } where("url is not null and url like ?", "%" + path + "%").
free_of_personal_info.
only_actionable.
order("created_at desc").
select { |pr| pr.path && pr.path.start_with?(path) }
end end


private private
Expand Down
13 changes: 13 additions & 0 deletions test/unit/support/requests/anonymous/anonymous_contact_test.rb
Expand Up @@ -23,6 +23,12 @@ def path_for(url)
URI(url).path URI(url).path
end end


should "enforce the presence of a reason why feedback isn't actionable" do
contact = new_contact(is_actionable: false, reason_why_not_actionable: "")
refute contact.valid?
refute contact.errors[:reason_why_not_actionable].empty?
end

should "not detect personal info when none is present in free text fields" do should "not detect personal info when none is present in free text fields" do
assert_equal "absent", contact(details: "abc", what_wrong: "abc", what_doing: "abc").personal_information_status assert_equal "absent", contact(details: "abc", what_wrong: "abc", what_doing: "abc").personal_information_status
end end
Expand Down Expand Up @@ -83,6 +89,13 @@ def path_for(url)
assert_equal [a], TestContact.find_all_starting_with_path(path_for(DEFAULTS[:url])) assert_equal [a], TestContact.find_all_starting_with_path(path_for(DEFAULTS[:url]))
end end


should "only return actionable feedback" do
a = contact(is_actionable: true)
_ = contact(is_actionable: false, reason_why_not_actionable: "spam")

assert_equal [a], TestContact.find_all_starting_with_path(path_for(DEFAULTS[:url]))
end

def teardown def teardown
TestContact.delete_all TestContact.delete_all
end end
Expand Down

0 comments on commit 84366d7

Please sign in to comment.