jinda 0.1.0 → 0.1.6.6

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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -11
  3. data/Rakefile +3 -1
  4. data/bin/console +1 -1
  5. data/lib/generators/jinda/config_generator.rb +23 -9
  6. data/lib/generators/jinda/install_generator.rb +31 -22
  7. data/lib/generators/jinda/minitest_generator.rb +30 -0
  8. data/lib/generators/jinda/rspec_generator.rb +30 -0
  9. data/lib/generators/jinda/templates/.env +2 -0
  10. data/lib/generators/jinda/templates/app/assets/images/facebook-continue-button.png +0 -0
  11. data/lib/generators/jinda/templates/app/assets/images/google-continue-button.png +0 -0
  12. data/lib/generators/jinda/templates/app/assets/javascripts/jqm/jquery.mobile.datebox.js +10 -4
  13. data/lib/generators/jinda/templates/app/assets/stylesheets/application.css.scss +2 -1
  14. data/lib/generators/jinda/templates/app/assets/stylesheets/jqm/app.scss +84 -0
  15. data/lib/generators/jinda/templates/app/assets/stylesheets/jqm/social.scss +133 -0
  16. data/lib/generators/jinda/templates/app/controllers/articles_controller.rb +17 -1
  17. data/lib/generators/jinda/templates/app/controllers/{ctrs_controller.rb → ctrs_controller.rb-gem-test} +0 -0
  18. data/lib/generators/jinda/templates/app/controllers/jinda_controller.rb +11 -3
  19. data/lib/generators/jinda/templates/app/jinda/index.mm +2 -2
  20. data/lib/generators/jinda/templates/app/jinda/template/linkview.haml +21 -0
  21. data/lib/generators/jinda/templates/app/models/jinda/module.rb +1 -1
  22. data/lib/generators/jinda/templates/app/models/user.rb +4 -2
  23. data/lib/generators/jinda/templates/app/views/jinda/_menu.haml +3 -1
  24. data/lib/generators/jinda/templates/app/views/jinda/_menu_mm.haml +17 -2
  25. data/lib/generators/jinda/templates/app/views/jinda/_static.haml +0 -10
  26. data/lib/generators/jinda/templates/app/views/jinda/index.html.haml +4 -3
  27. data/lib/generators/jinda/templates/app/views/jinda/run_form.haml +1 -1
  28. data/lib/generators/jinda/templates/app/views/layouts/jqm/_full.haml +11 -11
  29. data/lib/generators/jinda/templates/spec/controllers/articles_controller_spec.rb +155 -0
  30. data/lib/generators/jinda/templates/spec/helpers/rails_helper.rb +46 -0
  31. data/lib/generators/jinda/templates/spec/helpers/spec_helper.rb +96 -0
  32. data/lib/generators/jinda/templates/spec/models/user_spec.rb +26 -0
  33. data/lib/generators/jinda/templates/spec/requests/jinda_routes_spec.rb +82 -0
  34. data/lib/generators/jinda/templates/spec/requests/password_resets_spec.rb +15 -0
  35. data/lib/generators/jinda/templates/test/application_system_test_case.rb +5 -0
  36. data/lib/generators/jinda/templates/test/integration/jinda_routes_test.rb +42 -0
  37. data/lib/generators/jinda/templates/test/test_helper.rb +6 -0
  38. data/lib/jinda/gemhelpers.rb +50 -0
  39. data/lib/jinda/helpers.rb +335 -30
  40. data/lib/jinda/railtie.rb +2 -2
  41. data/lib/jinda/version.rb +1 -1
  42. data/lib/tasks/jinda.rake +0 -169
  43. metadata +141 -21
  44. data/lib/generators/jinda/templates/app/assets/images/facebook-button.png +0 -0
  45. data/lib/generators/jinda/templates/app/assets/images/facebook-sign-in-button.png +0 -0
  46. data/lib/generators/jinda/templates/app/assets/stylesheets/jqm/rouge.css.erb +0 -11
  47. data/lib/generators/jinda/templates/spec/controllers/admins_controller_spec.rb +0 -5
  48. data/lib/generators/jinda/templates/spec/controllers/devs_controller_spec.rb +0 -5
  49. data/lib/generators/jinda/templates/spec/controllers/users_controller_spec.rb +0 -5
  50. data/lib/generators/jinda/templates/spec/helpers/admins_helper_spec.rb +0 -15
  51. data/lib/generators/jinda/templates/spec/helpers/devs_helper_spec.rb +0 -15
  52. data/lib/generators/jinda/templates/spec/helpers/users_helper_spec.rb +0 -15
  53. data/lib/generators/jinda/templates/spec/spec_helper.rb +0 -38
  54. data/test/jinda_test.rb +0 -7
  55. data/test/test_helper.rb +0 -4
@@ -0,0 +1,133 @@
1
+ html * {
2
+ font-family: 'Montserrat', sans-serif;
3
+ box-sizing: border-box;
4
+ }
5
+
6
+ body {
7
+ background: #4688F1;
8
+ padding: 0;
9
+ margin: 0;
10
+ }
11
+
12
+ .login-box {
13
+ padding: 20px;
14
+ max-width: 480px;
15
+ margin: 5vh auto;
16
+ text-align: center;
17
+ letter-spacing: 1px;
18
+ position: relative;
19
+ }
20
+
21
+ .login-box:hover {
22
+ box-shadow: 0 8px 17px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
23
+ }
24
+
25
+ .login-box h2 {
26
+ margin: 20px 0 20px;
27
+ padding: 0;
28
+ text-transform: uppercase;
29
+ color: #4688F1;
30
+ }
31
+
32
+ .social-button {
33
+ background-position: 25px 0px;
34
+ box-sizing: border-box;
35
+ color: rgb(255, 255, 255);
36
+ cursor: pointer;
37
+ display: inline-block;
38
+ height: 50px;
39
+ line-height: 50px;
40
+ text-align: left;
41
+ text-decoration: none;
42
+ text-transform: uppercase;
43
+ vertical-align: middle;
44
+ width: 100%;
45
+ border-radius: 3px;
46
+ margin: 10px auto;
47
+ outline: rgb(255, 255, 255) none 0px;
48
+ padding-left: 20%;
49
+ transition: all 0.2s cubic-bezier(0.72, 0.01, 0.56, 1) 0s;
50
+ -webkit-transition: all .3s ease;
51
+ -moz-transition: all .3s ease;
52
+ -ms-transition: all .3s ease;
53
+ -o-transition: all .3s ease;
54
+ transition: all .3s ease;
55
+ }
56
+
57
+ #facebook-connect {
58
+ background: rgb(255, 255, 255) url('https://eswarasai.com/projects/social-login/img/facebook.svg') no-repeat scroll 5px 0px / 30px 50px padding-box border-box;
59
+ border: 1px solid rgb(60, 90, 154);
60
+ }
61
+
62
+ #facebook-connect:hover {
63
+ border-color: rgb(60, 90, 154);
64
+ background: rgb(60, 90, 154) url('https://eswarasai.com/projects/social-login/img/facebook-white.svg') no-repeat scroll 5px 0px / 30px 50px padding-box border-box;
65
+ -webkit-transition: all .8s ease-out;
66
+ -moz-transition: all .3s ease;
67
+ -ms-transition: all .3s ease;
68
+ -o-transition: all .3s ease;
69
+ transition: all .3s ease-out;
70
+ }
71
+
72
+ #facebook-connect span {
73
+ box-sizing: border-box;
74
+ color: rgb(60, 90, 154);
75
+ cursor: pointer;
76
+ text-align: center;
77
+ text-transform: uppercase;
78
+ border: 0px none rgb(255, 255, 255);
79
+ outline: rgb(255, 255, 255) none 0px;
80
+ -webkit-transition: all .3s ease;
81
+ -moz-transition: all .3s ease;
82
+ -ms-transition: all .3s ease;
83
+ -o-transition: all .3s ease;
84
+ transition: all .3s ease;
85
+ }
86
+
87
+ #facebook-connect:hover span {
88
+ color: #FFF;
89
+ -webkit-transition: all .3s ease;
90
+ -moz-transition: all .3s ease;
91
+ -ms-transition: all .3s ease;
92
+ -o-transition: all .3s ease;
93
+ transition: all .3s ease;
94
+ }
95
+
96
+ #google-connect {
97
+ background: rgb(255, 255, 255) url('https://eswarasai.com/projects/social-login/img/google-plus.png') no-repeat scroll 5px 0px / 50px 50px padding-box border-box;
98
+ border: 1px solid rgb(220, 74, 61);
99
+ }
100
+
101
+ #google-connect:hover {
102
+ border-color: rgb(220, 74, 61);
103
+ background: rgb(220, 74, 61) url('https://eswarasai.com/projects/social-login/img/google-plus-white.png') no-repeat scroll 5px 0px / 50px 50px padding-box border-box;
104
+ -webkit-transition: all .8s ease-out;
105
+ -moz-transition: all .3s ease;
106
+ -ms-transition: all .3s ease;
107
+ -o-transition: all .3s ease;
108
+ transition: all .3s ease-out;
109
+ }
110
+
111
+ #google-connect span {
112
+ box-sizing: border-box;
113
+ color: rgb(220, 74, 61);
114
+ cursor: pointer;
115
+ text-align: center;
116
+ text-transform: uppercase;
117
+ border: 0px none rgb(220, 74, 61);
118
+ outline: rgb(255, 255, 255) none 0px;
119
+ -webkit-transition: all .3s ease;
120
+ -moz-transition: all .3s ease;
121
+ -ms-transition: all .3s ease;
122
+ -o-transition: all .3s ease;
123
+ transition: all .3s ease;
124
+ }
125
+
126
+ #google-connect:hover span {
127
+ color: #FFF;
128
+ -webkit-transition: all .3s ease;
129
+ -moz-transition: all .3s ease;
130
+ -ms-transition: all .3s ease;
131
+ -o-transition: all .3s ease;
132
+ transition: all .3s ease;
133
+ }
@@ -19,14 +19,23 @@ class ArticlesController < ApplicationController
19
19
  end
20
20
 
21
21
  def create
22
+
22
23
  @article = Article.new(
23
24
  title: $xvars["form_article"]["title"],
24
25
  text: $xvars["form_article"]["text"],
25
26
  keywords: $xvars["form_article"]["keywords"],
26
27
  body: $xvars["form_article"]["body"],
27
-
28
28
  user_id: $xvars["user_id"])
29
29
  @article.save!
30
+ # if @article.save!
31
+ # format.html { redirect_to @article, notice: 'Sample was successfully created.' }
32
+ # format.json { render :show, status: :created, location: @article }
33
+ # else
34
+ # format.html { render :new }
35
+ # format.json { render json: @article.errors, status: :unprocessable_entity }
36
+ # end
37
+ redirect_to @article
38
+
30
39
  end
31
40
 
32
41
  def my
@@ -40,14 +49,21 @@ class ArticlesController < ApplicationController
40
49
  # They contain everything that we get their forms select_article and edit_article
41
50
  article_id = $xvars["select_article"] ? $xvars["select_article"]["title"] : $xvars["p"]["article_id"]
42
51
  @article = Article.find(article_id)
52
+
43
53
  @article.update(title: $xvars["edit_article"]["article"]["title"],
44
54
  text: $xvars["edit_article"]["article"]["text"],
45
55
  keywords: $xvars["edit_article"]["article"]["keywords"],
46
56
  body: $xvars["edit_article"]["article"]["body"])
57
+ redirect_to @article
58
+
47
59
 
48
60
  end
49
61
 
50
62
  def destroy
63
+ if Rails.env.test? #Temp solution until fix test of current_ma_user
64
+ current_ma_user = $xvars["current_ma_user"]
65
+ #current_ma_user = @article.user
66
+ end
51
67
  if current_ma_user.role.upcase.split(',').include?("A") || current_ma_user == @article.user
52
68
  @article.destroy
53
69
  end
@@ -36,11 +36,13 @@ class JindaController < ApplicationController
36
36
  ####################################################################################################]
37
37
  # prepare xmain.runseq eg: how many form_step or total_step and step properties check if authorized
38
38
  ####################################################################################################]
39
+ # view menu by user selected what service (module and code) to run (not all services like menu did
40
+ # Its only one service
39
41
  def init
40
42
  module_code, code = params[:s].split(":")
41
43
  @service= Jinda::Service.where(:module_code=> module_code, :code=> code).first
42
44
  # @service= Jinda::Service.where(:module_code=> params[:module], :code=> params[:service]).first
43
- if @service && authorize_init?
45
+ if @service && authorize_init?
44
46
  xmain = create_xmain(@service)
45
47
  result = create_runseq(xmain)
46
48
  unless result
@@ -59,6 +61,8 @@ class JindaController < ApplicationController
59
61
  end
60
62
  ####################################################################################################]
61
63
  # run if, form, mail, output etc depend on icon in freemind
64
+ # action from @runseq.action == do, form, if, output
65
+ # Then will call def run_do, run_form, run_if, run_output
62
66
  ####################################################################################################]
63
67
  def run
64
68
  init_vars(params[:id])
@@ -76,6 +80,9 @@ class JindaController < ApplicationController
76
80
  redirect_to_root
77
81
  else
78
82
  service= @xmain.service
83
+ ###############################################################################################
84
+ # Run View Form f created template by jinda rake follow freemind mm file
85
+ ###############################################################################################
79
86
  if service
80
87
  @title= "Transaction ID #{@xmain.xid}: #{@xmain.name} / #{@runseq.name}"
81
88
  fhelp= "app/views/#{service.module.code}/#{service.code}/#{@runseq.code}.md"
@@ -251,7 +258,8 @@ class JindaController < ApplicationController
251
258
  }
252
259
 
253
260
  else
254
- v = v.to_unsafe_h unless v.class == String
261
+ # bug in to_unsalfe_h rails 5.1.6 https://github.com/getsentry/raven-ruby/issues/799
262
+ # v = v.to_unsafe_h unless v.class == String
255
263
  eval "@xvars[@runseq.code][k] = v"
256
264
  end
257
265
  }
@@ -345,7 +353,7 @@ class JindaController < ApplicationController
345
353
  File.open('public/doc.html','w') {|f| f.puts html }
346
354
  respond_to do |format|
347
355
  format.html {
348
- render :plain=> @print+html, :layout => 'layouts/_page'
356
+ render :plain=> @print+html, :layout => 'layouts/jqm/_page'
349
357
  # render :text=> Maruku.new(doc).to_html, :layout => false
350
358
  # format.html {
351
359
  # h = RDoc::Markup::ToHtml.new
@@ -2,10 +2,10 @@
2
2
  <!-- To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net -->
3
3
  <node CREATED="1273819432637" ID="ID_1098419600" MODIFIED="1334737006485" TEXT="Jinda">
4
4
  <node CREATED="1273819462973" ID="ID_282419531" MODIFIED="1493705904561" POSITION="right" TEXT="services">
5
- <node CREATED="1275756501221" FOLDED="true" ID="ID_1720745721" MODIFIED="1507471632977" TEXT="users:User">
5
+ <node CREATED="1275756501221" ID="ID_1720745721" MODIFIED="1528215844718" TEXT="users:User">
6
6
  <node CREATED="1278491598711" ID="ID_1662699954" MODIFIED="1494393920347" TEXT="role:m"/>
7
7
  <node CREATED="1279700865182" ID="ID_1266797279" MODIFIED="1357798847781" TEXT="link:info: /users"/>
8
- <node CREATED="1319015338880" ID="ID_189841353" MODIFIED="1330477824203" TEXT="link:pending tasks: /mindapp/pending"/>
8
+ <node CREATED="1319015338880" ID="ID_189841353" MODIFIED="1528215866339" TEXT="link:pending tasks: /jinda/pending"/>
9
9
  <node CREATED="1275905802131" ID="ID_154000410" MODIFIED="1355422418892" TEXT="user:edit">
10
10
  <node CREATED="1275756515843" ID="ID_1108188320" MODIFIED="1330477833918" TEXT="enter_user:edit">
11
11
  <icon BUILTIN="attach"/>
@@ -0,0 +1,21 @@
1
+ - @title= "My Articles"
2
+ %p
3
+ - @page_title = 'All Articlces'
4
+ = paginate @articles
5
+ %table#article-table
6
+ %tr
7
+ %th Title
8
+ %th Description
9
+ %th Created
10
+ %th Updated
11
+ %th Delete
12
+ %th Edit
13
+ - @articles.each do |article|
14
+ %tr
15
+ %td= link_to article.title, :controller=>"articles", :action=>"show", :id=>article.id
16
+ %td= article.text.html_safe
17
+ %td= article.created_at.strftime('%m/%d/%Y')
18
+ %td= article.updated_at.strftime('%m/%d/%Y')
19
+ %td(align='center')= link_to image_tag('delete.png', style:'border:none; float:none;'), "#", :onclick=>"if (confirm('Please Confirm')) {location.hash='/articles/destroy/#{article.id}';}"
20
+ %td(align='center')= link_to image_tag('pencil.png', style:'border:none; float:none;'), {controller: "jinda", action: "init", s: 'articles:xedit_article', article_id: article.id}, data: { confirm: "Please Confirm" }
21
+
@@ -6,6 +6,6 @@ class Jinda::Module
6
6
  field :name, :type => String
7
7
  field :role, :type => String
8
8
  field :seq, :type => Integer
9
-
9
+ field :icon, :type => String
10
10
  has_many :services, :class_name => "Jinda::Service"
11
11
  end
@@ -28,8 +28,10 @@ class User
28
28
  end
29
29
 
30
30
  def self.from_omniauth(auth)
31
- where(auth.slice(:uid, :provider, :email)).first_or_create do |user|
32
- case auth.provider
31
+ # Rails now no longer support slice
32
+ # where(auth.slice(:uid, :provider, :email)).first_or_create do |user|
33
+ where(uid: auth.uid, provider: auth.provider, email: auth.info.email).first_or_create do |user|
34
+ case auth.provider
33
35
  when 'identity'
34
36
  identity = Identity.find auth.uid
35
37
  user.code = identity.code
@@ -21,4 +21,6 @@
21
21
  %li
22
22
  = link_to "Refresh", "#", :onclick=>"window.location.replace('/')"
23
23
  - if !login?
24
- = link_to image_tag( 'facebook-sign-in-button.png'), '/auth/facebook', rel: "external"
24
+ .login-box
25
+ = link_to image_tag( 'facebook-continue-button.png'), '/auth/facebook', rel: "external", class: "facebook-connect.social-button"
26
+ = link_to image_tag( 'google-continue-button.png'), '/auth/google_oauth2', rel: "external", class: "google-connect.social-button"
@@ -3,9 +3,24 @@
3
3
  - unless m.role.blank?
4
4
  - next unless login?
5
5
  - next unless current_ma_user.role
6
- - next unless current_ma_user.role.upcase.split(',').include?(m.role.upcase)
6
+ -# next unless current_ma_user.role.upcase.split(',').include?(m.role.upcase)
7
+ -# ####################### Remove w space in role ###################
8
+ - next unless current_ma_user.role.upcase.split(",").map!(&:strip).include?(m.role.upcase)
9
+
7
10
  %li
11
+ -# ########################### Main Display Menu ####################
8
12
  = m.name
13
+ -# ##################################################################
14
+ -# Code to display current login user role and required role for menu
15
+ -# ##################################################################
16
+
17
+ -# if defined?(current_ma_user.role) && !current_ma_user.role.blank?
18
+ =# current_ma_user.role
19
+ -# if m.role?
20
+ =# m.role.upcase
21
+
22
+ -# ##################################################################
23
+
9
24
  %ul
10
25
  - m.services.asc(:seq).each do |s|
11
26
  - next unless s.list
@@ -15,7 +30,7 @@
15
30
  - unless s.role.blank?
16
31
  - next unless login?
17
32
  - next unless current_ma_user.role
18
- - next unless current_ma_user.role.upcase.split(',').include?(s.role.upcase)
33
+ - next unless current_ma_user.role.upcase.split(",").map!(&:strip).include?(s.role.upcase)
19
34
  - if s.code.downcase=="link"
20
35
  - name, url = s.name.split(":", 2)
21
36
  - url.strip!
@@ -11,13 +11,3 @@
11
11
  = link_to "Pending Tasks", "#", :onclick=>"location.hash='/jinda/pending'", "data-role"=>"button"
12
12
  = link_to "Refresh", "#", :onclick=>"window.location.replace('/')", "data-role"=>"button"
13
13
  = link_to "About", "#", :onclick=>"location.hash='#about'", "data-role"=>"button"
14
- :javascript
15
- function notice(msg) {
16
- $("<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h1>"+ msg +"</h1></div>")
17
- .css({ "display": "block", "opacity": 0.96, "top": $(window).scrollTop() + 100 })
18
- .appendTo( $('div[data-id="main"]') )
19
- .delay( 4000 )
20
- .fadeOut( 400, function(){
21
- $(this).remove();
22
- });
23
- }
@@ -14,17 +14,18 @@
14
14
  %ul
15
15
  %li Rubygems 2.4.1
16
16
  %li Rails 5.1.4
17
- %li rails new YOURAPP -skip-test-unit --skip-bundle --skip-active-record
17
+ %li rails new YOURAPP --skip-test-unit --skip-bundle --skip-active-record
18
+ %li (rails new YOURAPP -BOT)
18
19
 
19
20
 
20
21
  %h2 Installation
21
22
  %ul
22
- %li gem 'jinda', '~> 0.0.8'
23
+ %li add gem 'jinda', '~> 0.1.1'
23
24
  %li bundle
24
25
  %li rails generate jinda:install
25
26
  %li bundle
26
27
  %li rails generate jinda:config
27
- %li rake db:seed, will create initial user:password admin:secret
28
+ %li rails jinda:seed, will create initial user:password admin:secret
28
29
  %li when update app/jinda/index.mm, run rake jinda:update
29
30
 
30
31
  %h2 Option: Themes available: Jinda_adminbsb, Jinda_adminlte
@@ -6,7 +6,7 @@
6
6
  - next_step = 'end_form'
7
7
  - if @help
8
8
  %div(data-role="collapsible" data-theme="e" data-content-theme="c" data-mini="true")
9
- %h3 ตำแนะนำ
9
+ %h3 Help
10
10
  %p= markdown(@help)
11
11
  = form_tag({ :action => next_step } , {:multipart => true, :onSubmit=>'return validate()', :class=>form_class, "data-ajax"=>"#{ajax?(@ui)}"}) do
12
12
  = hidden_field_tag 'xmain_id', @xmain.id
@@ -8,7 +8,7 @@
8
8
  = display_meta_tags
9
9
  - if GMAP
10
10
  = javascript_include_tag "http://maps.google.com/maps/api/js?sensor=false"
11
- - if ADSENSE
11
+ -# if ADSENSE
12
12
  = render :partial => 'custom/adsense'
13
13
  %body
14
14
  = render :partial => "jinda/menu"
@@ -27,15 +27,15 @@
27
27
  %div{"data-role" => "content"}
28
28
  = yield
29
29
  = render :partial => "jinda/static"
30
- :javascript
31
- $(document).on("pagehide", 'div', function(e,ui) {
32
- var page = $(e.target);
33
- if(page.attr('data-cache') == 'never') {
34
- page.remove();
35
- }
36
- });
37
- $( document ).on( "pagechange", function(){
38
- $.get("/jinda/ajax_notice", function(r) {$(r).appendTo('head').remove()});
39
- });
30
+ / :javascript
31
+ / $(document).on("pagehide", 'div', function(e,ui) {
32
+ / var page = $(e.target);
33
+ / if(page.attr('data-cache') == 'never') {
34
+ / page.remove();
35
+ / }
36
+ / });
37
+ / $( document ).on( "pagechange", function(){
38
+ / $.get("/jinda/ajax_notice", function(r) {$(r).appendTo('head').remove()});
39
+ / });
40
40
 
41
41
  /= raw handle_ma_notice
@@ -0,0 +1,155 @@
1
+ require 'rails_helper'
2
+ require 'database_cleaner'
3
+
4
+
5
+
6
+ RSpec.describe ArticlesController, type: :controller do
7
+
8
+
9
+ let(:valid_input) {
10
+ {:title => "My Title", :text => "My Item", :user_id => "admin"}
11
+ }
12
+
13
+ let(:invalid_input) {
14
+ {:title => "", :text => "", :user_id => ""}
15
+ }
16
+
17
+ @user = User.new(:uid => "admin", :provider => "Facebook", :email => "1.0@kul.asia", :role=> "a,m")
18
+
19
+
20
+ $xvars = {}
21
+ $xvars["form_article"] = {}
22
+
23
+ $xvars["form_article"]["title"] = "AAAAAA"
24
+ $xvars["form_article"]["text"] = "AAAAAA"
25
+ $xvars["form_article"]["body"] = "AAAAA"
26
+ $xvars["user_id"] = @user.id
27
+
28
+
29
+ $xvars["select_article"] = {}
30
+ $xvars["select_article"] = nil
31
+ $xvars["p"] = {}
32
+ $nxvars = {}
33
+ $xvars["edit_article"] = {}
34
+ $xvars["edit_article"]["article"] = {}
35
+ $xvars["edit_article"]["article"]["title"] = "BBBBB"
36
+ $xvars["edit_article"]["article"]["text"] = "BBBBB"
37
+ $xvars["edit_article"]["article"]["keywords"] = "BBBBB"
38
+ $xvars["edit_article"]["article"]["body"] = "BBBBB"
39
+ $xvars["current_ma_user"] = @user
40
+
41
+ let(:valid_attributes) {
42
+
43
+ {title: $xvars["form_article"]["title"],
44
+ text: $xvars["form_article"]["text"],
45
+ keywords: $xvars["form_article"]["keywords"],
46
+ body: $xvars["form_article"]["body"],
47
+ user_id: $xvars["user_id"]}
48
+ }
49
+
50
+ let(:invalid_attributes) {
51
+ {}
52
+ }
53
+
54
+ let(:valid_session) { {} }
55
+
56
+ describe "GET #index" do
57
+ it "returns a success response" do
58
+ article = Article.create! valid_input
59
+ get :index, params: {}, session: valid_session
60
+ expect(response).to be_success
61
+ end
62
+ end
63
+
64
+ describe "GET #show" do
65
+ it "returns a success response" do
66
+ article = Article.create! valid_input
67
+ get :show, params: {id: article.to_param}, session: valid_session
68
+ expect(response).to be_success
69
+ end
70
+ end
71
+
72
+ describe "GET #edit" do
73
+ it "returns a success response" do
74
+ article = Article.create! valid_input
75
+ get :edit, params: {id: article.to_param}, session: valid_session
76
+ expect(response).to be_success
77
+ end
78
+ end
79
+
80
+ describe "POST #create" do
81
+ context "with valid params" do
82
+ it "creates a new Article" do
83
+ expect {
84
+ post :create, params: {article: valid_attributes}, session: valid_session
85
+ }.to change(Article, :count).by(1)
86
+
87
+ end
88
+
89
+ it "redirects to the created article" do
90
+ post :create, params: {article: valid_attributes}, session: valid_session
91
+ expect(response).to redirect_to(Article.last)
92
+ end
93
+ end
94
+
95
+ context "with invalid params" do
96
+ it "returns a success response (i.e. to display the 'new' template)" do
97
+ post :create, params: {article: invalid_attributes}, session: valid_session
98
+ expect(response).not_to be_success
99
+ end
100
+ end
101
+ end
102
+
103
+ describe "PUT #update" do
104
+ context "with valid params" do
105
+ let(:new_attributes) {
106
+ $xvars
107
+ }
108
+
109
+ it "updates the requested article" do
110
+ article = Article.create! valid_attributes
111
+ $xvars["p"]["article_id"] = article.to_param
112
+ put :update, params: {id: article.to_param, article: new_attributes}, session: valid_session
113
+ article.reload
114
+ expect(article.title).to eq "BBBBB"
115
+ end
116
+
117
+ it "redirects to the article" do
118
+ article = Article.create! valid_attributes
119
+ $xvars["p"]["article_id"] = article.to_param
120
+ put :update, params: {id: article.to_param, article: new_attributes}, session: valid_session
121
+ expect(response).to redirect_to(article)
122
+ end
123
+ end
124
+
125
+ context "with invalid params" do
126
+ it "returns a success response (i.e. to display the 'edit' template)" do
127
+ article = Article.create! valid_attributes
128
+ $xvars["p"]["article_id"] = article.to_param
129
+ put :update, params: {id: article.to_param, article: invalid_attributes}, session: valid_session
130
+ expect(response).not_to be_success
131
+ end
132
+ end
133
+ end
134
+
135
+ describe "DELETE #destroy" do
136
+
137
+ it "destroys the requested article" do
138
+ article = Article.create! valid_attributes
139
+ #current_ma_user = article.user_id
140
+
141
+ expect {
142
+ delete :destroy, params: {id: article.to_param}, session: valid_session
143
+ }.to change(Article, :count).by(-1)
144
+ end
145
+
146
+ it "redirects to the articles list" do
147
+ article = Article.create! valid_attributes
148
+ delete :destroy, params: {id: article.to_param}, session: valid_session
149
+ expect(response).to redirect_to(articles_url)
150
+ end
151
+ end
152
+ if DatabaseCleaner.clean
153
+ puts "Cleaning Database ............................................"
154
+ end
155
+ end