locomotivecms_steam 1.1.0.rc2 → 1.1.0.rc3

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: c17c4a04bf43a0773bfe7862cc8a0b8b6f4cc1df
4
- data.tar.gz: 5f42f142c5e32e216aaaddb71e664297b1946d25
3
+ metadata.gz: 42c767e4b89256e979cc9e73a2851227052b8478
4
+ data.tar.gz: 45d39c6d1b6ee403c4797f2793eeecbe03e56d2f
5
5
  SHA512:
6
- metadata.gz: 839e0df868a0fe863513d9b9d772810825a632b1a8abdaca54c3a803b8c08261e1c85b2b696a6ccc0b856b4682581c62e94d2922fc7449fa96b1777d81f94652
7
- data.tar.gz: 8ebed488b272103bc81bddd06e387663ddb44fb93a62b35b62cc1caecb7851c4a2ffa25d60532caaf9f11228207d8d5e679b2c37ff5e09045a3bd060af7648a8
6
+ metadata.gz: cf631f30710f478aa18d766fb9b302fbea3a671ca4cc8b0c02ade4d6e3df11ffe162d779d06a0fac40df2348be9313fca2ef0d258dece9ad4e2666673415f782
7
+ data.tar.gz: aa70b068ba7218dbd9f29fe765860fb03b3eb3c72ef96956c48c9cb6596d0aaa896b700c1b111950cdb6dfa5ab1d4f1432b734e48aee3215693c00ede75231e9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- locomotivecms_steam (1.1.0.rc2)
4
+ locomotivecms_steam (1.1.0.rc3)
5
5
  RedCloth (~> 4.2.9)
6
6
  autoprefixer-rails (~> 6.3.3.1)
7
7
  chronic (~> 0.10.2)
@@ -40,7 +40,7 @@ module Locomotive
40
40
 
41
41
  def before_method(meth)
42
42
  if (meth.to_s =~ /^group_by_(.+)$/) == 0
43
- repository.group_by_select_option(@content_type, $1)
43
+ repository.group_by_select_option($1)
44
44
  elsif (meth.to_s =~ /^(.+)_options$/) == 0
45
45
  select_options($1)
46
46
  else
@@ -65,19 +65,34 @@ module Locomotive
65
65
  end
66
66
 
67
67
  def prepare_form_attributes(options)
68
- action = options[:action]
68
+ url = action_url(options)
69
69
  attributes = options.slice(:id, :class, :name, :novalidate)
70
70
 
71
- if action.blank? && options[:json]
72
- action = current_context['path']
73
- action = (action.blank? ? 'index' : action) + '.json'
71
+ { method: 'POST', enctype: 'multipart/form-data' }.merge(attributes).tap do |_attributes|
72
+ _attributes[:action] = url if url
74
73
  end
74
+ end
75
75
 
76
- { method: 'POST', enctype: 'multipart/form-data' }.merge(attributes).tap do |_attributes|
77
- _attributes[:action] = action if action
76
+ def action_url(options)
77
+ url = options[:action]
78
+
79
+ if url.blank?
80
+ if options[:json]
81
+ url = current_context['path'].blank? ? '/' : current_context['path']
82
+ url + 'index.json'
83
+ else
84
+ nil
85
+ end
86
+ else
87
+ url = '/' + url unless url.starts_with?('/')
88
+ url_builder.prefix(url)
78
89
  end
79
90
  end
80
91
 
92
+ def url_builder
93
+ current_context.registers[:services].url_builder
94
+ end
95
+
81
96
  end
82
97
 
83
98
  end
@@ -102,7 +102,7 @@ module Locomotive
102
102
  groups_to_array(name, _groups).tap do |groups|
103
103
  # entries with a not existing select_option value?
104
104
  unless _groups.blank?
105
- groups << { name: nil, entries: _groups.values.flatten }
105
+ groups << { name: nil, entries: _groups.values.flatten }.with_indifferent_access
106
106
  end
107
107
  end
108
108
  end
@@ -179,7 +179,7 @@ module Locomotive
179
179
  def groups_to_array(name, groups)
180
180
  content_type_repository.select_options(content_type, name).map do |option|
181
181
  option_name = i18n_value_of(option, :name)
182
- { name: option_name, entries: groups.delete(option_name) || [] }
182
+ { 'name' => option_name, 'entries' => groups.delete(option_name) || [] }.with_indifferent_access
183
183
  end
184
184
  end
185
185
 
@@ -30,12 +30,12 @@ module Locomotive
30
30
  "/entry_submissions/#{content_type.slug}"
31
31
  end
32
32
 
33
- private
34
-
35
33
  def prefix(url)
36
34
  mounted_on ? "#{mounted_on}#{url}" : url
37
35
  end
38
36
 
37
+ private
38
+
39
39
  def mounted_on
40
40
  return if request.nil?
41
41
  request.env['steam.mounted_on']
@@ -3,6 +3,6 @@
3
3
  # 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0
4
4
  module Locomotive
5
5
  module Steam
6
- VERSION = '1.1.0.rc2'
6
+ VERSION = '1.1.0.rc3'
7
7
  end
8
8
  end
@@ -96,7 +96,9 @@ describe 'ContactForm' do
96
96
 
97
97
  context 'when valid' do
98
98
 
99
- let(:response) { post_contact_form(url, params, false, true) }
99
+ let(:env) { {} }
100
+ let(:follow_redirect) { true }
101
+ let(:response) { post_contact_form(url, params, false, follow_redirect, env) }
100
102
 
101
103
  it 'returns a success status' do
102
104
  expect(response.status).to eq 200
@@ -106,6 +108,17 @@ describe 'ContactForm' do
106
108
  expect(response.body.to_s).to include 'Thank you John'
107
109
  end
108
110
 
111
+ context 'mounted on a different path than /' do
112
+
113
+ let(:env) { { 'steam.mounted_on' => '/foo/bar/' } }
114
+ let(:follow_redirect) { false }
115
+
116
+ it 'redirects to the location prefixed by the mounted_on path' do
117
+ expect(response.location).to match(/\A\/foo\/bar\/\/events\?submitted_type_slug=messages\&submitted_entry_slug=john/)
118
+ end
119
+
120
+ end
121
+
109
122
  end
110
123
 
111
124
  end
@@ -162,13 +175,13 @@ describe 'ContactForm' do
162
175
 
163
176
  end
164
177
 
165
- def post_contact_form(url, params, json = false, follow_redirect = false)
178
+ def post_contact_form(url, params, json = false, follow_redirect = false, env = {})
166
179
  if json
167
180
  url += '.json'
168
181
  params = params.symbolize_keys
169
182
  end
170
183
 
171
- post url, params
184
+ post url, params, env
172
185
 
173
186
  follow_redirect! if follow_redirect
174
187
 
@@ -88,7 +88,7 @@ describe Locomotive::Steam::Liquid::Drops::ContentEntryCollection do
88
88
  describe 'group entries by a select/belongs_to field' do
89
89
 
90
90
  before do
91
- expect(services.repositories.content_entry).to receive(:group_by_select_option).with(content_type, 'category').and_return([['a', [1, 2]]])
91
+ expect(services.repositories.content_entry).to receive(:group_by_select_option).with('category').and_return([['a', [1, 2]]])
92
92
  end
93
93
 
94
94
  it { expect(drop.before_method(:group_by_category)).to eq [['a', [1, 2]]] }
@@ -8,10 +8,12 @@ describe Locomotive::Steam::Liquid::Tags::ModelForm do
8
8
  allow(Rack::Csrf).to receive(:token).and_return(42)
9
9
  end
10
10
 
11
- let(:request) { instance_double('Request', env: {}) }
11
+ let(:path) { '' }
12
+ let(:env) { {} }
13
+ let(:request) { instance_double('Request', env: env) }
12
14
  let(:source) { "{% model_form 'newsletter_addresses' %}Newsletter Form{% endmodel_form %}" }
13
15
  let(:services) { Locomotive::Steam::Services.build_instance(request) }
14
- let(:context) { ::Liquid::Context.new({ path: '' }, {}, { services: services }) }
16
+ let(:context) { ::Liquid::Context.new({ 'path' => path }, {}, { services: services }) }
15
17
 
16
18
  subject { render_template(source, context) }
17
19
 
@@ -35,7 +37,29 @@ describe Locomotive::Steam::Liquid::Tags::ModelForm do
35
37
  describe 'json enabled' do
36
38
 
37
39
  let(:source) { "{% model_form 'newsletter_addresses', json: true %}Newsletter Form{% endmodel_form %}" }
38
- it { is_expected.to eq %(<form method="POST" enctype="multipart/form-data" action="index.json"><input type="hidden" name="content_type_slug" value="newsletter_addresses" /><input type="hidden" name="token" value="42" />Newsletter Form</form>) }
40
+ it { is_expected.to eq %(<form method="POST" enctype="multipart/form-data" action="/index.json"><input type="hidden" name="content_type_slug" value="newsletter_addresses" /><input type="hidden" name="token" value="42" />Newsletter Form</form>) }
41
+
42
+ context 'rendered at /_app/foo/preview' do
43
+
44
+ let(:path) { '/_app/foo/preview/' }
45
+ let(:env) { { 'steam.mounted_on' => '/_app/foo/preview/' } }
46
+ it { is_expected.to eq %(<form method="POST" enctype="multipart/form-data" action="/_app/foo/preview/index.json"><input type="hidden" name="content_type_slug" value="newsletter_addresses" /><input type="hidden" name="token" value="42" />Newsletter Form</form>) }
47
+
48
+ end
49
+
50
+ end
51
+
52
+ describe 'specifying an action' do
53
+
54
+ let(:source) { "{% model_form 'newsletter_addresses', action: 'foo/bar' %}Newsletter Form{% endmodel_form %}" }
55
+ it { is_expected.to eq %(<form method="POST" enctype="multipart/form-data" action="/foo/bar"><input type="hidden" name="content_type_slug" value="newsletter_addresses" /><input type="hidden" name="token" value="42" />Newsletter Form</form>) }
56
+
57
+ context 'mounted_on is not empty' do
58
+
59
+ let(:env) { { 'steam.mounted_on' => '/_app/foo/preview' } }
60
+ it { is_expected.to eq %(<form method="POST" enctype="multipart/form-data" action="/_app/foo/preview/foo/bar"><input type="hidden" name="content_type_slug" value="newsletter_addresses" /><input type="hidden" name="token" value="42" />Newsletter Form</form>) }
61
+
62
+ end
39
63
 
40
64
  end
41
65
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locomotivecms_steam
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.rc2
4
+ version: 1.1.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Didier Lafforgue
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-03-17 00:00:00.000000000 Z
14
+ date: 2016-03-24 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler