mokio 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -0
  3. data/app/assets/stylesheets/backend/custom.css.scss +1 -1
  4. data/app/views/mokio/common/_meta.html.slim +20 -20
  5. data/app/views/mokio/menus/_form.html.haml +1 -1
  6. data/app/views/mokio/menus/_menu.html.slim +7 -1
  7. data/app/views/mokio/menus/index.html.slim +1 -0
  8. data/app/views/mokio/menus/new_menu_position.slim +21 -0
  9. data/config/locales/en.yml +4 -1
  10. data/config/locales/pl.yml +4 -1
  11. data/config/routes.rb +6 -3
  12. data/db/migrate/20140422135850_add_mokio_to_application.rb +15 -15
  13. data/lib/mokio/concerns/controllers/menus.rb +25 -2
  14. data/lib/mokio/concerns/models/contact.rb +1 -1
  15. data/lib/mokio/concerns/models/menu.rb +2 -1
  16. data/lib/mokio/concerns/models/recipient.rb +0 -9
  17. data/lib/mokio/engine.rb +8 -0
  18. data/lib/mokio/frontend_helpers/langs_helper.rb +16 -9
  19. data/lib/mokio/frontend_helpers/menu_helper.rb +21 -16
  20. data/lib/mokio/slugged.rb +5 -0
  21. data/lib/mokio/version.rb +1 -1
  22. data/spec/controllers/{backend → mokio}/contents_controller_spec.rb +34 -25
  23. data/spec/controllers/mokio/dashboard_controller_spec.rb +76 -0
  24. data/spec/controllers/{backend → mokio}/menus_controller_spec.rb +104 -99
  25. data/spec/controllers/mokio/mov_galleries_controller_spec.rb +125 -0
  26. data/spec/controllers/mokio/photos_controller_spec.rb +350 -0
  27. data/spec/controllers/mokio/pic_galleries_controller_spec.rb +125 -0
  28. data/spec/controllers/mokio/static_modules_controller_spec.rb +166 -0
  29. data/spec/factories/contact_templates.rb +1 -1
  30. data/spec/factories/content_links_factory.rb +1 -1
  31. data/spec/factories/contents_factory.rb +8 -8
  32. data/spec/factories/gmaps.rb +1 -1
  33. data/spec/factories/langs.rb +1 -1
  34. data/spec/factories/menus_factory.rb +1 -1
  35. data/spec/factories/meta.rb +1 -1
  36. data/spec/factories/recipients.rb +1 -1
  37. data/spec/factories/selected_modules.rb +1 -1
  38. data/spec/factories/static_modules_factory.rb +2 -2
  39. data/spec/factories/users.rb +1 -1
  40. data/spec/helpers/mokio/common_helper_spec.rb +141 -0
  41. data/spec/helpers/mokio/menus_helper_spec.rb +70 -0
  42. data/spec/models/available_module_spec.rb +13 -10
  43. data/spec/models/contact_template_spec.rb +5 -3
  44. data/spec/models/content_link_spec.rb +5 -4
  45. data/spec/models/content_spec.rb +71 -70
  46. data/spec/models/data_file_spec.rb +5 -4
  47. data/spec/models/gmap_spec.rb +5 -4
  48. data/spec/models/lang_spec.rb +5 -4
  49. data/spec/models/menu_spec.rb +10 -2
  50. data/spec/models/meta_spec.rb +5 -4
  51. data/spec/models/module_position_spec.rb +11 -10
  52. data/spec/models/mov_gallery_spec.rb +62 -59
  53. data/spec/models/pic_gallery_spec.rb +62 -59
  54. data/spec/models/recipient_spec.rb +5 -4
  55. data/spec/models/selected_module_spec.rb +72 -88
  56. data/spec/models/static_module_spec.rb +56 -55
  57. data/spec/models/user_spec.rb +7 -3
  58. data/spec/spec_helper.rb +4 -1
  59. metadata +21 -22
  60. data/spec/controllers/backend/dashboard_controller_spec.rb +0 -69
  61. data/spec/controllers/backend/mov_galleries_controller_spec.rb +0 -118
  62. data/spec/controllers/backend/photos_controller_spec.rb +0 -342
  63. data/spec/controllers/backend/pic_galleries_controller_spec.rb +0 -118
  64. data/spec/controllers/backend/static_modules_controller_spec.rb +0 -159
  65. data/spec/factories/tags.rb +0 -17
  66. data/spec/helpers/backend/common_helper_spec.rb +0 -137
  67. data/spec/helpers/backend/menus_helper_spec.rb +0 -64
@@ -10,22 +10,29 @@ module Mokio
10
10
  #
11
11
  # ==== Attributes
12
12
  #
13
- # * +controller_action+ - your controller action path (e.g. "content_home_path")
14
13
  # * +image_folder+ - folder where helper will search country flag images (default: "langs" - searched in app/assets/images/langs)
15
- # * +submit_class+ - submit buttons css class (defaut: "btn-lang-submit")
14
+ # * +nav_class+ - nav css class (defaut: "lang_nav")
16
15
  # * +image_ext+ - language flag image extension(defaut: "png")
17
16
  #
18
- def build_lang_menu(controller_action, image_folder = "langs", submit_class = "btn-lang-submit", image_ext = "png")
19
- html = ""
17
+ def build_lang_menu(image_folder = "langs", nav_class = "lang_nav", image_ext = "png")
18
+ lang_links = ''
19
+
20
20
  Mokio::Lang.active.each do |lang|
21
- lang_form = form_tag(controller_action, :id => "#{lang.shortname}_lang_form") do
22
- hidden_field_tag("lang_code", lang.shortname) +
23
- image_submit_tag("#{image_folder}/#{lang.shortname}.#{image_ext}", :class => submit_class)
24
- end
25
- html << lang_form
21
+ lang_link =<<HTML
22
+ <li>#{link_to_unless(I18n.locale.to_s == lang.shortname, image_tag("#{image_folder}/#{lang.shortname}.#{image_ext}"), root_url( locale: lang.shortname.to_sym ), class: 'lang-link')}</li>
23
+ HTML
24
+ lang_links << lang_link
26
25
  end
26
+ html =<<HTML
27
+ <nav id="#{nav_class}">
28
+ <ul id='lang_list'>
29
+ #{lang_links}
30
+ </ul>
31
+ </nav>
32
+ HTML
27
33
  html.html_safe
28
34
  end
35
+
29
36
  end
30
37
  end
31
38
  end
@@ -103,10 +103,10 @@ module Mokio
103
103
  # Finds proper menu element - based on lang and menu position and calls build_menu_extended for this menu element
104
104
  #
105
105
 
106
- def build_menu_extended_lang(menu_position_name, lang_code, limit = 999999, include_menu_parent = false, options = {hierarchical: true, with_nav: true, nav_class: "nav_menu", active_class: "active", item_class: nil, item_with_children_class: nil, item_without_children_class: nil, ul_class: nil, ul_wrapper_class: nil, ul_nested_class:nil, ul_nested_wrapper_class:nil, a_class: nil})
106
+ def build_menu_extended_lang(menu_position_name, lang_code, options = {})
107
107
  lang = Mokio::Lang.find_by_shortname(lang_code)
108
108
  menu_parent = Mokio::Menu.where(lang_id: lang.id, name: menu_position_name) unless lang.blank?
109
- build_menu_extended(menu_parent.first.id, limit, include_menu_parent, options) unless menu_parent.blank?
109
+ build_menu_extended(menu_parent.first.id, options) unless menu_parent.blank?
110
110
  end
111
111
 
112
112
 
@@ -141,9 +141,9 @@ module Mokio
141
141
  # ==== Attributes
142
142
  #
143
143
  # * +menu_parent_id+ - starting menu element's id - this element will be displayed or not and all its children will be displayed
144
- # * +include_menu_parent+ - whether parent menu element should be displayed or not
145
- # * +limit+ - how deep should builder look for children, count starts from 1
146
144
  # * +options+ - hash with following options:
145
+ # * +include_menu_parent+ - whether parent menu element should be displayed or not
146
+ # * +limit+ - how deep should builder look for children, count starts from 1
147
147
  # * +hierarchical+ - specifies if you want to use hierarchical links or not
148
148
  # * +with_nav+ - whether nav element should be generated
149
149
  # * +nav_class+ - css class of the nav element
@@ -158,30 +158,30 @@ module Mokio
158
158
  # * +a_class+ - css class of the a element
159
159
  #* +content_type+ - content types for which we'll build menu items(string or array e.g. "Mokio::Article" OR ["Mokio::Article", "Mokio::PicGallery"])
160
160
  #* +content_item_class+ - css class of the content items (not Mokio::Menu, specified above)
161
+ #* +with_locale+ - whether add locale prefix to href
161
162
 
162
163
  # if you need hierarchical links in your frontend, add following route to your routes.rb
163
164
 
164
165
  # get "/*menu_path/:menu_id" => "content#show"
165
166
  # get "/:menu_id" => "content#show"
166
167
 
167
- def build_menu_extended(menu_parent_id, limit = 999999, include_menu_parent = false, options = {})
168
+ def build_menu_extended(menu_parent_id, options = {})
168
169
 
169
170
  set_options_defaults(options)
170
171
 
171
172
  html = ""
172
- html = "<nav #{"class='#{options[:nav_class]}'" if options[:nav_class]} id='menuMain'>" if options[:with_nav]
173
+ html << "<nav #{"class='#{options[:nav_class]}'" if options[:nav_class]} id='menuMain'>" if options[:with_nav]
173
174
  html << "<div class='#{options[:ul_wrapper_class]}'>" unless options[:ul_wrapper_class].nil?
174
175
  html << "<ul #{"class='#{options[:ul_class]}'" if options[:ul_class]}>"
175
176
  begin
176
177
  menu_parent = Mokio::Menu.find(menu_parent_id)
177
- if include_menu_parent
178
- html << build_menu_items_extended(menu_parent, limit, 1, menu_parent.ancestor_ids, options)
178
+ if options[:include_menu_parent]
179
+ html << build_menu_items_extended(menu_parent, 1, menu_parent.ancestor_ids, options)
179
180
  else
180
181
  menu_parent.children.order_default.each do |i|
181
- html << build_menu_items_extended(i, limit, 1, i.ancestor_ids, options)
182
+ html << build_menu_items_extended(i, 1, i.ancestor_ids, options)
182
183
  end
183
184
  end
184
-
185
185
  rescue => e
186
186
  MOKIO_LOG.error "BUILD MENU ERROR: #{e}"
187
187
  end
@@ -194,32 +194,34 @@ module Mokio
194
194
  # Builds menu starting from given menu element (real menu only)
195
195
  # - displays all its children
196
196
 
197
- def build_menu_items_extended (i, limit, index, active_ids = [], options)
197
+ def build_menu_items_extended (i, index, active_ids = [], options)
198
198
 
199
- return "" if index > limit
199
+ return "" if index > options[:limit]
200
200
 
201
201
  html = ""
202
202
  if i.visible && i.active
203
203
  item_class = build_item_class(i, options, active_ids)
204
204
  html << "<li #{"class='#{item_class}'" unless item_class.blank?}>"
205
205
 
206
+ locale_prefix = "/#{I18n.locale.to_s}" if options[:with_locale]
207
+ locale_prefix ||= ''
206
208
  if i.external_link.blank?
207
- html << "<a #{"class='#{options[:a_class]}'" if options[:a_class]} href='#{i.real_slug(options[:hierarchical])}'>#{i.name}</a>"
209
+ html << "<a #{"class='#{options[:a_class]}'" if options[:a_class]} href='#{locale_prefix}#{i.real_slug(options[:hierarchical])}'>#{i.name}</a>"
208
210
  else
209
- html << "<a #{"class='#{options[:a_class]}'" if options[:a_class]} href='#{i.external_link}' #{"rel='nofollow'" unless i.follow || i.follow.nil?} #{"target='#{i.target}'" unless (i.target.blank? || i.target == '_self') }>#{i.name}</a>"
211
+ html << "<a #{"class='#{options[:a_class]}'" if options[:a_class]} href='#{locale_prefix}#{i.external_link}' #{"rel='nofollow'" unless i.follow || i.follow.nil?} #{"target='#{i.target}'" unless (i.target.blank? || i.target == '_self') }>#{i.name}</a>"
210
212
  end
211
213
 
212
214
  items_html = ""
213
215
 
214
216
  i.children.order_default.each do |item_child|
215
- items_html << build_menu_items_extended(item_child, limit, index + 1, active_ids, options)
217
+ items_html << build_menu_items_extended(item_child, index + 1, active_ids, options)
216
218
  end
217
219
 
218
220
  content_item_class = [item_class, options[:content_item_class]].compact.join(" ")
219
221
  i.contents.displayed.order_default.each do |content|
220
222
  next if options[:content_type].blank? || options[:content_type].exclude?(content.type.to_s)
221
223
  items_html << "<li #{"class='#{content_item_class}'" unless content_item_class.blank?}>"
222
- items_html << "<a #{"class='#{options[:a_class]}'" if options[:a_class]} href='#{content.slug}'>#{content.title}</a>" if content.respond_to?("slug")
224
+ items_html << "<a #{"class='#{options[:a_class]}'" if options[:a_class]} href='#{locale_prefix}#{content.slug}'>#{content.title}</a>" if content.respond_to?("slug")
223
225
  items_html << "</li>"
224
226
  end
225
227
 
@@ -259,11 +261,14 @@ module Mokio
259
261
  # Sets default values for build_menu_extended
260
262
 
261
263
  def set_options_defaults(options)
264
+ options[:limit] = 999999 unless options.has_key? :limit
265
+ options[:include_menu_parent] = false unless options.has_key? :include_menu_parent
262
266
  options[:hierarchical] = true unless options.has_key? :hierarchical
263
267
  options[:with_nav] = true unless options.has_key? :with_nav
264
268
  options[:nav_class] = "nav_menu" unless options.has_key? :nav_class
265
269
  options[:active_class] = "active" unless options.has_key? :active_class
266
270
  options[:content_type] = "" unless options.has_key? :content_type
271
+ options[:with_locale] = false unless options.has_key? :with_locale
267
272
  end
268
273
 
269
274
 
@@ -1,5 +1,10 @@
1
1
  module Mokio
2
2
  module Slugged
3
+
4
+ def localized_slug
5
+ "/#{I18n.locale.to_s}#{slug}"
6
+ end
7
+
3
8
  def slug
4
9
  "/#{slug_prefix}/#{id}/#{slug_candidate.parameterize}"
5
10
  end
@@ -2,5 +2,5 @@ module Mokio
2
2
  #
3
3
  # Actual Mokio version
4
4
  #
5
- VERSION = "0.0.11"
5
+ VERSION = "0.0.12"
6
6
  end
@@ -18,30 +18,39 @@ require 'spec_helper'
18
18
  # Message expectations are only used when there is no simpler way to specify
19
19
  # that an instance is receiving a specific message.
20
20
 
21
- describe Mokio::Backend::ContentsController do
22
-
23
- # This should return the minimal set of attributes required to create a valid
24
- # Content. As you add validations to Content, be sure to
25
- # adjust the attributes here as well.
26
- let(:valid_attributes) { {:title => 'Tralalala' } }
27
-
28
- # This should return the minimal set of values that should be in the session
29
- # in order to pass any filters (e.g. authentication) defined in
30
- # ContentsController. Be sure to keep this updated too.
31
- let(:valid_session) { {} }
32
-
33
- # describe "GET index" do
34
- # it "assigns all contents as @contents" do
35
- # content = Content.create! valid_attributes
36
- # get :index, {}, valid_session
37
- # assigns(:content).should eq([content])
38
- # end
39
- # end
40
-
41
- describe "GET new" do
42
- # it "redirects to Article controller" do
43
- # expect{get :new, valid_session}.to redirect_to (new_backend_article_path)
44
- # end
45
- pending
21
+ module Mokio
22
+
23
+ describe Mokio::ContentsController do
24
+
25
+ before :each do
26
+ @routes = Mokio::Engine.routes
27
+ Content.delete_all
28
+ end
29
+
30
+ # This should return the minimal set of attributes required to create a valid
31
+ # Content. As you add validations to Content, be sure to
32
+ # adjust the attributes here as well.
33
+ let(:valid_attributes) { {:title => 'Tralalala' } }
34
+
35
+ # This should return the minimal set of values that should be in the session
36
+ # in order to pass any filters (e.g. authentication) defined in
37
+ # ContentsController. Be sure to keep this updated too.
38
+ let(:valid_session) { {} }
39
+
40
+ describe "GET index" do
41
+ it "assigns all contents as @contents" do
42
+ content = Content.create! valid_attributes
43
+ get :index, {}, valid_session
44
+ assigns(:contents).should eq([content])
45
+ end
46
+ end
47
+
48
+ describe "GET new" do
49
+ it "redirects to Article controller" do
50
+ get :new, valid_session
51
+ expect(response).to redirect_to (new_article_path)
52
+ end
53
+
54
+ end
46
55
  end
47
56
  end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ module Mokio
4
+
5
+ describe Mokio::DashboardController do
6
+ # include Devise::TestHelpers
7
+ let(:valid_session) { {} }
8
+
9
+ before :each do
10
+ @routes = Mokio::Engine.routes
11
+ end
12
+
13
+ describe "GET show" do
14
+ before(:all) do
15
+ Content.delete_all
16
+ Menu.delete_all
17
+ @root_pl_menu = FactoryGirl.create(:root_pl)
18
+ @top_menu = FactoryGirl.create(:top_pl)
19
+ @loose_content_elt = FactoryGirl.create(:article_displayed_and_active).becomes(Article)
20
+ @invisible_content = FactoryGirl.create(:article_non_displayed).becomes(Article)
21
+ @empty_menu_elt = FactoryGirl.create(:menu, :parent_id => @top_menu.id)
22
+ @menu_with_invisible = FactoryGirl.create(:menu, :parent_id => @top_menu.id)
23
+ @menu_with_invisible.contents << @invisible_content
24
+ @menu_with_invisible.save
25
+
26
+ @menu_with_visible = FactoryGirl.create(:menu, :parent_id => @top_menu.id)
27
+ @content = FactoryGirl.create(:article_displayed_and_active).becomes(Article)
28
+ @menu_with_visible.contents << @content
29
+ @menu_with_visible.save
30
+ end
31
+
32
+ it "displays loose content" do
33
+ get :show, {}, valid_session
34
+ if (!assigns(:more_loose_content))
35
+ expect(assigns(:loose_content).include?(@loose_content_elt)).to be_true
36
+ end
37
+ end
38
+
39
+ it "displays empty menu" do
40
+ get :show, {}, valid_session
41
+ if (!assigns(:more_empty_menu))
42
+ expect(assigns(:empty_menu).include?(@empty_menu_elt)).to be_true
43
+ end
44
+ end
45
+
46
+ it "displays invisible menu" do
47
+ get :show, {}, valid_session
48
+ if (!assigns(:more_empty_menu))
49
+ expect(@menu_with_invisible.invisible_content).to be_true
50
+ expect(assigns(:empty_menu).include?(@menu_with_invisible)).to be_true
51
+ end
52
+ end
53
+
54
+ it 'does not display assigned content' do
55
+ get :show, {}, valid_session
56
+ expect(assigns(:loose_content).include?(@menu_with_invisible)).to be_false
57
+ end
58
+
59
+ it 'does not display menu with visible content' do
60
+ get :show, {}, valid_session
61
+ expect(assigns(:empty_menu).include?(@menu_with_visible)).to be_false
62
+ end
63
+
64
+ it "displays last created" do
65
+ get :show, {}, valid_session
66
+ expect(assigns(:last_created).include?(@content)).to be_true
67
+ end
68
+
69
+ it "displays last updated" do
70
+ get :show, {}, valid_session
71
+ expect(assigns(:last_updated).include?(@content)).to be_true
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mokio::Backend::MenusController do
3
+ module Mokio
4
+
5
+ describe Mokio::MenusController do
4
6
  # include Devise::TestHelpers
5
7
  render_views
6
8
  # This should return the minimal set of attributes required to create a valid
@@ -14,64 +16,66 @@ describe Mokio::Backend::MenusController do
14
16
  let(:valid_session) { {} }
15
17
 
16
18
  before :each do
17
- request.env["HTTP_REFERER"] = backend_menus_path
19
+ @routes = Mokio::Engine.routes
20
+ request.env["HTTP_REFERER"] = menus_path
18
21
  end
19
22
 
20
23
  before :all do
21
- Menu.delete_all
22
- Lang.delete_all
23
- Lang.create(:name => 'polish', :shortname => 'pl', :id => 1)
24
- Menu.new(:name => 'pl', :id => 1, :lang_id => 1, :editable => false).save(:validate => false)
25
- Menu.new(:name => 'Stopka', :lang_id => 1, :parent_id => 1, :editable => false).save(:validate => false)
24
+ Mokio::Lang.delete_all
25
+ Mokio::Lang.create(:name => 'polish', :shortname => 'pl', :id => 1)
26
+ Mokio::Menu.delete_all
27
+ Mokio::Menu.new(:name => 'pl', :id => 1, :lang_id => 1, :editable => false, :slug => 'pl').save(:validate => false)
28
+ Mokio::Menu.new(:name => 'Stopka', :lang_id => 1, :parent_id => 1, :editable => false, :slug => 'stopka').save(:validate => false)
26
29
  end
27
30
 
28
- # describe "GET index" do
29
- # it "@menus contains arranged tree" do
30
- # get :index, {}, valid_session
31
- # assigns(:menus).keys[0].name.should eq("pl")
32
- # end
33
- # end
31
+ describe "GET index" do
32
+ it "@menus contains arranged tree" do
33
+ get :index, {}, valid_session
34
+ assigns(:menus).keys[0].name.should eq("pl")
35
+ end
36
+ end
34
37
 
35
38
  describe "GET new" do
39
+
36
40
  it "assigns a new backend_menu as @menu" do
37
- get :new, {}, valid_session
38
- assigns(:menu).should be_a_new(Menu)
41
+ get :new, valid_session
42
+ assigns(:menu).should be_a_new(Mokio::Menu)
39
43
  end
40
- it "@parent_tree is set for valid lang_id" do
41
- get :new, {}, valid_session
42
- assigns(:menu).parent_tree[0].name.should eq("pl") #todo - more than one language
44
+ it "@parent_root is set for valid lang_id" do
45
+ get :new, valid_session
46
+ assigns(:menu).parent_root.name.should eq("pl") #todo - more than one language
43
47
  end
44
48
  end
45
49
 
46
50
  describe "GET edit" do
47
51
  it "assigns the requested backend_menu as @menu" do
48
- menu = Menu.create! valid_attributes
52
+ menu = Mokio::Menu.create! valid_attributes
49
53
  get :edit, {:id => menu.to_param}, valid_session
50
54
  assigns(:menu).should eq(menu)
51
55
  end
52
56
 
53
- it "@parent_tree is set for valid lang_id" do
54
- menu = Menu.create! valid_attributes
57
+ it "@parent_root is set for valid lang_id" do
58
+ menu = Mokio::Menu.create! valid_attributes
55
59
  get :edit, {:id => menu.to_param}, valid_session
56
- assigns(:menu).parent_tree[0].name.should eq("pl")
60
+ assigns(:menu).parent_root.name.should eq("pl")
57
61
  end
58
62
 
59
63
  it "@parent_tree is set for deep element" do
60
- menu = Menu.find_by('ancestry is not NULL')
64
+ menu = Mokio::Menu.find_by('ancestry is not NULL')
61
65
  get :edit, {:id => menu.to_param}, valid_session
62
- assigns(:menu).parent_tree[0].name.should eq(menu.parent.name)
66
+ assigns(:menu).parent_root.name.should eq(menu.parent.name)
63
67
  end
64
68
 
65
69
  it "@parent_tree does not contain self" do
66
- menu = Menu.find_by('ancestry is not NULL')
70
+ menu = Mokio::Menu.find_by('ancestry is not NULL')
67
71
  get :edit, {:id => menu.to_param}, valid_session
68
72
  assigns(:menu).parent_tree.should_not include(menu)
69
73
  end
70
74
 
71
75
  it "gets article list for valid lang PL" do
72
- menu = Menu.create! valid_attributes
76
+ menu = Mokio::Menu.create! valid_attributes
73
77
  get :edit, {:id => menu.to_param}, valid_session
74
- assigns(:menu).available_contents.to_set.superset?(Article.where(:lang_id => menu.lang_id).to_set).should be_true
78
+ assigns(:menu).available_contents.to_set.superset?(Mokio::Article.where(:lang_id => menu.lang_id).to_set).should be_true
75
79
  end
76
80
 
77
81
  it "assigns a list of available (not selected) modules to available_modules_by_pos (with lang_id = 1)" do
@@ -80,12 +84,12 @@ describe Mokio::Backend::MenusController do
80
84
  stat_module.module_positions = [mod_pos]
81
85
  stat_module.lang_id = 1
82
86
  stat_module.save
83
- av_module = AvailableModule.where(static_module_id: stat_module.id, module_position_id: mod_pos.id).first
87
+ av_module = Mokio::AvailableModule.where(static_module_id: stat_module.id, module_position_id: mod_pos.id).first
84
88
  menu = FactoryGirl.create(:menu)
85
- get :edit, {:id => menu.to_param}, valid_session
89
+ get :edit, {:id => menu.to_param}, valid_session
86
90
  (assigns(:menu).available_modules_by_pos[mod_pos.id].include?(av_module)).should be_true
87
91
  end
88
-
92
+
89
93
  end
90
94
 
91
95
  describe "POST create" do
@@ -93,33 +97,33 @@ describe Mokio::Backend::MenusController do
93
97
  it "creates a new Menu" do
94
98
  expect {
95
99
  post :create, {:menu => valid_attributes}, valid_session
96
- }.to change(Menu, :count).by(1)
100
+ }.to change(Mokio::Menu, :count).by(1)
97
101
  end
98
102
 
99
-
103
+
100
104
  it "assigns a newly created backend_menu as @menu" do
101
105
  post :create, {:menu => valid_attributes}, valid_session
102
- assigns(:menu).should be_a(Menu)
106
+ assigns(:menu).should be_a(Mokio::Menu)
103
107
  assigns(:menu).should be_persisted
104
108
  end
105
109
 
106
110
  it "redirects to the created backend_menu" do
107
111
  post :create, {:menu => valid_attributes}, valid_session
108
- response.should redirect_to(backend_menus_path)
112
+ response.should redirect_to(menus_path)
109
113
  end
110
114
  end
111
115
 
112
116
  describe "with invalid params" do
113
117
  it "assigns a newly created but unsaved menu as @menu" do
114
118
  # Trigger the behavior that occurs when invalid params are submitted
115
- Menu.any_instance.stub(:save).and_return(false)
119
+ Mokio::Menu.any_instance.stub(:save).and_return(false)
116
120
  post :create, {:menu => { }}, valid_session
117
- assigns(:menu).should be_a_new(Menu)
121
+ assigns(:menu).should be_a_new(Mokio::Menu)
118
122
  end
119
123
 
120
124
  it "re-renders the 'new' template" do
121
125
  # Trigger the behavior that occurs when invalid params are submitted
122
- @menu = Menu.any_instance.stub(:save).and_return(false)
126
+ @menu = Mokio::Menu.any_instance.stub(:save).and_return(false)
123
127
  post :create, {:menu => { }}, valid_session
124
128
  response.should render_template("new")
125
129
  end
@@ -129,53 +133,53 @@ describe Mokio::Backend::MenusController do
129
133
  describe "PUT update" do
130
134
  describe "with valid params" do
131
135
  it "updates the requested backend_menu" do
132
- menu = Menu.create! valid_attributes
136
+ menu = Mokio::Menu.create! valid_attributes
133
137
  put :update, {:id => menu.to_param, :menu => { :name => "bla" }}, valid_session
134
- @new_menu = Menu.find(menu.id)
138
+ @new_menu = Mokio::Menu.find(menu.id)
135
139
  @new_menu.name.should eq("bla") #_receive(:update) #.with({ :name => "bla" })
136
-
140
+
137
141
  end
138
142
 
139
143
  it "for not editable menu update is not performed" do
140
- menu = Menu.where(editable: false).first
144
+ menu = Mokio::Menu.where(editable: false).first
141
145
  expect(menu.editable).to be_false
142
146
  put :update, {:id => menu.to_param, :menu => {:name => 'New name'}}, valid_session
143
- @new_menu = Menu.find(menu.id)
147
+ @new_menu = Mokio::Menu.find(menu.id)
144
148
  @new_menu.name.should eq(menu.name)
145
149
  end
146
150
 
147
151
  it "assigns the requested backend_menu as @menu" do
148
- menu = Menu.create! valid_attributes
152
+ menu = Mokio::Menu.create! valid_attributes
149
153
  put :update, {:id => menu.to_param, :menu => valid_attributes}, valid_session
150
154
  assigns(:menu).should eq(menu)
151
155
  end
152
156
 
153
157
  it "redirects to the backend_menu" do
154
- menu = Menu.create! valid_attributes
158
+ menu = Mokio::Menu.create! valid_attributes
155
159
  put :update, {:id => menu.to_param, :menu => valid_attributes}, valid_session
156
- response.should redirect_to(backend_menus_path)
160
+ response.should redirect_to(menus_path)
157
161
  end
158
162
  end
159
163
 
160
164
  describe "with invalid params" do
161
165
  it "assigns the backend_menu as @menu" do
162
- menu = Menu.create! valid_attributes
166
+ menu = Mokio::Menu.create! valid_attributes
163
167
  # Trigger the behavior that occurs when invalid params are submitted
164
- Menu.any_instance.stub(:save).and_return(false)
168
+ Mokio::Menu.any_instance.stub(:save).and_return(false)
165
169
  put :update, {:id => menu.to_param, :menu => { }}, valid_session
166
170
  assigns(:menu).should eq(menu)
167
171
  end
168
172
 
169
173
  it "re-renders the 'edit' template" do
170
- menu = Menu.create! valid_attributes
174
+ menu = Mokio::Menu.create! valid_attributes
171
175
  # Trigger the behavior that occurs when invalid params are submitted
172
- Menu.any_instance.stub(:save).and_return(false)
176
+ Mokio::Menu.any_instance.stub(:save).and_return(false)
173
177
  put :update, {:id => menu.to_param, :menu => { }}, valid_session
174
178
  response.should render_template("edit")
175
179
  end
176
180
 
177
181
  it "contents are not removed" do
178
- menu = Menu.create! valid_attributes
182
+ menu = Mokio::Menu.create! valid_attributes
179
183
  content = FactoryGirl.create(:content)
180
184
  menu.contents << content
181
185
  menu.save
@@ -192,7 +196,7 @@ describe Mokio::Backend::MenusController do
192
196
  stat_module.module_positions = [mod_pos]
193
197
  stat_module.lang_id = 1
194
198
  stat_module.save
195
- menu = Menu.create! valid_attributes
199
+ menu = Mokio::Menu.create! valid_attributes
196
200
  first_module = menu.available_modules_by_pos[mod_pos.id][0]
197
201
  menu.available_modules << first_module
198
202
  menu.save
@@ -205,9 +209,9 @@ describe Mokio::Backend::MenusController do
205
209
  end
206
210
 
207
211
  it "contents order is saved after update" do
208
- content1 = Article.create(:title => 'Bla')
209
- content2 = Article.create(:title => 'ZZZZ')
210
- menu = Menu.create! valid_attributes
212
+ content1 = Mokio::Article.create(:title => 'Bla')
213
+ content2 = Mokio::Article.create(:title => 'ZZZZ')
214
+ menu = Mokio::Menu.create! valid_attributes
211
215
  put :update, {:id => menu.to_param, :menu => {:content_ids => [content2.id, content1.id] }}, valid_session
212
216
  menu.reload
213
217
  expect(menu.contents.first).to eq(content2)
@@ -223,7 +227,7 @@ describe Mokio::Backend::MenusController do
223
227
  stat_module1.module_positions = [mod_pos]
224
228
  stat_module1.lang_id = 1
225
229
  stat_module1.save
226
- menu = Menu.create! valid_attributes
230
+ menu = Mokio::Menu.create! valid_attributes
227
231
  first_module_id = menu.available_modules_by_pos[mod_pos.id][0].id
228
232
  put :update, {:id => menu.to_param, :menu => {:available_module_ids => {mod_pos.id.to_s => [menu.available_modules_by_pos[mod_pos.id][0].id, menu.available_modules_by_pos[mod_pos.id][1].id] }}}, valid_session
229
233
  (assigns(:menu).available_modules.first.id).should eq(first_module_id)
@@ -231,8 +235,8 @@ describe Mokio::Backend::MenusController do
231
235
 
232
236
 
233
237
  it "contents are cleared properly" do
234
- content = Article.create(:title => 'Bla')
235
- menu = Menu.create! valid_attributes
238
+ content = Mokio::Article.create(:title => 'Bla')
239
+ menu = Mokio::Menu.create! valid_attributes
236
240
  menu.contents << content
237
241
  menu.save
238
242
  expect(menu.contents.length).to eq(1)
@@ -246,7 +250,7 @@ describe Mokio::Backend::MenusController do
246
250
  stat_module.module_positions = [mod_pos]
247
251
  stat_module.lang_id = 1
248
252
  stat_module.save
249
- menu = Menu.create! valid_attributes
253
+ menu = Mokio::Menu.create! valid_attributes
250
254
  first_module = menu.available_modules_by_pos[mod_pos.id][0]
251
255
  menu.available_modules << first_module
252
256
  menu.save
@@ -260,72 +264,72 @@ describe Mokio::Backend::MenusController do
260
264
 
261
265
  describe "DELETE destroy" do
262
266
  it "destroys the requested menu when deletable" do
263
- menu = Menu.create! valid_attributes.merge(:deletable => true)
267
+ menu = Mokio::Menu.create! valid_attributes.merge(:deletable => true)
264
268
  @obj = menu
265
269
  expect {
266
270
  delete :destroy, {:id => menu.to_param}, valid_session
267
- }.to change(Menu, :count).by(-1)
271
+ }.to change(Mokio::Menu, :count).by(-1)
268
272
  end
269
273
 
270
274
  it "redirects to the backend_menus list" do
271
- menu = Menu.create! valid_attributes
275
+ menu = Mokio::Menu.create! valid_attributes
272
276
  delete :destroy, {:id => menu.to_param}, valid_session
273
- response.should redirect_to(backend_menus_url)
277
+ response.should redirect_to(menus_url)
274
278
 
275
279
  end
276
280
 
277
281
  it "not destroys the requested menu when not deletable" do
278
- menu = Menu.create! valid_attributes.merge(:deletable => false)
282
+ menu = Mokio::Menu.create! valid_attributes.merge(:deletable => false)
279
283
  expect {
280
284
  delete :destroy, {:id => menu.to_param}, valid_session
281
- }.to change(Menu, :count).by(0)
285
+ }.to change(Mokio::Menu, :count).by(0)
282
286
  end
283
287
 
284
288
  it "redirects to the backend_menus list when not deletable" do
285
- menu = Menu.create! valid_attributes.merge(:deletable => false)
289
+ menu = Mokio::Menu.create! valid_attributes.merge(:deletable => false)
286
290
  delete :destroy, {:id => menu.to_param}, valid_session
287
- response.should redirect_to(backend_menus_url)
291
+ response.should redirect_to(menus_url)
288
292
 
289
293
  end
290
294
 
291
295
 
292
296
  it "destroys the requested menu" do
293
- menu = Menu.create! valid_attributes.merge(:deletable => true)
294
- child_del = Menu.create! valid_attributes.merge(:deletable => false, :parent => menu)
295
- child_not_del = Menu.create! valid_attributes.merge(:deletable => true, :parent => menu)
297
+ menu = Mokio::Menu.create! valid_attributes.merge(:deletable => true)
298
+ child_del = Mokio::Menu.create! valid_attributes.merge(:deletable => false, :parent => menu)
299
+ child_not_del = Mokio::Menu.create! valid_attributes.merge(:deletable => true, :parent => menu)
296
300
  expect {
297
301
  delete :destroy, {:id => menu.to_param}, valid_session
298
- }.to change(Menu, :count).by(-1)
302
+ }.to change(Mokio::Menu, :count).by(-1)
299
303
 
300
304
  end
301
305
 
302
306
  it "attaches children to parent node" do
303
- top_parent = Menu.create! valid_attributes.merge(:deletable => true)
304
- menu = Menu.create! valid_attributes.merge(:deletable => true, :parent => top_parent)
305
- child_del = Menu.create! valid_attributes.merge(:deletable => false, :parent => menu)
306
- child_not_del = Menu.create! valid_attributes.merge(:deletable => true, :parent => menu)
307
+ top_parent = Mokio::Menu.create! valid_attributes.merge(:deletable => true)
308
+ menu = Mokio::Menu.create! valid_attributes.merge(:deletable => true, :parent => top_parent)
309
+ child_del = Mokio::Menu.create! valid_attributes.merge(:deletable => false, :parent => menu)
310
+ child_not_del = Mokio::Menu.create! valid_attributes.merge(:deletable => true, :parent => menu)
307
311
  delete :destroy, {:id => menu.to_param}, valid_session
308
- expect top_parent.children.should include(child_del)
312
+ expect top_parent.children.should include(child_del)
309
313
  end
310
314
  end
311
315
 
312
316
  describe "update_menu_breadcrumps" do
313
317
  subject {controller.update_menu_breadcrumps}
314
318
  it "updates menu_breadcrumps element" do
315
- menu = Menu.find_by(:name => "Stopka")
316
- # expect(
317
- # (xhr :get, :update_menu_breadcrumps, {:menu_id => menu.id}, valid_session).body
318
- # ).to match('.*pl.*Stopka.*')
319
- pending
319
+ menu = Mokio::Menu.find_by(:name => "Stopka")
320
+ expect(
321
+ (xhr :get, :update_menu_breadcrumps, {:id => menu.id}, valid_session).body
322
+ ).to match('.*pl.*Stopka.*')
323
+
320
324
  end
321
325
  end
322
326
 
323
327
  describe "lang_changed" do
324
328
  subject {controller.lang_changed}
325
329
  it "updates menu_parent options" do
326
- menu = Menu.find_by(:name => "Stopka")
330
+ menu = Mokio::Menu.find_by(:name => "Stopka")
327
331
  body = (xhr :get, :lang_changed, {:menu_id => menu.id, :lang_id => 1}, valid_session).body
328
- expect(body).to match('.*pl.*')
332
+ expect(body).to match('.*Stopka.*')
329
333
  end
330
334
 
331
335
  end
@@ -333,14 +337,14 @@ describe Mokio::Backend::MenusController do
333
337
  describe "sort" do
334
338
  before(:each) {
335
339
  @menu_hash = {}
336
- @menu_fake_pl = Menu.create! valid_attributes.merge(:parent => nil, :lang_id => 1)
337
- @menu_fake_top = Menu.create! valid_attributes.merge(:parent_id => @menu_fake_pl.id, :lang_id => 1)
338
- @menu = Menu.create! valid_attributes.merge(:parent_id => @menu_fake_top.id, :lang_id => 1)
339
- @menu_child = Menu.create! valid_attributes.merge(:parent_id => @menu.id, :lang_id => 1)
340
- @menu_grandchild1 = Menu.create! valid_attributes.merge(:parent_id => @menu_child.id, :seq => 1, :lang_id => 1)
341
- @menu_grandchild2 = Menu.create! valid_attributes.merge(:parent_id => @menu_child.id, :seq => 2, :lang_id => 1)
342
- @menu_grandchild3 = Menu.create! valid_attributes.merge(:parent_id => @menu_child.id, :seq => 3, :lang_id => 1)
343
- @potential_parent = Menu.create! valid_attributes
340
+ @menu_fake_pl = Mokio::Menu.create! valid_attributes.merge(:parent => nil, :lang_id => 1)
341
+ @menu_fake_top = Mokio::Menu.create! valid_attributes.merge(:parent_id => @menu_fake_pl.id, :lang_id => 1)
342
+ @menu = Mokio::Menu.create! valid_attributes.merge(:parent_id => @menu_fake_top.id, :lang_id => 1)
343
+ @menu_child = Mokio::Menu.create! valid_attributes.merge(:parent_id => @menu.id, :lang_id => 1)
344
+ @menu_grandchild1 = Mokio::Menu.create! valid_attributes.merge(:parent_id => @menu_child.id, :seq => 1, :lang_id => 1)
345
+ @menu_grandchild2 = Mokio::Menu.create! valid_attributes.merge(:parent_id => @menu_child.id, :seq => 2, :lang_id => 1)
346
+ @menu_grandchild3 = Mokio::Menu.create! valid_attributes.merge(:parent_id => @menu_child.id, :seq => 3, :lang_id => 1)
347
+ @potential_parent = Mokio::Menu.create! valid_attributes
344
348
  @menu_hash[@menu.id] = @menu_fake_top.id
345
349
  @menu_hash[@menu_child.id] = @menu_child.parent_id
346
350
  }
@@ -349,7 +353,7 @@ describe Mokio::Backend::MenusController do
349
353
  it "changes the order of elements" do
350
354
  @menu_hash[@menu_grandchild2.id] = @menu_grandchild2.parent_id
351
355
  @menu_hash[@menu_grandchild1.id] = @menu_grandchild1.parent_id
352
- xhr :get, :sort, {:menu => @menu_hash}, valid_session
356
+ xhr :get, :sort, {:menu => @menu_hash}, valid_session
353
357
  expect(@menu_grandchild2.reload.seq).to eq(1)
354
358
  expect(@menu_grandchild1.reload.seq).to eq(2)
355
359
  end
@@ -375,21 +379,21 @@ describe Mokio::Backend::MenusController do
375
379
  expect(@menu_child.reload.root.id).to eq(@menu_grandchild3.root.id)
376
380
  expect(@menu_child.reload.root.id).not_to eq(@menu_child.parent.id)
377
381
  expect(@menu_child.root.lang.id).to eq(@menu_child.lang.id)
378
-
382
+
379
383
  end
380
384
 
381
- it "allows changes of ROOT nodes order" do
382
- @menu2 = Menu.create! valid_attributes.merge(:parent => nil, :lang_id => 1)
383
- @menu3 = Menu.create! valid_attributes.merge(:parent_id => nil, :lang_id => 1)
385
+ it "allows changes of ROOT nodes order" do
386
+ @menu2 = Mokio::Menu.create! valid_attributes.merge(:parent => nil, :lang_id => 1)
387
+ @menu3 = Mokio::Menu.create! valid_attributes.merge(:parent_id => nil, :lang_id => 1)
384
388
  @menu_hash[@menu2.id] = "null"
385
389
  @menu_hash[@menu3.id] = "null"
386
-
387
- xhr :get, :sort, {:menu => @menu_hash}, valid_session
390
+
391
+ xhr :get, :sort, {:menu => @menu_hash}, valid_session
388
392
  expect(@menu3.reload.seq).to eq(@menu2.reload.seq + 1)
389
393
 
390
394
  end
391
395
 
392
- it "doesn't allow loops in the tree" do
396
+ it "doesn't allow loops in the tree" do
393
397
  @menu_hash[@menu_child.id] = @menu_grandchild1.id
394
398
  xhr :get, :sort, {:menu => @menu_hash}, valid_session
395
399
  @menu_child.reload
@@ -402,8 +406,9 @@ describe Mokio::Backend::MenusController do
402
406
  @menu_grandchild1.save
403
407
  @menu_hash[@menu_grandchild1.id] = @root_en.id
404
408
  expect(@menu_grandchild1.lang_id).not_to eq(@root_en.lang_id)
405
- xhr :get, :sort, {:menu => @menu_hash}, valid_session
409
+ xhr :get, :sort, {:menu => @menu_hash}, valid_session
406
410
  expect(@menu_grandchild1.reload.lang_id).to eq(@root_en.lang_id)
407
411
  end
408
412
  end
409
413
  end
414
+ end