simple_form-polymorphic_associations 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/concerns/simple_form_polymorphic_associations/controller/autocomplete_concern.rb +1 -1
- data/app/concerns/simple_form_polymorphic_associations/model/autocomplete_concern.rb +2 -1
- data/app/inputs/polymorphic_association_input.rb +6 -3
- data/lib/simple_form-polymorphic_associations/spec_helpers/system.rb +39 -0
- data/lib/simple_form-polymorphic_associations/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0beb264dc98808fcc7bfa4a1ab6ec2bc5219663398877f1487731cf9059ee31b
|
4
|
+
data.tar.gz: 86032e0623b65c0a3dd998cc7b5c6b84fc062fba9337139820bf3b85e524f8a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '01261180fcd1e963563626f04bf25e4018e2b0d42b0a5474f827c37bed3f3e96a0959be69951094aaefa17423f71852fe1e8dbb066722124cb5e7ad76841aae0'
|
7
|
+
data.tar.gz: e25ca8e8f9a4631fee36fb20fdc9816096ee7b3a67b9fd13e038694a1bd82a442d41980248bb88325011391b9901e87748a730d551d6a4f6d67bfc170b5b782f
|
@@ -4,7 +4,7 @@ module SimpleFormPolymorphicAssociations
|
|
4
4
|
#
|
5
5
|
# # app/controllers/people_controller.rb
|
6
6
|
# class PeopleController < ApplicationController
|
7
|
-
# include SimpleFormPolymorphicAssociations::AutocompleteConcern
|
7
|
+
# include SimpleFormPolymorphicAssociations::Controller::AutocompleteConcern
|
8
8
|
# end
|
9
9
|
#
|
10
10
|
module AutocompleteConcern
|
@@ -4,7 +4,8 @@ module SimpleFormPolymorphicAssociations
|
|
4
4
|
#
|
5
5
|
# # app/models/person.rb
|
6
6
|
# class Person < ActiveRecord::Base
|
7
|
-
# include SimpleFormPolymorphicAssociations::AutocompleteConcern
|
7
|
+
# include SimpleFormPolymorphicAssociations::Model::AutocompleteConcern
|
8
|
+
#
|
8
9
|
# autocomplete scope: ->(matcher) { where("people.firstname LIKE :term", term: "%#{matcher.downcase}%") }, id_method: :id, text_method: :human
|
9
10
|
# end
|
10
11
|
#
|
@@ -46,13 +46,16 @@ class PolymorphicAssociationInput < SimpleForm::Inputs::Base
|
|
46
46
|
def input(wrapper_options = nil)
|
47
47
|
ActiveSupport::SafeBuffer.new.tap do |o|
|
48
48
|
collection = options[:classes].keys.collect { |c| [c.model_name.human, c] }
|
49
|
-
|
50
|
-
value_method = :to_s
|
49
|
+
instance_label_method = options.delete(:instance_label_method) || :to_s
|
51
50
|
o << @builder.select("#{attribute_name}_type", collection, { include_blank: true }, { class: 'form-control select required polymorphic-association-class-select' })
|
52
51
|
options[:classes].each do |klass, url|
|
53
52
|
o << "<a class=\"polymorphic-association-autocomplete-link\" data-class=\"#{klass}\" href=\"#{url}\" ></a>".html_safe
|
54
53
|
end
|
55
|
-
|
54
|
+
id_select_collection = []
|
55
|
+
if selected_record = object.send(attribute_name).presence
|
56
|
+
id_select_collection << [selected_record.send(instance_label_method), selected_record.id]
|
57
|
+
end
|
58
|
+
o << @builder.select("#{attribute_name}_id", id_select_collection, {}, { class: 'form-control select required polymorphic-association-resource-select' })
|
56
59
|
end
|
57
60
|
end
|
58
61
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module SimpleFormPolymorphicAssociations
|
2
|
+
module SpecHelpers
|
3
|
+
# Usage:
|
4
|
+
#
|
5
|
+
# # spec/support/simple_form-polymorphic_associations.rb
|
6
|
+
# require "simple_form-polymorphic_associations/spec_helpers/system"
|
7
|
+
#
|
8
|
+
# RSpec.configure do |config|
|
9
|
+
# config.include SimpleFormPolymorphicAssociations::SpecHelpers::System, type: :system
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
module System
|
13
|
+
# Usage:
|
14
|
+
#
|
15
|
+
# # spec/system/projects_spec.rb
|
16
|
+
# require "rails_helper"
|
17
|
+
#
|
18
|
+
# RSpec.describe "Projects", type: :system, js: true do
|
19
|
+
# let(:user) { create(:user) }
|
20
|
+
#
|
21
|
+
# before(:each) { user }
|
22
|
+
#
|
23
|
+
# it do
|
24
|
+
# visit "/projects/new"
|
25
|
+
# polymorphic_select(user, :name, from: "project[owner_id]")
|
26
|
+
# find("input[type='submit']").click
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
def polymorphic_select(record, label_method, options)
|
31
|
+
select record.class.model_name.human, from: options[:from].gsub(/_id]$/, "_type]")
|
32
|
+
first(".select2-container", minimum: 1).click
|
33
|
+
find(".select2-search--dropdown input.select2-search__field").send_keys(user.send(label_method))
|
34
|
+
sleep(1)
|
35
|
+
find(".select2-search--dropdown input.select2-search__field").send_keys(:enter)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form-polymorphic_associations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Vasquez Angel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_form
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- config/initializers/assets.rb
|
43
43
|
- lib/simple_form-polymorphic_associations.rb
|
44
44
|
- lib/simple_form-polymorphic_associations/engine.rb
|
45
|
+
- lib/simple_form-polymorphic_associations/spec_helpers/system.rb
|
45
46
|
- lib/simple_form-polymorphic_associations/version.rb
|
46
47
|
homepage:
|
47
48
|
licenses:
|
@@ -62,8 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
63
|
- !ruby/object:Gem::Version
|
63
64
|
version: '0'
|
64
65
|
requirements: []
|
65
|
-
|
66
|
-
rubygems_version: 2.7.8
|
66
|
+
rubygems_version: 3.3.26
|
67
67
|
signing_key:
|
68
68
|
specification_version: 4
|
69
69
|
summary: Simple Form polymorphic associations.
|