best_in_place 1.0.0 → 1.0.1

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.
@@ -339,7 +339,9 @@ BestInPlaceEditor.forms = {
339
339
 
340
340
  jQuery.fn.best_in_place = function() {
341
341
  this.each(function(){
342
- jQuery(this).data('bestInPlaceEditor', new BestInPlaceEditor(this));
342
+ if (!jQuery(this).data('bestInPlaceEditor')) {
343
+ jQuery(this).data('bestInPlaceEditor', new BestInPlaceEditor(this));
344
+ }
343
345
  });
344
346
  return this;
345
347
  };
@@ -1,3 +1,4 @@
1
+ require "best_in_place/utils"
1
2
  require "best_in_place/helper"
2
3
  require "best_in_place/engine"
3
4
 
@@ -1,5 +1,6 @@
1
1
  module BestInPlace
2
2
  module BestInPlaceHelpers
3
+
3
4
  def best_in_place(object, field, opts = {})
4
5
  opts[:type] ||= :input
5
6
  opts[:collection] ||= []
@@ -20,7 +21,7 @@ module BestInPlace
20
21
  collection = opts[:collection].to_json
21
22
  end
22
23
  out = "<span class='best_in_place'"
23
- out << " id='best_in_place_#{object.class.to_s.gsub("::", "_").underscore}_#{field}'"
24
+ out << " id='#{BestInPlace::Utils.build_best_in_place_id(object, field)}'"
24
25
  out << " data-url='#{opts[:path].blank? ? url_for(object).to_s : url_for(opts[:path])}'"
25
26
  out << " data-object='#{object.class.to_s.gsub("::", "_").underscore}'"
26
27
  out << " data-collection='#{collection}'" unless collection.blank?
@@ -1,24 +1,28 @@
1
1
  module BestInPlace
2
2
  module TestHelpers
3
+
3
4
  def bip_text(model, attr, new_value)
5
+ id = BestInPlace::Utils.build_best_in_place_id model, attr
4
6
  page.execute_script <<-JS
5
- $("#best_in_place_#{model}_#{attr}").click();
6
- $("#best_in_place_#{model}_#{attr} input[name='#{attr}']").val('#{new_value}');
7
- $("#best_in_place_#{model}_#{attr} form").submit();
7
+ $("##{id}").click();
8
+ $("##{id} input[name='#{attr}']").val('#{new_value}');
9
+ $("##{id} form").submit();
8
10
  JS
9
11
  end
10
12
 
11
13
  def bip_bool(model, attr)
12
- page.execute_script("$('#best_in_place_#{model}_#{attr}').click();")
14
+ id = BestInPlace::Utils.build_best_in_place_id model, attr
15
+ page.execute_script("$('##{id}').click();")
13
16
  end
14
17
 
15
18
  def bip_select(model, attr, name)
19
+ id = BestInPlace::Utils.build_best_in_place_id model, attr
16
20
  page.execute_script <<-JS
17
21
  (function() {
18
- $("#best_in_place_#{model}_#{attr}").click();
19
- var opt_value = $("#best_in_place_#{model}_#{attr} select option:contains('#{name}')").attr('value');
20
- $("#best_in_place_#{model}_#{attr} select option[value='" + opt_value + "']").attr('selected', true);
21
- $("#best_in_place_#{model}_#{attr} select").change();
22
+ $("##{id}").click();
23
+ var opt_value = $("##{id} select option:contains('#{name}')").attr('value');
24
+ $("##{id} select option[value='" + opt_value + "']").attr('selected', true);
25
+ $("##{id} select").change();
22
26
  })();
23
27
  JS
24
28
  end
@@ -0,0 +1,15 @@
1
+ module BestInPlace
2
+ class Utils
3
+
4
+ def self.build_best_in_place_id(object, field)
5
+ if object.is_a?(Symbol) || object.is_a?(String)
6
+ return "best_in_place_#{object}_#{field}"
7
+ end
8
+
9
+ id = "best_in_place_#{object.class.to_s.demodulize.underscore}"
10
+ id << "_#{object.id}" if object.class.ancestors.include?(ActiveRecord::Base)
11
+ id << "_#{field}"
12
+ id
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module BestInPlace
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -26,8 +26,18 @@ describe BestInPlace::BestInPlaceHelpers do
26
26
  @span = nk.css("span")
27
27
  end
28
28
 
29
- it "should have a proper id" do
30
- @span.attribute("id").value.should == "best_in_place_user_name"
29
+ context "when it's an ActiveRecord model" do
30
+ it "should have a proper id" do
31
+ @span.attribute("id").value.should == "best_in_place_user_#{@user.id}_name"
32
+ end
33
+ end
34
+
35
+ context "when it's not an AR model" do
36
+ it "shold generate an html id without any id" do
37
+ nk = Nokogiri::HTML.parse(helper.best_in_place [1,2,3], :first, :path => @user)
38
+ span = nk.css("span")
39
+ span.attribute("id").value.should == "best_in_place_array_first"
40
+ end
31
41
  end
32
42
 
33
43
  it "should have the best_in_place class" do
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "spec_helper"
3
3
 
4
- describe "Double initialization bug", :js => true, :pending => true do
4
+ describe "Double initialization bug", :js => true do
5
5
  before do
6
6
  @user = User.new :name => "Lucia",
7
7
  :last_name => "Napoli",
@@ -21,7 +21,7 @@ describe "Double initialization bug", :js => true, :pending => true do
21
21
  page.should have_content("No thanks")
22
22
  end
23
23
 
24
- bip_bool :user, :receive_email
24
+ bip_bool @user, :receive_email
25
25
 
26
26
  visit double_init_user_path(@user)
27
27
  within("#receive_email") do
@@ -35,14 +35,14 @@ describe "JS behaviour", :js => true do
35
35
  end
36
36
  end
37
37
 
38
- it "should be able to use the bip_text to update a text field" do
38
+ it "should be able to use bip_text to update a text field" do
39
39
  @user.save!
40
40
  visit user_path(@user)
41
41
  within("#email") do
42
42
  page.should have_content("lucianapoli@gmail.com")
43
43
  end
44
44
 
45
- bip_text :user, :email, "new@email.com"
45
+ bip_text @user, :email, "new@email.com"
46
46
 
47
47
  visit user_path(@user)
48
48
  within("#email") do
@@ -54,13 +54,13 @@ describe "JS behaviour", :js => true do
54
54
  @user.save!
55
55
  visit user_path(@user)
56
56
 
57
- bip_text :user, :email, "new@email.com"
57
+ bip_text @user, :email, "new@email.com"
58
58
 
59
59
  within("#email") do
60
60
  page.should have_content("new@email.com")
61
61
  end
62
62
 
63
- bip_text :user, :email, "new_two@email.com"
63
+ bip_text @user, :email, "new_two@email.com"
64
64
 
65
65
  within("#email") do
66
66
  page.should have_content("new_two@email.com")
@@ -76,10 +76,10 @@ describe "JS behaviour", :js => true do
76
76
  @user.save!
77
77
  visit user_path(@user)
78
78
 
79
- bip_text :user, :email, "wrong format"
79
+ bip_text @user, :email, "wrong format"
80
80
  page.should have_content("Email has wrong email format")
81
81
 
82
- bip_text :user, :email, "another@email.com"
82
+ bip_text @user, :email, "another@email.com"
83
83
  within("#email") do
84
84
  page.should have_content("another@email.com")
85
85
  end
@@ -97,7 +97,7 @@ describe "JS behaviour", :js => true do
97
97
  page.should have_content("Italy")
98
98
  end
99
99
 
100
- bip_select :user, :country, "France"
100
+ bip_select @user, :country, "France"
101
101
 
102
102
  visit user_path(@user)
103
103
  within("#country") do
@@ -113,7 +113,7 @@ describe "JS behaviour", :js => true do
113
113
  page.should have_content("No thanks")
114
114
  end
115
115
 
116
- bip_bool :user, :receive_email
116
+ bip_bool @user, :receive_email
117
117
 
118
118
  visit user_path(@user)
119
119
  within("#receive_email") do
@@ -125,7 +125,7 @@ describe "JS behaviour", :js => true do
125
125
  @user.save!
126
126
  visit user_path(@user)
127
127
 
128
- bip_text :user, :address, ""
128
+ bip_text @user, :address, ""
129
129
  page.should have_content("Address can't be blank")
130
130
  within("#address") do
131
131
  page.should have_content("Via Roma 99")
@@ -136,7 +136,7 @@ describe "JS behaviour", :js => true do
136
136
  @user.save!
137
137
  visit user_path(@user)
138
138
 
139
- bip_text :user, :last_name, "a"
139
+ bip_text @user, :last_name, "a"
140
140
  page.should have_content("last_name has invalid length")
141
141
  end
142
142
 
@@ -144,13 +144,13 @@ describe "JS behaviour", :js => true do
144
144
  @user.save!
145
145
  visit user_path(@user)
146
146
 
147
- bip_text :user, :last_name, "a"
147
+ bip_text @user, :last_name, "a"
148
148
 
149
149
  within("#last_name") do
150
150
  page.should have_content("Napoli")
151
151
  end
152
152
 
153
- bip_text :user, :last_name, "Another"
153
+ bip_text @user, :last_name, "Another"
154
154
 
155
155
  within("#last_name") do
156
156
  page.should have_content("Another")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: best_in_place
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-26 00:00:00.000000000 Z
12
+ date: 2011-11-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &81861640 !ruby/object:Gem::Requirement
16
+ requirement: &12194680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *81861640
24
+ version_requirements: *12194680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jquery-rails
27
- requirement: &81861380 !ruby/object:Gem::Requirement
27
+ requirement: &12192700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *81861380
35
+ version_requirements: *12192700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec-rails
38
- requirement: &81860990 !ruby/object:Gem::Requirement
38
+ requirement: &12191840 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.7.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *81860990
46
+ version_requirements: *12191840
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: nokogiri
49
- requirement: &81860690 !ruby/object:Gem::Requirement
49
+ requirement: &12206480 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.5.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *81860690
57
+ version_requirements: *12206480
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: capybara
60
- requirement: &81860440 !ruby/object:Gem::Requirement
60
+ requirement: &12205480 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 1.0.1
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *81860440
68
+ version_requirements: *12205480
69
69
  description: BestInPlace is a jQuery script and a Rails 3 helper that provide the
70
70
  method best_in_place to display any object field easily editable for the user by
71
71
  just clicking on it. It supports input data, text data, boolean data and custom
@@ -89,6 +89,7 @@ files:
89
89
  - lib/best_in_place/engine.rb
90
90
  - lib/best_in_place/helper.rb
91
91
  - lib/best_in_place/test_helpers.rb
92
+ - lib/best_in_place/utils.rb
92
93
  - lib/best_in_place/version.rb
93
94
  - spec/helpers/best_in_place_spec.rb
94
95
  - spec/integration/double_init_spec.rb
@@ -165,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
166
  version: '0'
166
167
  segments:
167
168
  - 0
168
- hash: 151823247
169
+ hash: 1147511774352652739
169
170
  required_rubygems_version: !ruby/object:Gem::Requirement
170
171
  none: false
171
172
  requirements:
@@ -174,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
175
  version: '0'
175
176
  segments:
176
177
  - 0
177
- hash: 151823247
178
+ hash: 1147511774352652739
178
179
  requirements: []
179
180
  rubyforge_project: best_in_place
180
181
  rubygems_version: 1.8.10