wobapphelpers 3.1.0

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.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +155 -0
  4. data/Rakefile +30 -0
  5. data/app/assets/stylesheets/wobapphelpers/breadcrumbs.scss +13 -0
  6. data/config/locales/de.yml +9 -0
  7. data/config/locales/en.yml +9 -0
  8. data/lib/generators/templates/erb/scaffold/_form.html.erb +26 -0
  9. data/lib/generators/templates/erb/scaffold/edit.html.erb +1 -0
  10. data/lib/generators/templates/erb/scaffold/index.html.erb +32 -0
  11. data/lib/generators/templates/erb/scaffold/new.html.erb +1 -0
  12. data/lib/generators/templates/erb/scaffold/show.html.erb +15 -0
  13. data/lib/generators/templates/initializers/wobapphelpers.rb +18 -0
  14. data/lib/generators/templates/layouts/application.html.erb +44 -0
  15. data/lib/generators/templates/rails/scaffold_controller/controller.rb +66 -0
  16. data/lib/generators/wobapphelpers/install_generator.rb +24 -0
  17. data/lib/generators/wobapphelpers/scaffold_templates_generator.rb +20 -0
  18. data/lib/tasks/wobapphelpers_tasks.rake +4 -0
  19. data/lib/wobapphelpers.rb +37 -0
  20. data/lib/wobapphelpers/breadcrumbs.rb +16 -0
  21. data/lib/wobapphelpers/breadcrumbs/action_controller.rb +57 -0
  22. data/lib/wobapphelpers/breadcrumbs/breadcrumbs_helper.rb +26 -0
  23. data/lib/wobapphelpers/helpers.rb +12 -0
  24. data/lib/wobapphelpers/helpers/action_view_helper.rb +170 -0
  25. data/lib/wobapphelpers/helpers/icon_helper.rb +39 -0
  26. data/lib/wobapphelpers/rails.rb +4 -0
  27. data/lib/wobapphelpers/responders.rb +13 -0
  28. data/lib/wobapphelpers/responders/locales/de.yml +12 -0
  29. data/lib/wobapphelpers/responders/locales/en.yml +12 -0
  30. data/lib/wobapphelpers/version.rb +4 -0
  31. data/test/breadcrumbs/action_controller_test.rb +44 -0
  32. data/test/breadcrumbs/breadcrumb_helper_test.rb +35 -0
  33. data/test/dummy/app/controllers/application_controller.rb +19 -0
  34. data/test/dummy/app/controllers/blogs_controller.rb +55 -0
  35. data/test/dummy/app/controllers/home_controller.rb +7 -0
  36. data/test/dummy/app/controllers/posts_controller.rb +58 -0
  37. data/test/dummy/app/helpers/application_helper.rb +3 -0
  38. data/test/dummy/app/helpers/blogs_helper.rb +2 -0
  39. data/test/dummy/app/helpers/posts_helper.rb +2 -0
  40. data/test/dummy/app/models/blog.rb +2 -0
  41. data/test/dummy/app/models/post.rb +2 -0
  42. data/test/dummy/config/application.rb +31 -0
  43. data/test/dummy/config/boot.rb +5 -0
  44. data/test/dummy/config/environment.rb +5 -0
  45. data/test/dummy/config/environments/development.rb +37 -0
  46. data/test/dummy/config/environments/production.rb +83 -0
  47. data/test/dummy/config/environments/test.rb +45 -0
  48. data/test/dummy/config/initializers/assets.rb +1 -0
  49. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  50. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  51. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  52. data/test/dummy/config/initializers/inflections.rb +16 -0
  53. data/test/dummy/config/initializers/mime_types.rb +4 -0
  54. data/test/dummy/config/initializers/session_store.rb +3 -0
  55. data/test/dummy/config/initializers/simple_form.rb +161 -0
  56. data/test/dummy/config/initializers/simple_form_bootstrap.rb +107 -0
  57. data/test/dummy/config/initializers/wobapphelpers.rb +9 -0
  58. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  59. data/test/dummy/config/routes.rb +61 -0
  60. data/test/dummy/db/migrate/20140420155942_create_posts.rb +12 -0
  61. data/test/dummy/db/migrate/20140516164637_create_blogs.rb +12 -0
  62. data/test/dummy/db/schema.rb +33 -0
  63. data/test/dummy/lib/templates/rails/scaffold_controller/controller.rb +65 -0
  64. data/test/generators/install_generator_test.rb +29 -0
  65. data/test/generators/scaffold_templates_generator_test.rb +16 -0
  66. data/test/helpers/action_view_helper_test.rb +41 -0
  67. data/test/helpers/active_class_helper_test.rb +9 -0
  68. data/test/helpers/can_view_helper_test.rb +172 -0
  69. data/test/helpers/flash_helper_test.rb +11 -0
  70. data/test/helpers/form_legend_test.rb +29 -0
  71. data/test/helpers/icon_helper_test.rb +21 -0
  72. data/test/helpers/show_edit_delete_link_helper_test.rb +45 -0
  73. data/test/integration/helper_delivery_test.rb +28 -0
  74. data/test/responders/flash_test.rb +23 -0
  75. data/test/test_helper.rb +42 -0
  76. data/test/tmp/lib/templates/rails/scaffold_controller/controller.rb +66 -0
  77. data/test/translate_test.rb +10 -0
  78. data/test/wobapphelpers_test.rb +20 -0
  79. metadata +371 -0
@@ -0,0 +1,65 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= controller_class_name %>Controller < ApplicationController
7
+ before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
8
+
9
+ # GET <%= route_url %>
10
+ def index
11
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
12
+ respond_with(@<%= plural_table_name %>)
13
+ end
14
+
15
+ # GET <%= route_url %>/1
16
+ def show
17
+ respond_with(@<%= singular_table_name %>)
18
+ end
19
+
20
+ # GET <%= route_url %>/new
21
+ def new
22
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
23
+ respond_with(@<%= singular_table_name %>)
24
+ end
25
+
26
+ # GET <%= route_url %>/1/edit
27
+ def edit
28
+ end
29
+
30
+ # POST <%= route_url %>
31
+ def create
32
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
33
+
34
+ @<%= orm_instance.save %>
35
+ respond_with(@<%= singular_table_name %>)
36
+ end
37
+
38
+ # PATCH/PUT <%= route_url %>/1
39
+ def update
40
+ @<%= orm_instance.update("#{singular_table_name}_params") %>
41
+ respond_with(@<%= singular_table_name %>)
42
+ end
43
+
44
+ # DELETE <%= route_url %>/1
45
+ def destroy
46
+ @<%= orm_instance.destroy %>
47
+ respond_with(@<%= singular_table_name %>)
48
+ end
49
+
50
+ private
51
+ # Use callbacks to share common setup or constraints between actions.
52
+ def set_<%= singular_table_name %>
53
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
54
+ end
55
+
56
+ # Only allow a trusted parameter "white list" through.
57
+ def <%= "#{singular_table_name}_params" %>
58
+ <%- if attributes_names.empty? -%>
59
+ params[:<%= singular_table_name %>]
60
+ <%- else -%>
61
+ params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
62
+ <%- end -%>
63
+ end
64
+ end
65
+ <% end -%>
@@ -0,0 +1,29 @@
1
+ require "test_helper"
2
+
3
+ class InstallGeneratorTest < Rails::Generators::TestCase
4
+ tests Wobapphelpers::Generators::InstallGenerator
5
+ destination File.expand_path("../../tmp", __FILE__)
6
+ setup :prepare_destination
7
+
8
+ test "Assert all files are properly created" do
9
+ run_generator
10
+ assert_file "config/locales/wobapphelpers.de.yml"
11
+ assert_file "config/locales/wobapphelpers.en.yml"
12
+ end
13
+
14
+ test "Assert layout is copied" do
15
+ run_generator
16
+ assert_file "app/views/layouts/application.html.erb" do |layout|
17
+ assert_match(/DOCTYPE html/, layout)
18
+ assert_match(/navbar-brand/, layout)
19
+ assert_match(/meta name="viewport"/, layout)
20
+ end
21
+ end
22
+
23
+ test "Initializer is copied" do
24
+ run_generator
25
+ assert_file "config/initializers/wobapphelpers.rb" do |init|
26
+ assert_match(/Wobapphelpers.setup/, init)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,16 @@
1
+ require "test_helper"
2
+
3
+ class ScaffoldTemplatesGeneratorTest < Rails::Generators::TestCase
4
+ tests Wobapphelpers::Generators::ScaffoldTemplatesGenerator
5
+ destination File.expand_path("../../tmp", __FILE__)
6
+ setup :prepare_destination
7
+
8
+ test "Assert all files are properly created" do
9
+ run_generator
10
+ ["show.html.erb", "edit.html.erb", "new.html.erb",
11
+ "index.html.erb", "_form.html.erb"].each do |file|
12
+ assert_file "lib/templates/erb/scaffold/#{file}"
13
+ end
14
+ assert_file "lib/templates/rails/scaffold_controller/controller.rb"
15
+ end
16
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+ require 'sass'
3
+ require 'jquery-rails'
4
+ require 'shoulda-context'
5
+
6
+ class ActionViewHelperTest < ActionDispatch::IntegrationTest
7
+ setup do
8
+ Post.create!(subject: 'brabbel', body: 'Dies ist ein Test', user: 'wob', release: Date.today)
9
+ Post.create!(subject: 'fasel', body: 'Dies ist ein zweiter Test', user: 'wob', release: Date.today)
10
+ end
11
+
12
+ context "without cancan" do
13
+ should "show posts#index" do
14
+ visit posts_path
15
+ within('table tbody') do
16
+ assert all(:xpath, '//a[contains(@class, "btn btn-secondary") and contains(@title, "Posting anzeigen")]').count == 2,
17
+ "No show posting link found"
18
+ assert all(:xpath, '//a[contains(@class,"btn btn-secondary") and contains(@title, "Posting bearbeiten")]').count == 2,
19
+ "No edit posting link found"
20
+ assert (all(:xpath, '//a[contains(@class,"btn btn-danger") and contains(@data-method, "delete") and contains(@title, "Posting löschen")]').length == 2),
21
+ "No delete posting link found"
22
+ end
23
+ assert page.has_link?('Posting erstellen'), "no new post link found"
24
+ assert find(:xpath, '//a[contains(@class, "btn btn-secondary") and contains(text(), "Posting erstellen")]'),
25
+ "No new posting link found"
26
+ assert page.has_link?('Zurück'), "No back button found"
27
+ assert find(:xpath, '//a[contains(@class, "btn btn-secondary") and contains(text(), "Zurück")]'),
28
+ "No back button found"
29
+ end
30
+
31
+ should "cancel_button renders i with class fa" do
32
+ visit new_post_path
33
+ assert page.has_text?('Post/new')
34
+ within('form') do
35
+ assert page.has_link?('Abbrechen'), "button submit not found"
36
+ assert find('a.btn.btn-secondary i.fa.fa-trash'),
37
+ "button cancel not found"
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class ActiveClassHelperTest < ActionView::TestCase
4
+ include Wobapphelpers::Helpers::ActionViewHelper
5
+
6
+ should "render new link" do
7
+ assert_equal "active", render(plain: active_class('test'))
8
+ end
9
+ end
@@ -0,0 +1,172 @@
1
+ require 'test_helper'
2
+ require 'sass'
3
+ require 'jquery-rails'
4
+ require 'shoulda-context'
5
+
6
+ class CanViewHelperTest < ActionController::TestCase
7
+ tests PostsController
8
+
9
+ setup do
10
+ @p1 = Post.create!(subject: 'brabbel', body: 'Dies ist ein Test', user: 'wob', release: Date.today)
11
+ @p2 = Post.create!(subject: 'fasel', body: 'Dies ist ein zweiter Test', user: 'wob', release: Date.today)
12
+ Wobapphelpers.cancan = :cancan1
13
+ @ability = Object.new
14
+ @ability.extend(::CanCan::Ability)
15
+ @controller.stubs(:current_ability).returns(@ability)
16
+ end
17
+
18
+ teardown do
19
+ Wobapphelpers.cancan = :none
20
+ end
21
+
22
+
23
+ context "with ability :create" do
24
+ setup do
25
+ @ability.can :create, Post
26
+ end
27
+
28
+ should "render new link" do
29
+ get :index
30
+ assert_select "a.btn.btn-secondary", {
31
+ href: "/posts/new", text: "Posting erstellen", count: 1
32
+ }
33
+ end
34
+
35
+ should "not render show link" do
36
+ get :index
37
+ assert_select "a.btn.btn-secondary" do
38
+ assert_select "[href='/posts/#{assigns(:posts).first.id}']",
39
+ title: "Posting anzeigen", count: 0
40
+ assert_select "[href='/posts/#{assigns(:posts).last.id}']",
41
+ title: "Posting anzeigen", count: 0
42
+ end
43
+ end
44
+
45
+ should "not render edit link" do
46
+ get :index
47
+ assert_select "a.btn.btn-secondary" do
48
+ assert_select "[href='/posts/#{assigns(:posts).first.id}/edit']",
49
+ title: "Posting bearbeiten", count: 0
50
+ assert_select "[href='/posts/#{assigns(:posts).last.id}/edit']",
51
+ title: "Posting bearbeiten", count: 0
52
+ end
53
+ end
54
+ should "not render delete link" do
55
+ get :index
56
+ assert_select "a.btn.btn-danger", title: "Posting löschen", count: 0
57
+ end
58
+ end
59
+
60
+ context "with ability :read" do
61
+ setup do
62
+ @ability.can :read, Post
63
+ end
64
+
65
+ should "render show link" do
66
+ get :index
67
+ assert_select "a.btn.btn-secondary" do
68
+ assert_select "[href='/posts/#{assigns(:posts).first.id}']",
69
+ title: "Posting anzeigen"
70
+ assert_select "[href='/posts/#{assigns(:posts).last.id}']",
71
+ title: "Posting anzeigen"
72
+ end
73
+ end
74
+
75
+ should "not render create link" do
76
+ get :index
77
+ assert_select "a.btn.btn-secondary", {
78
+ href: "/posts/new", text: "Posting erstellen", count: 0
79
+ }
80
+ end
81
+ should "not render edit link" do
82
+ get :index
83
+ assert_select "a.btn.btn-secondary" do
84
+ assert_select "[href='/posts/#{assigns(:posts).first.id}/edit']",
85
+ title: "Posting bearbeiten", count: 0
86
+ assert_select "[href='/posts/#{assigns(:posts).last.id}/edit']",
87
+ title: "Posting bearbeiten", count: 0
88
+ end
89
+ end
90
+ should "not render delete link" do
91
+ get :index
92
+ assert_select "a.btn.btn-danger", title: "Posting löschen", count: 0
93
+ end
94
+ end
95
+
96
+ context "with ability :update" do
97
+ setup do
98
+ @ability.can :update, Post
99
+ end
100
+
101
+ should "not render show link" do
102
+ get :index
103
+ assert_select "a.btn.btn-secondary" do
104
+ assert_select "[href='/posts/#{assigns(:posts).first.id}']",
105
+ title: "Posting anzeigen", count: 0
106
+ assert_select "[href='/posts/#{assigns(:posts).last.id}']",
107
+ title: "Posting anzeigen", count: 0
108
+ end
109
+ end
110
+
111
+ should "not render create link" do
112
+ get :index
113
+ assert_select "a.btn.btn-secondary", {
114
+ href: "/posts/new", text: "Posting erstellen", count: 0
115
+ }
116
+ end
117
+ should "render edit link" do
118
+ get :index
119
+ assert_select "a.btn.btn-secondary" do
120
+ assert_select "[href='/posts/#{assigns(:posts).first.id}/edit']",
121
+ title: "Posting bearbeiten"
122
+ assert_select "[href='/posts/#{assigns(:posts).last.id}/edit']",
123
+ title: "Posting bearbeiten"
124
+ end
125
+ end
126
+ should "not render delete link" do
127
+ get :index
128
+ assert_select "a.btn.btn-danger", title: "Posting löschen", count: 0
129
+ end
130
+ end
131
+
132
+ context "with ability :read" do
133
+ setup do
134
+ @ability.can :destroy, Post
135
+ end
136
+
137
+ should "not render show link" do
138
+ get :index
139
+ assert_select "a.btn.btn-secondary" do
140
+ assert_select "[href='/posts/#{assigns(:posts).first.id}']",
141
+ title: "Posting anzeigen", count: 0
142
+ assert_select "[href='/posts/#{assigns(:posts).last.id}']",
143
+ title: "Posting anzeigen", count: 0
144
+ end
145
+ end
146
+
147
+ should "not render create link" do
148
+ get :index
149
+ assert_select "a.btn.btn-secondary", {
150
+ href: "/posts/new", text: "Posting erstellen", count: 0
151
+ }
152
+ end
153
+ should "not render edit link" do
154
+ get :index
155
+ assert_select "a.btn.btn-secondary" do
156
+ assert_select "[href='/posts/#{assigns(:posts).first.id}/edit']",
157
+ title: "Posting bearbeiten", count: 0
158
+ assert_select "[href='/posts/#{assigns(:posts).last.id}/edit']",
159
+ title: "Posting bearbeiten", count: 0
160
+ end
161
+ end
162
+ should "render delete link" do
163
+ get :index
164
+ assert_select "a.btn.btn-danger" do
165
+ assert_select "[href='/posts/#{assigns(:posts).first.id}']",
166
+ title: "Posting bearbeiten", count: 1
167
+ assert_select "[href='/posts/#{assigns(:posts).last.id}']",
168
+ title: "Posting bearbeiten", count: 1
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class FlashHelperTest < ActionController::TestCase
4
+ tests PostsController
5
+
6
+ test "shows flash messages within layout" do
7
+ get :index
8
+ assert_match "Always done", response.body
9
+ end
10
+
11
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ class FormLegendTest < ActionController::TestCase
4
+ tests PostsController
5
+
6
+ setup do
7
+ @p1 = Post.create!(subject: 'brabbel', body: 'Dies ist ein Test', user: 'wob', release: Date.today)
8
+ @p2 = Post.create!(subject: 'fasel', body: 'Dies ist ein zweiter Test', user: 'wob', release: Date.today)
9
+ end
10
+
11
+ should "render group specific new form title" do
12
+ get :new
13
+ assert_select "div.row" do
14
+ assert_select "div" do
15
+ assert_select "legend", text: "Post/new"
16
+ end
17
+ end
18
+ end
19
+
20
+ should "render group specific update form title" do
21
+ get :edit, params: { id: @p1 }
22
+ assert_select "div.row" do
23
+ assert_select "div" do
24
+ assert_select "legend", text: "Post/edit"
25
+ end
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+ require 'sass'
3
+
4
+ class IconHelperTest < ActionView::TestCase
5
+ include Wobapphelpers::Helpers::IconHelper
6
+
7
+ test "icon() renders i with class fa" do
8
+ render plain: icon('search')
9
+
10
+ assert_select 'i.fa.fa-search.fa-fw', 1
11
+ assert_select 'i.fa.fa-quark', 0
12
+ end
13
+
14
+ Wobapphelpers::Helpers::IconHelper::PREDEFINED_ICONS.each do |key,value|
15
+ test "icon_#{key} renders i with class fa-#{value}" do
16
+ render plain: send("icon_#{key}")
17
+
18
+ assert_select "i.fa.fa-#{value}", 1
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+ require 'sass'
3
+
4
+ class ShowEditDeleteLinkHelperTest < ActionView::TestCase
5
+ include Wobapphelpers::Helpers::All
6
+
7
+ setup do
8
+ @post = Post.create(subject: 'bla', body: 'text')
9
+ end
10
+
11
+ test "new_link with options :class, :title and :remote" do
12
+ render plain: new_link(Post, class: 'btn btn-small',
13
+ title: 'Test title', remote: true)
14
+
15
+ assert_select 'a[class=?][title=?][data-remote=?]',
16
+ "btn btn-small", "Test title", "true"
17
+ end
18
+
19
+ test "show_link with options :class, :title and :remote" do
20
+ render plain: show_link(@post, class: 'btn btn-small',
21
+ title: 'Test title', remote: true)
22
+
23
+ assert_select 'a[class=?][title=?][data-remote=?]',
24
+ "btn btn-small", "Test title", "true"
25
+ end
26
+
27
+ test "edit_link with options :class, :title and :remote" do
28
+ render plain: edit_link(@post, class: 'btn btn-small',
29
+ title: 'Test title', remote: true)
30
+
31
+ assert_select 'a[class=?][title=?][data-remote=?]',
32
+ "btn btn-small", "Test title", "true"
33
+ end
34
+
35
+ test "delete_link with options :class, :title and :remote" do
36
+ render plain: delete_link(@post, class: 'btn btn-small',
37
+ title: 'Test title', remote: true)
38
+
39
+ assert_select 'a[class=?][title=?][data-remote=?][data-method=?]',
40
+ "btn btn-small", "Test title", "true", "delete"
41
+ end
42
+
43
+
44
+
45
+ end