autoforme 0.5.1 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c90629ac93941ca426fb8db3fbb83618a367330c
4
- data.tar.gz: 756db19ef87d030d8c4d233521f20b8a18bfbb31
3
+ metadata.gz: 38de0a66935c0a09e6b2e4302fad7860f051aa35
4
+ data.tar.gz: 1fd338240c95d55401ea5e44f0c949f575fdad7b
5
5
  SHA512:
6
- metadata.gz: 5f879772b9cefac7eef9cc136510e7fa1e2297ba4ce6dec115b23c5acaf6f6b1835c94e092ea460ec5c5de05d855ae975b040a3771991c84e3affd072f450a39
7
- data.tar.gz: 3509bedb63c7ee892a4e6cf077aa4ea4175a0013a27ecb8a88cc17fe0edf642b4328455a667d9b275d9a0e07196d49323a5340eab8d5e6899811eda509793501
6
+ metadata.gz: 97edee23d620a6e9854f6a7c105909687b80d31a71e6bcfcf2bb98cae1244a592b622ebe7a5c791169c41f5e37bf06e28b07c371c41a2e27a82a31927b6737b5
7
+ data.tar.gz: 08356511c1ae30e5c8db04b8ab8e95ecb57a475b2fa0a56fd5f9ccba549ccfd3b7791007e4df766011e6d77dcda7a4d75dd5321c1653eaad416bc6c271af43b3
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ === 0.5.2 (2013-12-18)
2
+
3
+ * Use default empty option when picking a many to many association to edit (jeremyevans)
4
+
5
+ * Don't force user to pick many to many association to edit if only one choice is available (jeremyevans)
6
+
7
+ * Don't show many to many edit link for models without many to many associations (jeremyevans)
8
+
9
+ * Quailfy columns when searching, fixing issues when eager_graph is used on the model (jeremyevans)
10
+
1
11
  === 0.5.1 (2013-12-17)
2
12
 
3
13
  * Show header with display name for current object on mtm edit page (jeremyevans)
@@ -426,7 +426,13 @@ module AutoForme
426
426
  def handle_mtm_edit
427
427
  if id = request.id
428
428
  obj = model.with_pk(:edit, request, request.id)
429
- if assoc = params_association
429
+ unless assoc = params_association
430
+ options = model.mtm_association_select_options(request)
431
+ if options.length == 1
432
+ assoc = options.first
433
+ end
434
+ end
435
+ if assoc
430
436
  page do
431
437
  t = "<h2>Edit #{humanize(assoc)} for #{h model.object_display_name(type, request, obj)}</h2>"
432
438
  t << Forme.form(obj, form_attributes(:action=>url_for("mtm_update/#{model.primary_key_value(obj)}?association=#{assoc}")), form_opts) do |f|
@@ -446,7 +452,7 @@ module AutoForme
446
452
  else
447
453
  page do
448
454
  Forme.form(form_attributes(:action=>"mtm_edit/#{model.primary_key_value(obj)}"), form_opts) do |f|
449
- f.input(:select, :options=>model.mtm_association_select_options(request), :name=>'association', :id=>'association', :label=>'Association')
455
+ f.input(:select, :options=>options, :name=>'association', :id=>'association', :label=>'Association', :add_blank=>true)
450
456
  f.button(:value=>'Edit', :class=>'btn btn-primary')
451
457
  end
452
458
  end
@@ -49,7 +49,13 @@ module AutoForme
49
49
 
50
50
  # Whether the given type of action is supported for this model.
51
51
  def supported_action?(type, request)
52
- (handle_proc(supported_actions || framework.supported_actions_for(model, request), request) || DEFAULT_SUPPORTED_ACTIONS).include?(type)
52
+ v = (handle_proc(supported_actions || framework.supported_actions_for(model, request), request) || DEFAULT_SUPPORTED_ACTIONS).include?(type)
53
+ if v && type == :mtm_edit
54
+ assocs = mtm_association_select_options(request)
55
+ assocs && !assocs.empty?
56
+ else
57
+ v
58
+ end
53
59
  end
54
60
 
55
61
  # An array of many to many association symbols to handle via a separate mtm_edit page.
@@ -172,9 +172,9 @@ module AutoForme
172
172
  primary_key = S.qualify(ref.associated_class.table_name, ref.primary_key)
173
173
  ds = ds.where(ref[:key]=>ads.where(primary_key=>v).select(primary_key))
174
174
  elsif column_type(c) == :string
175
- ds = ds.where(S.ilike(c, "%#{ds.escape_like(v.to_s)}%"))
175
+ ds = ds.where(S.ilike(S.qualify(model.table_name, c), "%#{ds.escape_like(v.to_s)}%"))
176
176
  else
177
- ds = ds.where(c=>v.to_s)
177
+ ds = ds.where(S.qualify(model.table_name, c)=>v.to_s)
178
178
  end
179
179
  end
180
180
  end
@@ -1,6 +1,6 @@
1
1
  module AutoForme
2
2
  # Version constant, use <tt>AutoForme.version</tt> instead.
3
- VERSION = '0.5.1'.freeze
3
+ VERSION = '0.5.2'.freeze
4
4
 
5
5
  # Returns the version as a frozen string (e.g. '0.1.0')
6
6
  def self.version
data/spec/mtm_spec.rb CHANGED
@@ -10,6 +10,18 @@ describe AutoForme do
10
10
  Object.send(:remove_const, :Artist)
11
11
  end
12
12
 
13
+ it "should not show MTM link if there are no many to many associations" do
14
+ app_setup do
15
+ model Artist
16
+ model Album
17
+ end
18
+
19
+ visit("/Artist/browse")
20
+ page.html.should_not =~ /MTM/
21
+ visit("/Artist/mtm_edit")
22
+ page.html.should =~ /Unhandled Request/
23
+ end
24
+
13
25
  it "should have basic many to many association editing working" do
14
26
  app_setup do
15
27
  model Artist do
@@ -28,9 +40,6 @@ describe AutoForme do
28
40
  select("Artist1")
29
41
  click_button "Edit"
30
42
 
31
- select("albums")
32
- click_button "Edit"
33
-
34
43
  find('h2').text.should == 'Edit Albums for Artist1'
35
44
  all('select')[0].all('option').map{|s| s.text}.should == ["Album1", "Album2", "Album3"]
36
45
  all('select')[1].all('option').map{|s| s.text}.should == []
@@ -70,9 +79,6 @@ describe AutoForme do
70
79
  select("Artist1")
71
80
  click_button "Edit"
72
81
 
73
- select("albums")
74
- click_button "Edit"
75
-
76
82
  all('select')[0].all('option').map{|s| s.text}.should == []
77
83
  fill_in "Associate With", :with=>a1.id
78
84
  click_button "Update"
@@ -213,9 +219,6 @@ describe AutoForme do
213
219
  select("Artist1")
214
220
  click_button "Edit"
215
221
 
216
- select("albums")
217
- click_button "Edit"
218
-
219
222
  all('select')[0].all('option').map{|s| s.text}.should == ["Album1", "Album2", "Album3"]
220
223
  all('select')[1].all('option').map{|s| s.text}.should == []
221
224
  select("Album1", :from=>"Associate With")
@@ -253,8 +256,6 @@ describe AutoForme do
253
256
  visit("/Artist/mtm_edit")
254
257
  select("Artist1")
255
258
  click_button "Edit"
256
- select("albums")
257
- click_button "Edit"
258
259
 
259
260
  all('select')[0].all('option').map{|s| s.text}.should == ["B1", "E1"]
260
261
  all('select')[1].all('option').map{|s| s.text}.should == []
@@ -279,8 +280,6 @@ describe AutoForme do
279
280
  visit('/Artist/mtm_edit')
280
281
  select("Artist1")
281
282
  click_button "Edit"
282
- select("albums")
283
- click_button "Edit"
284
283
  select("E1", :from=>"Associate With")
285
284
  Album.where(:name=>'E1').update(:name=>'Y1')
286
285
  proc{click_button "Update"}.should raise_error(Sequel::NoMatchingRow)
@@ -288,8 +287,6 @@ describe AutoForme do
288
287
  visit('/Artist/mtm_edit')
289
288
  select("Artist1")
290
289
  click_button "Edit"
291
- select("albums")
292
- click_button "Edit"
293
290
  all('select')[0].all('option').map{|s| s.text}.should == []
294
291
  all('select')[1].all('option').map{|s| s.text}.should == []
295
292
  end
@@ -314,9 +311,6 @@ describe AutoForme do
314
311
  select("Artist1")
315
312
  click_button "Edit"
316
313
 
317
- select("albums")
318
- click_button "Edit"
319
-
320
314
  check "Album12"
321
315
  click_button "Update"
322
316
  Artist.first.albums.map{|x| x.name}.should == %w'Album1'
@@ -332,3 +326,55 @@ describe AutoForme do
332
326
  check "Album3Album3"
333
327
  end
334
328
  end
329
+
330
+ describe AutoForme do
331
+ before(:all) do
332
+ db_setup(:artists=>[[:name, :string]], :albums=>[[:name, :string]], :albums_artists=>[[:album_id, :integer, {:table=>:albums}], [:artist_id, :integer, {:table=>:artists}]])
333
+ model_setup(:Artist=>[:artists, [[:many_to_many, :albums]], [[:many_to_many, :other_albums, {:clone=>:albums}]]], :Album=>[:albums, [[:many_to_many, :artists]]])
334
+ end
335
+ after(:all) do
336
+ Object.send(:remove_const, :Album)
337
+ Object.send(:remove_const, :Artist)
338
+ end
339
+
340
+ it "should have basic many to many association editing working" do
341
+ app_setup do
342
+ model Artist do
343
+ mtm_associations [:albums, :other_albums]
344
+ end
345
+ model Album
346
+ end
347
+
348
+ Artist.create(:name=>'Artist1')
349
+ Album.create(:name=>'Album1')
350
+ Album.create(:name=>'Album2')
351
+ Album.create(:name=>'Album3')
352
+
353
+ visit("/Artist/mtm_edit")
354
+ page.find('title').text.should == 'Artist - Many To Many Edit'
355
+ select("Artist1")
356
+ click_button "Edit"
357
+
358
+ select('albums')
359
+ click_button "Edit"
360
+
361
+ find('h2').text.should == 'Edit Albums for Artist1'
362
+ all('select')[0].all('option').map{|s| s.text}.should == ["Album1", "Album2", "Album3"]
363
+ all('select')[1].all('option').map{|s| s.text}.should == []
364
+ select("Album1", :from=>"Associate With")
365
+ click_button "Update"
366
+ page.html.should =~ /Updated albums association for Artist/
367
+ Artist.first.albums.map{|x| x.name}.should == %w'Album1'
368
+
369
+ all('select')[0].all('option').map{|s| s.text}.should == ["Album2", "Album3"]
370
+ all('select')[1].all('option').map{|s| s.text}.should == ["Album1"]
371
+ select("Album2", :from=>"Associate With")
372
+ select("Album3", :from=>"Associate With")
373
+ select("Album1", :from=>"Disassociate From")
374
+ click_button "Update"
375
+ Artist.first.refresh.albums.map{|x| x.name}.should == %w'Album2 Album3'
376
+
377
+ all('select')[0].all('option').map{|s| s.text}.should == ["Album1"]
378
+ all('select')[1].all('option').map{|s| s.text}.should == ["Album2", "Album3"]
379
+ end
380
+ end
@@ -12,6 +12,9 @@ class AutoFormeSpec::App < Sinatra::Base
12
12
  register Sinatra::Flash
13
13
  use Rack::Csrf
14
14
 
15
+ not_found do
16
+ 'Unhandled Request'
17
+ end
15
18
  get '/session/set' do
16
19
  session.merge!(params)
17
20
  ''
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoforme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-17 00:00:00.000000000 Z
11
+ date: 2013-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: forme
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.0
19
+ version: 0.9.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.0
26
+ version: 0.9.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rack
29
29
  requirement: !ruby/object:Gem::Requirement