polygallery 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49a28708abb8cca57bc55038fc319c6c282028cc
4
- data.tar.gz: 7a743956ff2b910dae1c4bab9b569b4a6a9fa5e9
3
+ metadata.gz: d5677a62369074c87bcb244a40524461ef19e0ff
4
+ data.tar.gz: cc56143ab682bc3d307573f4484c0b88e897370a
5
5
  SHA512:
6
- metadata.gz: f5372a9227768bb0c008a246487cd33cb0937a09826c6fa743acd0d76317605a3f64a82ebe2bc25e95aca814b0d0fe87205767cb7a9f69c38d4192a425ee4b07
7
- data.tar.gz: 1a8a04395a265f4ba928cb833beafd2c8571ea5f9586b897e06810ba870a24238d181c3aca952eeab809b9994cfbf5904c9df921b9b305bb38268146f87ddf11
6
+ metadata.gz: fa6d708ebf3b9be3852540dd193952016f102e56c88c423735fa770dbfd3c6b6ee52a5d7fc8e718dcfc274427fcea75f7324d6b6e796dd1968a3feef3d877c30
7
+ data.tar.gz: c1f82b8cf65bed7f766f1c9db488eae729c21fd25f8bb6ecdc2fecf00f191b49d4542bd95fd08c45005927773c0c18df5fb67eb7f9b107270a0fb42208b81cea
@@ -1,22 +1,51 @@
1
1
  require 'polygallery/factories'
2
2
  module Polygallery
3
3
  module CapybaraHelpers
4
- def add_photo_to_form(attrs=nil, table_id='photos')
4
+ def select_polyphoto_tr(i=0, table_id='photos')
5
+ all(".polygallery-cocoon-table##{table_id} tbody tr").to_a[i] end
6
+
7
+ def add_photo_to_form(table_id='photos', attrs=nil)
8
+ unless table_id.is_a? String
9
+ attrs = table_id; table_id = 'photos' end
5
10
  attrs ||= build :polygallery_photo
6
- tr_selector = ".polygallery-cocoon-table##{table_id} tr"
7
- last_tr = all(tr_selector).last
8
- if last_tr.find('input[id$="_photo"]').value.present?
11
+ tr_selector = ".polygallery-cocoon-table##{table_id} tbody tr"
12
+ trs = all(tr_selector); last_tr = trs.last
13
+ unless trs.length == 1 && last_tr.find('input[id$="_photo"]').value.blank?
9
14
  page.execute_script <<-SCRIPT
10
- $('.btn.add_fields[data-association-insertion-node="##{table_id} .photo-receptacle"]').click();
15
+ $('.add_fields[data-association-insertion-node="##{table_id} .photo-receptacle"]').click();
11
16
  SCRIPT
12
17
  last_tr = all(tr_selector).last
13
18
  end
14
19
  within last_tr do
15
- random_photo = get_random_photo
16
- find('input[id$="_photo"]').set random_photo
20
+ find('input[id$="_photo"]').set get_random_photo
17
21
  find('input[id$="_caption"]').set(attrs.caption)
18
22
  yield if block_given?
19
23
  end
20
24
  end
25
+
26
+ def change_photo_in_form(photo_index=0, table_id='photos', file_to_use=nil)
27
+ if photo_index.is_a? File
28
+ file_to_use = photo_index; photo_index = 0 end
29
+ if table_id.is_a? File
30
+ file_to_use = table_id; table_id = 'photos' end
31
+ if photo_index.is_a? String
32
+ table_id = photo_index; photo_index = 0 end
33
+ file_to_use ||= get_random_photo
34
+ within select_polyphoto_tr(photo_index, table_id) do |tr|
35
+ file_input = find('input[id$="_photo"]')
36
+ file_input.set file_to_use
37
+ yield(tr) if block_given?
38
+ end
39
+ end
40
+
41
+ def remove_photo_from_form(photo_index=0, table_id='photos')
42
+ if photo_index.is_a? String
43
+ table_id = photo_index; photo_index = 0 end
44
+ tr_selector = ".polygallery-cocoon-table##{table_id} tbody tr:nth-child(#{photo_index + 1})"
45
+ page.execute_script <<-SCRIPT
46
+ $('#{tr_selector} .remove_fields').click();
47
+ SCRIPT
48
+ end
49
+
21
50
  end
22
51
  end
@@ -182,13 +182,14 @@ module Polygallery
182
182
  build_gallery_associations.map(&:build_first_photo)
183
183
  end
184
184
 
185
- def first_polyphoto
185
+ def first_polyphoto(ga_name=nil)
186
186
  return Photo.new unless gallery_associations.any?
187
- fg = gallery_associations.to_a.find{|pg| pg.photos.any? }
188
- return Photo.new if fg.nil?
189
- fg.first_photo
187
+ ga = if ga_name.present? then send(ga_name)
188
+ else gallery_associations.to_a.find{|pg| pg.photos.any? } end
189
+ return Photo.new if ga.nil?
190
+ ga.first_photo
190
191
  end
191
- def first_photo; first_polyphoto.photo end
192
+ def first_photo(ga_name=nil); first_polyphoto(ga_name).photo end
192
193
 
193
194
  def ensure_galleryable_set
194
195
  gallery_associations.each do |ga|
@@ -110,8 +110,6 @@ module Polygallery
110
110
  end
111
111
 
112
112
  def build_polygallery_photos
113
- # puts "BUILDING PHOTOS for #{title}"
114
- # puts "PHOTO ATTRS: #{self.photos_attributes.inspect}"
115
113
  # Convert attributes to array if in hash form
116
114
  # self.photos_attributes =
117
115
  # self.photos_attributes.map{|_, v| v
@@ -128,7 +126,7 @@ module Polygallery
128
126
 
129
127
  attrs_for_photos.each_with_index do |attrs_for_photo, index|
130
128
  attrs_for_photo[:polygallery_options] = self.polygallery_settings
131
- should_destroy = attrs_for_photo.delete(:_destroy) == 'true'
129
+ should_destroy = %w(true 1).include? attrs_for_photo.delete(:_destroy)
132
130
  if attrs_for_photo.key? :id
133
131
  existing_id = attrs_for_photo.delete(:id).to_i
134
132
  existing_photo = self.polygallery_photos_class.find existing_id
@@ -138,15 +136,9 @@ module Polygallery
138
136
  else
139
137
  # puts 'Updating an existing photo'
140
138
  existing_photo.update_attributes attrs_for_photo end
141
- # elsif attrs_for_photo.key? :built
142
- # puts 'Photo already built'
143
139
  else
144
140
  # puts 'Building a new photo'
145
- # puts attrs_for_photo.inspect
146
- # built_photo =
147
141
  self.polygallery_photos.build attrs_for_photo
148
- # set_nest built_photo
149
- # self.polygallery_photos_attributes[index][:built] = true
150
142
  end
151
143
  end
152
144
  self.photos_built = true
@@ -1,3 +1,3 @@
1
1
  module Polygallery
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polygallery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - MacKinley Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-22 00:00:00.000000000 Z
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails