Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent promotion rule to show user multiple times #3195

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/resource_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def index
ids = params[:ids].split(",").flatten
collection_scope = collection_scope.where(id: ids)
else
collection_scope = collection_scope.ransack(params[:q]).result
collection_scope = collection_scope.ransack(params[:q]).result(distinct: true)
end

@collection = paginate(collection_scope)
Expand Down
38 changes: 38 additions & 0 deletions api/spec/controllers/spree/api/resource_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ def permitted_widget_attributes
model do
acts_as_list
validates :name, presence: true
has_many :components
end
end

with_model 'Component', scope: :all do
table do |t|
t.string :name
t.belongs_to :widget
end

model do
belongs_to :widget
end
end

Expand All @@ -58,6 +70,32 @@ def permitted_widget_attributes
end

context "it has authorization to read widgets" do
context "when the widget has many components" do
before do
2.times{ Component.create!(name: 'a component', widget_id: widget.id) }
end

context "and the query contains multiple attributes" do
it "returns unique results" do
get(
:index,
params: {
token: admin_user.spree_api_key,
q: { m: 'or', name_start: 'a wid', components_name_start: 'a comp' }
},
as: :json
)
expect(response).to be_successful
expect(json_response['widgets']).to contain_exactly(
hash_including(
name: 'a widget',
position: 1
)
)
end
end
end

it "returns widgets" do
get :index, params: { token: admin_user.spree_api_key }, as: :json
expect(response).to be_successful
Expand Down