Skip to content
Snippets Groups Projects
Verified Commit 68ee9e2c authored by David Gunnarsson's avatar David Gunnarsson
Browse files

Make sample searchable

parent 318ffa66
Branches
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ class Avo::Resources::ImageColor < Avo::BaseResource
# }
def fields
field :sample, as: :belongs_to
field :sample, as: :belongs_to, searchable: true
field :hue, as: :number
field :saturation, as: :number
field :brightness, as: :number
......
......@@ -4,9 +4,9 @@ class Avo::Resources::Sample < Avo::BaseResource
# self.includes = []
# self.attachments = []
# self.search = {
# query: -> { query.ransack(id_eq: params[:q], m: "or").result(distinct: false) }
# }
self.search = {
query: -> { query.ransack(sample_no_cont: params[:q], m: "or").result(distinct: false) }
}
def fields
field :sample_no, as: :text, sortable: true
......
......@@ -18,6 +18,10 @@ class Sample < ApplicationRecord
validates :sample_no, presence: true
def self.ransackable_attributes(auth_object = nil)
%w[sample_no]
end
serialize :analysis_method_ids, coder: MultiValueWrapper
serialize :voids_form_ids, coder: MultiValueWrapper
serialize :sorting_ids, coder: MultiValueWrapper
......
......@@ -5,6 +5,10 @@ class SamplePolicy < ApplicationPolicy
user? && user.apprentice?
end
def search?
user? && user.apprentice?
end
class Scope < ApplicationPolicy::Scope
def resolve
scope.all
......
......@@ -12,6 +12,7 @@ RSpec.describe SamplePolicy do
it { is_expected.to forbid_new_and_create_actions }
it { is_expected.to forbid_edit_and_update_actions }
it { is_expected.to forbid_action(:destroy) }
it { is_expected.to forbid_action(:search) }
end
context "for an apprentice" do
......@@ -22,6 +23,7 @@ RSpec.describe SamplePolicy do
it { is_expected.to permit_new_and_create_actions }
it { is_expected.to permit_edit_and_update_actions }
it { is_expected.to permit_action(:destroy) }
it { is_expected.to permit_action(:search) }
end
context "for an editor" do
......@@ -32,6 +34,7 @@ RSpec.describe SamplePolicy do
it { is_expected.to permit_new_and_create_actions }
it { is_expected.to permit_edit_and_update_actions }
it { is_expected.to permit_action(:destroy) }
it { is_expected.to permit_action(:search) }
end
context "for an admin" do
......@@ -42,6 +45,7 @@ RSpec.describe SamplePolicy do
it { is_expected.to permit_new_and_create_actions }
it { is_expected.to permit_edit_and_update_actions }
it { is_expected.to permit_action(:destroy) }
it { is_expected.to permit_action(:search) }
end
describe "Scope" do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment