diff --git a/Gemfile.lock b/Gemfile.lock index d9eb8b504..29bae0528 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -202,7 +202,9 @@ GEM mime-types (3.3.1) mime-types-data (~> 3.2015) mime-types-data (3.2021.0225) - mimemagic (0.3.5) + mimemagic (0.3.10) + nokogiri (~> 1) + rake mini_mime (1.0.2) mini_portile2 (2.5.0) minitest (5.14.4) @@ -291,7 +293,7 @@ GEM http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) - rexml (3.2.4) + rexml (3.2.5) rollbar (2.22.1) rspec-core (3.10.1) rspec-support (~> 3.10.0) diff --git a/app/admin/user.rb b/app/admin/user.rb index 7de9e123b..afdcb0d20 100644 --- a/app/admin/user.rb +++ b/app/admin/user.rb @@ -30,6 +30,7 @@ filter :email filter :username filter :phone + filter :postcode form do |f| f.semantic_errors *f.object.errors.keys @@ -37,6 +38,7 @@ f.input :username f.input :email f.input :phone + f.input :postcode f.input :gender, as: :select, collection: User::GENDERS f.input :identity_document end diff --git a/app/assets/javascripts/application/tags.js b/app/assets/javascripts/application/tags.js index d7341a03d..e3f6f9067 100644 --- a/app/assets/javascripts/application/tags.js +++ b/app/assets/javascripts/application/tags.js @@ -7,6 +7,10 @@ $(function() { loadTags('inquiry'); }); + $(".switch_member-js").on("click", function() { + loadTags('user'); + }); + function loadTags(type){ $.get({ url: `/tags/alpha_grouped_index.js?post_type=${type}`, @@ -28,7 +32,7 @@ $(function() { ajax: { url: '/tags.json', data: function(params) { - return { term: params.term }; + return { term: params.term, model: $(this).data("model") }; }, processResults: function(data, params) { // parse the data into the format expected by Select2 diff --git a/app/assets/stylesheets/application/member-card.scss b/app/assets/stylesheets/application/member-card.scss index 6592e33f6..c72c603eb 100644 --- a/app/assets/stylesheets/application/member-card.scss +++ b/app/assets/stylesheets/application/member-card.scss @@ -37,6 +37,13 @@ } } + &__tags { + a { + margin-left: 4px; + color: white; + } + } + &__activity { font-size: 14px; color: #78adb9; diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 339ad9411..01f0028ec 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -2,27 +2,30 @@ class TagsController < ApplicationController before_action :authenticate_user!, :member_should_be_active def index - posts = Post.by_organization(current_organization) - @all_tags = posts.find_like_tag(params[:term]) + model = params[:model].classify.constantize + posts = model.by_organization(current_organization) + @tags = posts.find_like_tag(params[:term]) - render json: @all_tags + render json: @tags end def alpha_grouped_index redirect_to users_path && return unless current_organization 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 + @tags = case post_type + when "offer" + Offer.by_organization(current_organization).active.of_active_members + when "inquiry" + Inquiry.by_organization(current_organization).active.of_active_members + when "user" + Member.by_organization(current_organization).active + end.alphabetical_grouped_tags respond_to do |format| format.html format.js do - render partial: "grouped_index", locals: { alpha_tags: @alpha_tags, post_type: post_type } + render partial: "grouped_index", locals: { alpha_tags: @tags, post_type: post_type } end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 02a14402c..ef37ac57b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,8 +1,13 @@ class UsersController < ApplicationController before_action :authenticate_user!, :member_should_be_active + has_scope :tagged_with, as: :tag + def index - search_and_load_members current_organization.members.active, { s: 'user_last_sign_in_at DESC' } + members = current_organization.members.active + members = apply_scopes(members) + + search_and_load_members members, { s: 'user_last_sign_in_at DESC' } end def manage @@ -37,9 +42,12 @@ def create if @user.persisted? @user.tune_after_persisted(current_organization) + @user.add_tags(current_organization, params[:tag_list] || []) + redirect_to_after_create else @user.email = "" if empty_email + render action: "new" end end @@ -49,6 +57,8 @@ def update authorize @user if @user.update(user_params) + @user.add_tags(current_organization, params[:tag_list] || []) + redirect_to @user else render action: :edit, status: :unprocessable_entity @@ -76,7 +86,7 @@ def scoped_users def user_params fields_to_permit = %w"gender username email date_of_birth phone - alt_phone active description notifications push_notifications" + alt_phone active description notifications push_notifications postcode" fields_to_permit += %w"admin registration_number registration_date" if admin? fields_to_permit += %w"organization_id superadmin" if superadmin? diff --git a/app/decorators/member_decorator.rb b/app/decorators/member_decorator.rb index f08f33e5c..4902308c9 100644 --- a/app/decorators/member_decorator.rb +++ b/app/decorators/member_decorator.rb @@ -1,5 +1,5 @@ class MemberDecorator < ViewModel - delegate :user, :member_uid, :active?, to: :object + delegate :user, :member_uid, :tags, :active?, to: :object delegate :phone, :alt_phone, :username, :description, :last_sign_in_at, to: :user def manager? diff --git a/app/models/account.rb b/app/models/account.rb index 73ba91a19..c441349ba 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -22,16 +22,6 @@ def update_balance save end - # Return the maximum allowed amount of time that the acccount is able to - # spend without overflowing - def allowance - if min_allowed_balance - [0, balance - min_allowed_balance].min - else - Float::INFINITY - end - end - # Print the account as its accountable reference def to_s accountable.to_s diff --git a/app/models/concerns/taggable.rb b/app/models/concerns/taggable.rb index 61e3d6f78..70f1c0aba 100644 --- a/app/models/concerns/taggable.rb +++ b/app/models/concerns/taggable.rb @@ -6,7 +6,7 @@ module Taggable extend ActiveSupport::Concern included do - scope :tagged_with, ->(tag) { where("? = ANY (tags)", tag) } + scope :tagged_with, ->(tag) { where("? = ANY (#{table_name}.tags)", tag) } end def tag_list diff --git a/app/models/member.rb b/app/models/member.rb index e9a05215b..28285f486 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -1,8 +1,22 @@ class Member < ApplicationRecord + include Taggable + # Cast the member_uid integer to a string to allow pg ILIKE search (from Ransack *_contains) ransacker :member_uid_search do Arel.sql("member_uid::text") end + # Convert array of tags to string + ransacker :member_tags do + Arel.sql("array_to_string(tags, ',')") + end + ransack_alias :member_search, %w( + user_username + user_email + user_phone + user_alt_phone + member_uid_search + member_tags + ).join("_or_") belongs_to :user belongs_to :organization @@ -15,6 +29,7 @@ class Member < ApplicationRecord scope :by_month, -> (month) { where(created_at: month.beginning_of_month..month.end_of_month) } scope :active, -> { where active: true } + scope :by_organization, ->(org) { where(organization_id: org) if org } validates :organization_id, presence: true validates :member_uid, diff --git a/app/models/user.rb b/app/models/user.rb index fae6223c2..7adbb5525 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -110,6 +110,11 @@ def tune_after_persisted(organization) save end + def add_tags(organization, tag_list) + member = as_member_of(organization) + member.update(tag_list: tag_list) + end + def has_valid_email? !email.include? "example.com" end diff --git a/app/views/shared/_post_form.html.erb b/app/views/shared/_post_form.html.erb index 7a1ec2b82..f0a635849 100644 --- a/app/views/shared/_post_form.html.erb +++ b/app/views/shared/_post_form.html.erb @@ -34,7 +34,7 @@ f.object.tags || [], { selected: f.object.tags }, multiple: true, - data: { placeholder: t('application.tips.entertag') }, + data: { placeholder: t("application.tips.entertag"), model: "post" }, id: "tags-js", class: "form-control" %> diff --git a/app/views/tags/alpha_grouped_index.html.erb b/app/views/tags/alpha_grouped_index.html.erb index 8c7cf58e7..9c71acfa4 100644 --- a/app/views/tags/alpha_grouped_index.html.erb +++ b/app/views/tags/alpha_grouped_index.html.erb @@ -1,20 +1,22 @@ -

- <%= t '.maintitle' %> - <%= form_tag alpha_grouped_index_tags_path, method: :get do %> -
- - -
- <% end %> -

+

<%= t '.maintitle' %>

+ +<%= form_tag alpha_grouped_index_tags_path, method: :get do %> +
+ + + +
+<% end %> +
- <%= render 'grouped_index', - alpha_tags: @alpha_tags, - post_type: params[:post_type] || 'offer' %> + <%= render 'grouped_index', alpha_tags: @tags, post_type: params[:post_type] || 'offer' %>
diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index f2b32484b..39a845213 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -20,6 +20,16 @@ end_year: Date.today.year - 12, include_blank: :true %> <%= f.input :description, as: "text" %> + <%= f.input :postcode %> + <%= label_tag :tag_list, t('activerecord.attributes.post.tag_list') %> +
+ <%= select_tag :tag_list, + options_for_select(member.tags, member.tags), + multiple: true, + data: { placeholder: t("application.tips.entertag"), model: "member" }, + id: "tags-js", + class: "form-control" %> +
diff --git a/app/views/users/_member_card.html.erb b/app/views/users/_member_card.html.erb index d4e556498..e4263c41f 100644 --- a/app/views/users/_member_card.html.erb +++ b/app/views/users/_member_card.html.erb @@ -11,6 +11,17 @@ <% else %> <%= t('.no_activity') %> <% end %> + <% member.tags[0..2].each do |tag| %> + + <%= link_to users_path tag: tag do %> + <%= glyph :tag %> + <%= tag&.truncate(29) %> + <% end %> + + <% end %> + <% if member.tags.size > 3 %> + ... + <% end %>
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 75e1c9a56..55fb08316 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -3,4 +3,4 @@ <%= t ".edit_user" %> -<%= render "form" %> +<%= render "form", member: @user.as_member_of(current_organization) %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index b2e84ee80..a2600bbd9 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -14,7 +14,7 @@
<%= search_form_for(@search, class: "navbar-form navbar-left", url: users_path) do |f| %>
- <%= f.search_field :user_username_or_user_email_or_member_uid_search_contains, class: "form-control" %> + <%= f.search_field :member_search_cont, class: "form-control" %>
diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 6087868ca..93f503b7d 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -66,6 +66,7 @@ ca: notifications: Rebre notificacions organization: Organització phone: Telèfon + postcode: Codi postal push_notifications: Rebre notificacions al mòbil registration_date: Data d'alta registration_number: Codi d'usuari diff --git a/config/locales/en.yml b/config/locales/en.yml index 2a65f5c3e..5b623ec2f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -66,6 +66,7 @@ en: notifications: Receive email notifications organization: Organization phone: Phone + postcode: Postal code push_notifications: Receive mobile notifications registration_date: Registration date registration_number: User code diff --git a/config/locales/es.yml b/config/locales/es.yml index 91d7203b4..727d42aa6 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -66,6 +66,7 @@ es: notifications: Recibir notificaciones organization: Organización phone: Teléfono + postcode: Código postal push_notifications: Recibir notificaciones móviles registration_date: Fecha de alta registration_number: Código de usuario diff --git a/config/locales/eu.yml b/config/locales/eu.yml index aff3fbb19..b92da9594 100644 --- a/config/locales/eu.yml +++ b/config/locales/eu.yml @@ -66,6 +66,7 @@ eu: notifications: Jaso eposta jakinarazpenak organization: Erakundea phone: Telefonoa + postcode: push_notifications: Jaso jakinarazpenak sakelakoan registration_date: Erregistratze-da registration_number: Erabiltzaile kodea diff --git a/config/locales/gl.yml b/config/locales/gl.yml index e24ed1004..559f5130b 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -66,6 +66,7 @@ gl: notifications: Recibir notificacións por correo electrónico organization: Organización phone: Teléfono + postcode: push_notifications: Recibir notificacións móbiles registration_date: Data de rexistro registration_number: Código de persoa usuaria diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 50d54dfa6..79cfc3f23 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -66,6 +66,7 @@ pt-BR: notifications: Receber notificações organization: Organização phone: Telefone + postcode: push_notifications: Receber notificações pelo celular registration_date: Data de ingresso registration_number: Código do usuário diff --git a/db/migrate/20210423193937_add_post_code_to_users.rb b/db/migrate/20210423193937_add_post_code_to_users.rb new file mode 100644 index 000000000..c081fa264 --- /dev/null +++ b/db/migrate/20210423193937_add_post_code_to_users.rb @@ -0,0 +1,5 @@ +class AddPostCodeToUsers < ActiveRecord::Migration[6.1] + def change + add_column :users, :postcode, :string + end +end diff --git a/db/migrate/20210424174640_add_tags_to_members.rb b/db/migrate/20210424174640_add_tags_to_members.rb new file mode 100644 index 000000000..4f3098936 --- /dev/null +++ b/db/migrate/20210424174640_add_tags_to_members.rb @@ -0,0 +1,5 @@ +class AddTagsToMembers < ActiveRecord::Migration[6.1] + def change + add_column :members, :tags, :text, array: true, default: [] + end +end diff --git a/db/structure.sql b/db/structure.sql index fcb2d6336..8c071d613 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1,16 +1,10 @@ --- --- PostgreSQL database dump --- - --- Dumped from database version 9.5.14 --- Dumped by pg_dump version 9.5.14 - SET statement_timeout = 0; SET lock_timeout = 0; SET client_encoding = 'UTF8'; SET standard_conforming_strings = on; SELECT pg_catalog.set_config('search_path', '', false); SET check_function_bodies = false; +SET xmloption = content; SET client_min_messages = warning; -- @@ -163,6 +157,18 @@ CREATE SEQUENCE public.active_admin_comments_id_seq ALTER SEQUENCE public.active_admin_comments_id_seq OWNED BY public.active_admin_comments.id; +-- +-- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.ar_internal_metadata ( + key character varying NOT NULL, + value character varying, + created_at timestamp(6) without time zone NOT NULL, + updated_at timestamp(6) without time zone NOT NULL +); + + -- -- Name: categories; Type: TABLE; Schema: public; Owner: - -- @@ -308,7 +314,8 @@ CREATE TABLE public.members ( updated_at timestamp without time zone, entry_date date, member_uid integer, - active boolean DEFAULT true + active boolean DEFAULT true, + tags text[] DEFAULT '{}'::text[] ); @@ -564,7 +571,8 @@ CREATE TABLE public.users ( locked_at timestamp without time zone, locale character varying DEFAULT 'es'::character varying, notifications boolean DEFAULT true, - push_notifications boolean DEFAULT true NOT NULL + push_notifications boolean DEFAULT true NOT NULL, + postcode character varying ); @@ -694,6 +702,14 @@ ALTER TABLE ONLY public.active_admin_comments ADD CONSTRAINT active_admin_comments_pkey PRIMARY KEY (id); +-- +-- Name: ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.ar_internal_metadata + ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key); + + -- -- Name: categories_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -1016,125 +1032,70 @@ ALTER TABLE ONLY public.push_notifications -- PostgreSQL database dump complete -- -SET search_path TO "$user", public; - -INSERT INTO schema_migrations (version) VALUES ('1'); - -INSERT INTO schema_migrations (version) VALUES ('2'); - -INSERT INTO schema_migrations (version) VALUES ('20121019101022'); - -INSERT INTO schema_migrations (version) VALUES ('20121104004639'); - -INSERT INTO schema_migrations (version) VALUES ('20121104085711'); - -INSERT INTO schema_migrations (version) VALUES ('20121121233818'); - -INSERT INTO schema_migrations (version) VALUES ('20130214175758'); - -INSERT INTO schema_migrations (version) VALUES ('20130214181128'); - -INSERT INTO schema_migrations (version) VALUES ('20130222185624'); - -INSERT INTO schema_migrations (version) VALUES ('20130425165150'); - -INSERT INTO schema_migrations (version) VALUES ('20130508085004'); - -INSERT INTO schema_migrations (version) VALUES ('20130513092219'); - -INSERT INTO schema_migrations (version) VALUES ('20130514094755'); - -INSERT INTO schema_migrations (version) VALUES ('20130618210236'); - -INSERT INTO schema_migrations (version) VALUES ('20130621102219'); - -INSERT INTO schema_migrations (version) VALUES ('20130621103053'); - -INSERT INTO schema_migrations (version) VALUES ('20130621103501'); - -INSERT INTO schema_migrations (version) VALUES ('20130621105452'); - -INSERT INTO schema_migrations (version) VALUES ('20130703233851'); - -INSERT INTO schema_migrations (version) VALUES ('20130703234011'); - -INSERT INTO schema_migrations (version) VALUES ('20130703234042'); - -INSERT INTO schema_migrations (version) VALUES ('20130723160206'); - -INSERT INTO schema_migrations (version) VALUES ('20131017144321'); - -INSERT INTO schema_migrations (version) VALUES ('20131025202608'); - -INSERT INTO schema_migrations (version) VALUES ('20131027215517'); - -INSERT INTO schema_migrations (version) VALUES ('20131029202724'); - -INSERT INTO schema_migrations (version) VALUES ('20131103221044'); - -INSERT INTO schema_migrations (version) VALUES ('20131104004235'); - -INSERT INTO schema_migrations (version) VALUES ('20131104013634'); - -INSERT INTO schema_migrations (version) VALUES ('20131104013829'); - -INSERT INTO schema_migrations (version) VALUES ('20131104032622'); - -INSERT INTO schema_migrations (version) VALUES ('20131220160257'); - -INSERT INTO schema_migrations (version) VALUES ('20131227110122'); - -INSERT INTO schema_migrations (version) VALUES ('20131227142805'); - -INSERT INTO schema_migrations (version) VALUES ('20131227155440'); - -INSERT INTO schema_migrations (version) VALUES ('20131231110424'); - -INSERT INTO schema_migrations (version) VALUES ('20140119161433'); - -INSERT INTO schema_migrations (version) VALUES ('20140513141718'); - -INSERT INTO schema_migrations (version) VALUES ('20140514225527'); - -INSERT INTO schema_migrations (version) VALUES ('20150329193421'); - -INSERT INTO schema_migrations (version) VALUES ('20150330200315'); - -INSERT INTO schema_migrations (version) VALUES ('20150422162806'); - -INSERT INTO schema_migrations (version) VALUES ('20180221161343'); - -INSERT INTO schema_migrations (version) VALUES ('20180501093846'); - -INSERT INTO schema_migrations (version) VALUES ('20180514193153'); - -INSERT INTO schema_migrations (version) VALUES ('20180524143938'); - -INSERT INTO schema_migrations (version) VALUES ('20180525141138'); - -INSERT INTO schema_migrations (version) VALUES ('20180529144243'); - -INSERT INTO schema_migrations (version) VALUES ('20180530180546'); - -INSERT INTO schema_migrations (version) VALUES ('20180604145622'); - -INSERT INTO schema_migrations (version) VALUES ('20180828160700'); - -INSERT INTO schema_migrations (version) VALUES ('20180831161349'); - -INSERT INTO schema_migrations (version) VALUES ('20180924164456'); - -INSERT INTO schema_migrations (version) VALUES ('20181004200104'); - -INSERT INTO schema_migrations (version) VALUES ('20190319121401'); - -INSERT INTO schema_migrations (version) VALUES ('20190322180602'); - -INSERT INTO schema_migrations (version) VALUES ('20190411192828'); - -INSERT INTO schema_migrations (version) VALUES ('20190412163011'); - -INSERT INTO schema_migrations (version) VALUES ('20190523213421'); +SET search_path TO "$user",public; + +INSERT INTO "schema_migrations" (version) VALUES +('1'), +('2'), +('20121019101022'), +('20121104004639'), +('20121104085711'), +('20121121233818'), +('20130214175758'), +('20130214181128'), +('20130222185624'), +('20130425165150'), +('20130508085004'), +('20130513092219'), +('20130514094755'), +('20130618210236'), +('20130621102219'), +('20130621103053'), +('20130621103501'), +('20130621105452'), +('20130703233851'), +('20130703234011'), +('20130703234042'), +('20130723160206'), +('20131017144321'), +('20131025202608'), +('20131027215517'), +('20131029202724'), +('20131103221044'), +('20131104004235'), +('20131104013634'), +('20131104013829'), +('20131104032622'), +('20131220160257'), +('20131227110122'), +('20131227142805'), +('20131227155440'), +('20131231110424'), +('20140119161433'), +('20140513141718'), +('20140514225527'), +('20150329193421'), +('20150330200315'), +('20150422162806'), +('20180221161343'), +('20180501093846'), +('20180514193153'), +('20180524143938'), +('20180525141138'), +('20180529144243'), +('20180530180546'), +('20180604145622'), +('20180828160700'), +('20180831161349'), +('20180924164456'), +('20181004200104'), +('20190319121401'), +('20190322180602'), +('20190411192828'), +('20190412163011'), +('20190523213421'), +('20190523225323'), +('20210423193937'), +('20210424174640'); -INSERT INTO schema_migrations (version) VALUES ('20190523225323'); diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb index 7f633698c..b0aa91339 100644 --- a/spec/controllers/tags_controller_spec.rb +++ b/spec/controllers/tags_controller_spec.rb @@ -1,8 +1,9 @@ RSpec.describe TagsController do let (:tags) { %w(foo bar baz) } let (:more_tags) { %w(ruby rails js) } + let (:member_tags) { %w(html html css html5) } let (:organization) { Fabricate(:organization) } - let (:member) { Fabricate(:member, organization: organization) } + let (:member) { Fabricate(:member, organization: organization, tags: member_tags) } let! (:offer) { Fabricate(:offer, user: member.user, organization: organization, tags: tags) } let! (:inquiry) { Fabricate(:inquiry, user: member.user, organization: organization, tags: more_tags) } @@ -11,20 +12,37 @@ end describe "GET index" do - it "returns http success" do - get :index + it "returns json and http success" do + get :index, params: { model: "post" } + 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(more_tags + tags) + get :index, params: { model: "post" } + + expect(assigns(:tags)).to eq(more_tags + tags) end it "with search term, returns filtered tags" do - get :index, params: { term: "foo" } - expect(assigns(:all_tags)).to eq(["foo"]) + get :index, params: { model: "post", term: "foo" } + + expect(assigns(:tags)).to eq(["foo"]) + end + + context "for members" do + it "with no search term, returns all members tags" do + get :index, params: { model: "member" } + + expect(assigns(:tags)).to eq(member_tags.uniq) + end + + it "with search term, returns filtered members tags" do + get :index, params: { model: "member", term: "htm" } + + expect(assigns(:tags)).to eq(%w(html html5)) + end end end @@ -34,7 +52,7 @@ it "load offers tags by default if no type is passed" do get :alpha_grouped_index - expect(assigns(:alpha_tags)).to eq({ + expect(assigns(:tags)).to eq({ "B" => [["bar", 1], ["baz", 1]], "F" => [["foo", 1]] }) @@ -43,12 +61,21 @@ it "load tags by type" do get :alpha_grouped_index, params: { post_type: "inquiry" } - expect(assigns(:alpha_tags)).to eq({ + expect(assigns(:tags)).to eq({ "J" => [["js", 1]], "R" => [["rails", 1], ["ruby", 1]] }) end + it "load member tags" do + get :alpha_grouped_index, params: { post_type: "user" } + + expect(assigns(:tags)).to eq({ + "H" => [["html", 2], ["html5", 1]], + "C" => [["css", 1]] + }) + end + it "renders a partial with format js" do get :alpha_grouped_index, xhr: true diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index da6f59000..5bed749df 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -118,7 +118,25 @@ user = Fabricate(:user, username: 'foo', email: 'foo@email.com') member = Fabricate(:member, user: user, organization: test_organization, member_uid: 1000) - get :index, params: { q: { user_username_or_user_email_or_member_uid_search_contains: 1000 } } + get :index, params: { q: { member_search_cont: 1000 } } + + expect(assigns(:members)).to include(member) + end + + it 'allows to search by member tags in searcher' do + user = Fabricate(:user, username: 'foo', email: 'foo@email.com') + member = Fabricate(:member, user: user, organization: test_organization, member_uid: 1000, tags: ["Boss"]) + + get :index, params: { q: { member_search_cont: "Bos" } } + + expect(assigns(:members)).to include(member) + end + + it 'allows to search by member tags clicking on one' do + user = Fabricate(:user, username: 'foo', email: 'foo@email.com') + member = Fabricate(:member, user: user, organization: test_organization, member_uid: 1000, tags: ["Boss"]) + + get :index, params: { tag: "Boss" } expect(assigns(:members)).to include(member) end @@ -167,7 +185,16 @@ user = Fabricate(:user, phone: 123456789) member = Fabricate(:member, user: user, organization: test_organization) - get :manage, params: { q: { user_username_or_user_email_or_user_phone_or_user_alt_phone_or_member_uid_search_contains: 123456789 } } + get :manage, params: { q: { member_search_cont: 123456789 } } + + expect(assigns(:members)).to include(member) + end + + it 'allows to search by member tags' do + user = Fabricate(:user) + member = Fabricate(:member, user: user, organization: test_organization, member_uid: 1000, tags: ["Boss"]) + + get :index, params: { q: { member_search_cont: "Bos" } } expect(assigns(:members)).to include(member) end @@ -311,11 +338,14 @@ username: user.username, email: user.email, phone: "1234", - alt_phone: "4321") } + alt_phone: "4321", + postcode: "40000"), tag_list: %w"tag1 tag2" } user.reload expect(user.phone).to eq("1234") expect(user.alt_phone).to eq("4321") + expect(user.postcode).to eq("40000") + expect(user.as_member_of(test_organization).tags).to eq(%w"tag1 tag2") end it "cannot change another user's attributes" do @@ -344,11 +374,14 @@ username: user.username, email: user.email, phone: "1234", - alt_phone: "4321") } + alt_phone: "4321", + postcode: "40000"), tag_list: %w"tag1 tag2" } user.reload expect(user.phone).to eq("1234") expect(user.alt_phone).to eq("4321") + expect(user.postcode).to eq("40000") + expect(user.as_member_of(test_organization).tags).to eq(%w"tag1 tag2") end end end