Skip to content

Commit 1703809

Browse files
authored
Merge pull request #619 from coopdevs/admin_post_tags
admin: fix post creation with tags
2 parents bbc8a70 + 2705cd0 commit 1703809

File tree

6 files changed

+33
-25
lines changed

6 files changed

+33
-25
lines changed

app/admin/post.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
index do
33
id_column
44
column :class
5+
column :is_group
56
column :title
67
column :created_at do |post|
78
l post.created_at.to_date, format: :long
@@ -19,10 +20,11 @@
1920
f.input :type, as: :radio, collection: %w[Offer Inquiry]
2021
f.input :title
2122
f.input :organization
22-
f.input :user, hint: "* should be member of the selected organization"
23+
f.input :user, hint: "Should be member of the selected organization"
2324
f.input :category
2425
f.input :description
25-
f.input :tag_list
26+
f.input :tag_list, hint: "Accepts comma separated values"
27+
f.input :is_group
2628
f.input :active
2729
end
2830
f.actions
@@ -36,6 +38,7 @@
3638
filter :organization
3739
filter :user
3840
filter :category
41+
filter :is_group
3942
filter :active
4043
filter :created_at
4144
end

app/admin/user.rb

+2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
filter :organizations
3030
filter :email
3131
filter :username
32+
filter :phone
3233

3334
form do |f|
3435
f.semantic_errors *f.object.errors.keys
3536
f.inputs do
3637
f.input :username
3738
f.input :email
39+
f.input :phone
3840
f.input :gender, as: :select, collection: User::GENDERS
3941
f.input :identity_document
4042
end

app/models/concerns/taggable.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ def tag_list
1313
tags && tags.join(", ")
1414
end
1515

16-
def tag_list=(tag_list)
17-
self.tags = tag_list.reject(&:empty?)
16+
def tag_list=(new_tags)
17+
new_tags = new_tags.split(",").map(&:strip) if new_tags.is_a?(String)
18+
19+
self.tags = new_tags.reject(&:empty?)
1820
end
1921

2022
module ClassMethods

spec/fabricators/member_fabricator.rb

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
Fabricator(:member) do
2-
32
user { Fabricate(:user) }
43
organization { Fabricate(:organization) }
54
manager false
65
active true
7-
86
end

spec/fabricators/post_fabricator.rb

-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
Fabricator(:post) do
2-
32
title { Faker::Lorem.sentence }
43
user { Fabricate(:user) }
54
description { Faker::Lorem.paragraph }
65
category { Fabricate(:category) }
76
active { true }
8-
97
end
108

119
Fabricator(:inquiry) do
12-
1310
type "Inquiry"
1411

1512
title { Faker::Lorem.sentence }
@@ -21,13 +18,11 @@
2118
end
2219

2320
Fabricator(:offer) do
24-
2521
type "Offer"
2622

2723
title { Faker::Lorem.sentence }
2824
user { Fabricate(:user) }
2925
description { Faker::Lorem.paragraph }
3026
category { Fabricate(:category) }
3127
active { true }
32-
3328
end

spec/models/taggable_spec.rb

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
RSpec.describe Taggable do
22
let(:organization) { Fabricate(:organization) }
3-
3+
let(:tags) { %w(foo bar baz) }
4+
let(:more_tags) { %w(foo baz qux) }
45
let!(:offer) do
56
Fabricate(
67
:offer,
@@ -17,9 +18,6 @@
1718
end
1819

1920
context "class methods and scopes" do
20-
let(:tags) { %w(foo bar baz) }
21-
let(:more_tags) { %w(foo baz qux) }
22-
2321
it "tagged_with" do
2422
expect(Offer.tagged_with("bar")).to eq [offer]
2523
end
@@ -33,18 +31,28 @@
3331
expect(Offer.find_like_tag("Foo")).to eq ["foo"]
3432
expect(Offer.find_like_tag("none")).to eq []
3533
end
36-
end
3734

38-
describe '.alphabetical_grouped_tags' do
39-
let(:tags) { %w(foo bar baz Boo) }
40-
let(:more_tags) { %w(foo baz qux) }
35+
describe '.alphabetical_grouped_tags' do
36+
let(:tags) { %w(foo bar baz Boo) }
37+
let(:more_tags) { %w(foo baz qux) }
4138

42-
it 'sorts them by alphabetical order case insensitive' do
43-
expect(Offer.alphabetical_grouped_tags).to eq({
44-
'B' => [['bar', 1], ['baz', 2], ['Boo', 1]],
45-
'F' => [['foo', 2]],
46-
'Q' => [['qux', 1]]
47-
})
39+
it 'sorts them by alphabetical order case insensitive' do
40+
expect(Offer.alphabetical_grouped_tags).to eq({
41+
'B' => [['bar', 1], ['baz', 2], ['Boo', 1]],
42+
'F' => [['foo', 2]],
43+
'Q' => [['qux', 1]]
44+
})
45+
end
4846
end
4947
end
48+
49+
it "#tag_list= writter accepts string and array" do
50+
offer = Offer.new
51+
52+
offer.tag_list = ["a", "b"]
53+
expect(offer.tag_list).to eq "a, b"
54+
55+
offer.tag_list = "c, d"
56+
expect(offer.tag_list).to eq "c, d"
57+
end
5058
end

0 commit comments

Comments
 (0)