selections 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +3 -1
- data/README.md +2 -2
- data/lib/generators/selections_scaffold/selections_scaffold_generator.rb +1 -1
- data/lib/selections/form_builder_extensions.rb +1 -1
- data/lib/selections/selectable.rb +8 -8
- data/lib/selections/version.rb +1 -1
- data/spec/selections/selections_tag_spec.rb +1 -2
- metadata +2 -3
- data/lib/generators/selections_scaffold/templates/.DS_Store +0 -0
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
## 0.2.
|
1
|
+
## 0.2.2
|
2
|
+
* https://github.com/nigelr/selections/pull/14 - Update selections to no longer use hash rocket syntax.
|
2
3
|
|
4
|
+
## 0.2.1
|
3
5
|
* Check the existence of the selections table in `belongs_to_selection` so it is safe to use during rake tasks like db:reset.
|
4
6
|
|
5
7
|
## 0.1.14 (should of been 0.2.0)
|
data/README.md
CHANGED
@@ -120,7 +120,7 @@ The selections method excepts all the standard Ruby on Rails form helper options
|
|
120
120
|
If you have a selection named differently to the foreign key eg. the foreign key is variety_id, you can use a system_code option.
|
121
121
|
|
122
122
|
```ruby
|
123
|
-
<%= f.selections :variety, :
|
123
|
+
<%= f.selections :variety, system_code: :category %>
|
124
124
|
```
|
125
125
|
|
126
126
|
### Radio Buttons Options
|
@@ -199,7 +199,7 @@ Thanks to @mattconnolly
|
|
199
199
|
In a new form the selections list will have blank top row unless a default item is set in the selections eg. Medium Priority, then there
|
200
200
|
will be no blank row and the default item will be selected.
|
201
201
|
|
202
|
-
When editing a form, by default the blank row will not be displayed. Use the options :
|
202
|
+
When editing a form, by default the blank row will not be displayed. Use the options include_blank: true option to override.
|
203
203
|
|
204
204
|
#### Archived Item
|
205
205
|
|
@@ -29,7 +29,7 @@ class SelectionsScaffoldGenerator < Rails::Generators::Base
|
|
29
29
|
|
30
30
|
migration_template 'create_selections.rb', 'db/migrate/create_selections.rb'
|
31
31
|
|
32
|
-
route 'resources(:selections, :
|
32
|
+
route 'resources(:selections, only: :index) { resources :selections, except: :show }'
|
33
33
|
|
34
34
|
end
|
35
35
|
end
|
@@ -12,14 +12,14 @@ module Selections
|
|
12
12
|
# Setup any required model information for a selectable model.
|
13
13
|
acts_as_tree
|
14
14
|
|
15
|
-
validate :name, :
|
15
|
+
validate :name, existence: true
|
16
16
|
validates_presence_of :name
|
17
|
-
validates_uniqueness_of :name, :
|
18
|
-
validates_uniqueness_of :system_code, :
|
17
|
+
validates_uniqueness_of :name, scope: :parent_id
|
18
|
+
validates_uniqueness_of :system_code, scope: :archived_at
|
19
19
|
validates_format_of :system_code, :with => /^[a-z][a-zA-Z_0-9]*$/, :message => "can only contain alphanumeric characters and '_', not spaces"
|
20
20
|
|
21
|
-
before_validation :auto_gen_system_code, :
|
22
|
-
before_validation :disable_system_code_change, :
|
21
|
+
before_validation :auto_gen_system_code, on: :create
|
22
|
+
before_validation :disable_system_code_change, on: :update
|
23
23
|
after_validation :check_defaults
|
24
24
|
|
25
25
|
default_scope :order => [:position_value, :name]
|
@@ -43,9 +43,9 @@ module Selections
|
|
43
43
|
# Selection.priorities => returns [high, medium, low] instances (children)
|
44
44
|
|
45
45
|
def method_missing lookup_code, *options
|
46
|
-
if (scope = where(:
|
46
|
+
if (scope = where(system_code: lookup_code.to_s)).exists?
|
47
47
|
scope.first
|
48
|
-
elsif (scope = where(:
|
48
|
+
elsif (scope = where(system_code: lookup_code.to_s.singularize)).exists?
|
49
49
|
scope.first.children
|
50
50
|
else
|
51
51
|
super
|
@@ -118,7 +118,7 @@ module Selections
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def siblings_with_default_set #:nodoc:
|
121
|
-
self.parent.children.where(:
|
121
|
+
self.parent.children.where(is_default: true).where("id != ?", self.id.to_i).first
|
122
122
|
end
|
123
123
|
|
124
124
|
def archived #:nodoc:
|
data/lib/selections/version.rb
CHANGED
@@ -318,8 +318,7 @@ describe SelectionTag do
|
|
318
318
|
end
|
319
319
|
it 'returns valid html' do
|
320
320
|
ticket.update_attribute(:priority_id, selection_3.id)
|
321
|
-
|
322
|
-
expect(edit_form(options: {:include_blank => true}, html_options: {class: 'fred'}).radio_tag).to eq "<label class=\"fred\" for=\"ticket_priority_id\"><input class=\"fred\" id=\"ticket_priority_id\" name=\"ticket[priority_id]\" type=\"radio\" />none</label><label class=\"fred\" for=\"ticket_priority_id_4\"><input checked=\"checked\" class=\"fred\" id=\"ticket_priority_id_4\" name=\"ticket[priority_id]\" type=\"radio\" value=\"4\" />high</label><label checked=\"checked\" class=\"fred\" for=\"ticket_priority_id_2\"><input class=\"fred\" id=\"ticket_priority_id_2\" name=\"ticket[priority_id]\" type=\"radio\" value=\"2\" />low</label><label class=\"fred\" for=\"ticket_priority_id_3\"><input class=\"fred\" id=\"ticket_priority_id_3\" name=\"ticket[priority_id]\" type=\"radio\" value=\"3\" />medium</label>"
|
321
|
+
expect(edit_form(options: {include_blank: true}, html_options: {class: 'fred'}).radio_tag).to eq "<label class=\"fred\" for=\"ticket_priority_id\"><input class=\"fred\" id=\"ticket_priority_id\" name=\"ticket[priority_id]\" type=\"radio\" />none</label><label class=\"fred\" for=\"ticket_priority_id_4\"><input checked=\"checked\" class=\"fred\" id=\"ticket_priority_id_4\" name=\"ticket[priority_id]\" type=\"radio\" value=\"4\" />high</label><label checked=\"checked\" class=\"fred\" for=\"ticket_priority_id_2\"><input class=\"fred\" id=\"ticket_priority_id_2\" name=\"ticket[priority_id]\" type=\"radio\" value=\"2\" />low</label><label class=\"fred\" for=\"ticket_priority_id_3\"><input class=\"fred\" id=\"ticket_priority_id_3\" name=\"ticket[priority_id]\" type=\"radio\" value=\"3\" />medium</label>"
|
323
322
|
end
|
324
323
|
end
|
325
324
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: selections
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -157,7 +157,6 @@ files:
|
|
157
157
|
- README.md
|
158
158
|
- Rakefile
|
159
159
|
- lib/generators/selections_scaffold/selections_scaffold_generator.rb
|
160
|
-
- lib/generators/selections_scaffold/templates/.DS_Store
|
161
160
|
- lib/generators/selections_scaffold/templates/_form.html.haml
|
162
161
|
- lib/generators/selections_scaffold/templates/create_selections.rb
|
163
162
|
- lib/generators/selections_scaffold/templates/edit.html.erb
|
Binary file
|