Skip to content

admin: fix post creation with tags #619

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

Merged
merged 1 commit into from
Apr 25, 2021
Merged
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
7 changes: 5 additions & 2 deletions app/admin/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
index do
id_column
column :class
column :is_group
column :title
column :created_at do |post|
l post.created_at.to_date, format: :long
Expand All @@ -19,10 +20,11 @@
f.input :type, as: :radio, collection: %w[Offer Inquiry]
f.input :title
f.input :organization
f.input :user, hint: "* should be member of the selected organization"
f.input :user, hint: "Should be member of the selected organization"
f.input :category
f.input :description
f.input :tag_list
f.input :tag_list, hint: "Accepts comma separated values"
f.input :is_group
f.input :active
end
f.actions
Expand All @@ -36,6 +38,7 @@
filter :organization
filter :user
filter :category
filter :is_group
filter :active
filter :created_at
end
2 changes: 2 additions & 0 deletions app/admin/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
filter :organizations
filter :email
filter :username
filter :phone

form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs do
f.input :username
f.input :email
f.input :phone
f.input :gender, as: :select, collection: User::GENDERS
f.input :identity_document
end
Expand Down
6 changes: 4 additions & 2 deletions app/models/concerns/taggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ def tag_list
tags && tags.join(", ")
end

def tag_list=(tag_list)
self.tags = tag_list.reject(&:empty?)
def tag_list=(new_tags)
new_tags = new_tags.split(",").map(&:strip) if new_tags.is_a?(String)

self.tags = new_tags.reject(&:empty?)
end

module ClassMethods
Expand Down
2 changes: 0 additions & 2 deletions spec/fabricators/member_fabricator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Fabricator(:member) do

user { Fabricate(:user) }
organization { Fabricate(:organization) }
manager false
active true

end
5 changes: 0 additions & 5 deletions spec/fabricators/post_fabricator.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
Fabricator(:post) do

title { Faker::Lorem.sentence }
user { Fabricate(:user) }
description { Faker::Lorem.paragraph }
category { Fabricate(:category) }
active { true }

end

Fabricator(:inquiry) do

type "Inquiry"

title { Faker::Lorem.sentence }
Expand All @@ -21,13 +18,11 @@
end

Fabricator(:offer) do

type "Offer"

title { Faker::Lorem.sentence }
user { Fabricate(:user) }
description { Faker::Lorem.paragraph }
category { Fabricate(:category) }
active { true }

end
36 changes: 22 additions & 14 deletions spec/models/taggable_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
RSpec.describe Taggable do
let(:organization) { Fabricate(:organization) }

let(:tags) { %w(foo bar baz) }
let(:more_tags) { %w(foo baz qux) }
let!(:offer) do
Fabricate(
:offer,
Expand All @@ -17,9 +18,6 @@
end

context "class methods and scopes" do
let(:tags) { %w(foo bar baz) }
let(:more_tags) { %w(foo baz qux) }

it "tagged_with" do
expect(Offer.tagged_with("bar")).to eq [offer]
end
Expand All @@ -33,18 +31,28 @@
expect(Offer.find_like_tag("Foo")).to eq ["foo"]
expect(Offer.find_like_tag("none")).to eq []
end
end

describe '.alphabetical_grouped_tags' do
let(:tags) { %w(foo bar baz Boo) }
let(:more_tags) { %w(foo baz qux) }
describe '.alphabetical_grouped_tags' do
let(:tags) { %w(foo bar baz Boo) }
let(:more_tags) { %w(foo baz qux) }

it 'sorts them by alphabetical order case insensitive' do
expect(Offer.alphabetical_grouped_tags).to eq({
'B' => [['bar', 1], ['baz', 2], ['Boo', 1]],
'F' => [['foo', 2]],
'Q' => [['qux', 1]]
})
it 'sorts them by alphabetical order case insensitive' do
expect(Offer.alphabetical_grouped_tags).to eq({
'B' => [['bar', 1], ['baz', 2], ['Boo', 1]],
'F' => [['foo', 2]],
'Q' => [['qux', 1]]
})
end
end
end

it "#tag_list= writter accepts string and array" do
offer = Offer.new

offer.tag_list = ["a", "b"]
expect(offer.tag_list).to eq "a, b"

offer.tag_list = "c, d"
expect(offer.tag_list).to eq "c, d"
end
end