-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #606 from coopdevs/develop
v3.11.0
- Loading branch information
Showing
6 changed files
with
57 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,27 @@ | ||
class TagsController < ApplicationController | ||
def index | ||
@posts = Post.by_organization(current_organization) | ||
@all_tags = @posts.find_like_tag(params[:term]) | ||
posts = Post.by_organization(current_organization) | ||
@all_tags = posts.find_like_tag(params[:term]) | ||
|
||
render json: @all_tags | ||
end | ||
|
||
def alpha_grouped_index | ||
redirect_to users_path && return unless current_organization | ||
|
||
@alpha_tags = case params[:post_type] || "offer" | ||
post_type = params[:post_type] || "offer" | ||
@alpha_tags = case post_type | ||
when "offer" then Offer | ||
when "inquiry" then Inquiry | ||
end.by_organization(current_organization). | ||
active.of_active_members. | ||
alphabetical_grouped_tags | ||
end | ||
|
||
def inquiries | ||
@alpha_tags = Inquiry.by_organization(current_organization).active.of_active_members. | ||
alphabetical_grouped_tags | ||
|
||
render partial: "grouped_index", locals: { alpha_tags: @alpha_tags, post_type: "inquiries" } | ||
end | ||
|
||
def offers | ||
@alpha_tags = Offer.by_organization(current_organization).active.of_active_members. | ||
alphabetical_grouped_tags | ||
|
||
render partial: "grouped_index", locals: { alpha_tags: @alpha_tags, post_type: "offers" } | ||
respond_to do |format| | ||
format.html | ||
format.js do | ||
render partial: "grouped_index", locals: { alpha_tags: @alpha_tags, post_type: post_type } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,58 @@ | ||
RSpec.describe TagsController do | ||
let (:tags) { %w(foo bar baz) } | ||
let (:more_tags) { %w(ruby rails js) } | ||
let (:organization) { Fabricate(:organization) } | ||
let (:member) { Fabricate(:member, organization: organization) } | ||
let! (:post) { Fabricate(:offer, | ||
user: member.user, | ||
organization: organization, | ||
tags: tags) } | ||
let! (:offer) { Fabricate(:offer, user: member.user, organization: organization, tags: tags) } | ||
let! (:inquiry) { Fabricate(:inquiry, user: member.user, organization: organization, tags: more_tags) } | ||
|
||
describe "GET 'index'" do | ||
describe "GET index" do | ||
before(:each) do | ||
login(member.user) | ||
end | ||
|
||
it "returns http success" do | ||
get 'index' | ||
get :index | ||
expect(response).to have_http_status(:ok) | ||
expect(response.content_type).to match("application/json") | ||
end | ||
|
||
it "with no search term, returns all tags" do | ||
get 'index' | ||
expect(assigns(:all_tags)).to eq(tags) | ||
get :index | ||
expect(assigns(:all_tags)).to eq(more_tags + tags) | ||
end | ||
|
||
it "with search term, returns filtered tags" do | ||
get 'index', params: { term: "foo" } | ||
get :index, params: { term: "foo" } | ||
expect(assigns(:all_tags)).to eq(["foo"]) | ||
end | ||
end | ||
|
||
describe "GET alpha_grouped_index" do | ||
before { session[:current_organization_id] = organization.id } | ||
|
||
it "load offers tags by default if no type is passed" do | ||
get :alpha_grouped_index | ||
|
||
expect(assigns(:alpha_tags)).to eq({ | ||
"B" => [["bar", 1], ["baz", 1]], | ||
"F" => [["foo", 1]] | ||
}) | ||
end | ||
|
||
it "load tags by type" do | ||
get :alpha_grouped_index, params: { post_type: "inquiry" } | ||
|
||
expect(assigns(:alpha_tags)).to eq({ | ||
"J" => [["js", 1]], | ||
"R" => [["rails", 1], ["ruby", 1]] | ||
}) | ||
end | ||
|
||
it "renders a partial with format js" do | ||
get :alpha_grouped_index, xhr: true | ||
|
||
expect(response).to render_template(partial: "_grouped_index") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters