turbosack 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +10 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/modules.xml +8 -0
- data/.idea/turbolog.iml +42 -0
- data/.idea/vcs.xml +6 -0
- data/.idea/workspace.xml +217 -0
- data/.rspec +3 -0
- data/.travis.yml +21 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Guardfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +81 -0
- data/Rakefile +21 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/generators/turbosack/config_generator.rb +138 -0
- data/lib/generators/turbosack/install_generator.rb +67 -0
- data/lib/generators/turbosack/templates/.env +2 -0
- data/lib/generators/turbosack/templates/.gitignore +21 -0
- data/lib/generators/turbosack/templates/.rspec +2 -0
- data/lib/generators/turbosack/templates/app/controllers/Users/omniauth_callbacks_controller.rb +6 -0
- data/lib/generators/turbosack/templates/app/helpers/application_helper.rb +10 -0
- data/lib/generators/turbosack/templates/app/models/user.rb +12 -0
- data/lib/generators/turbosack/templates/application_controller_spec.rb +8 -0
- data/lib/generators/turbosack/templates/lib/string_calculator.rb +12 -0
- data/lib/generators/turbosack/templates/routes.rb +6 -0
- data/lib/generators/turbosack/templates/spec/controllers/welcomes_controller_spec.rb +86 -0
- data/lib/generators/turbosack/templates/spec/factories/users.rb +15 -0
- data/lib/generators/turbosack/templates/spec/factories/welcomes.rb +5 -0
- data/lib/generators/turbosack/templates/spec/helpers/welcomes_helper_spec.rb +23 -0
- data/lib/generators/turbosack/templates/spec/models/welcome_spec.rb +17 -0
- data/lib/generators/turbosack/templates/spec/rails_helper.rb +23 -0
- data/lib/generators/turbosack/templates/spec/requests/welcomes_spec.rb +16 -0
- data/lib/generators/turbosack/templates/spec/spec_helper.rb +96 -0
- data/lib/generators/turbosack/templates/spec/support/controller_helper.rb +12 -0
- data/lib/generators/turbosack/templates/spec/support/database_cleaner.rb +73 -0
- data/lib/generators/turbosack/templates/spec/support/devise.rb +8 -0
- data/lib/generators/turbosack/templates/spec/welcomes_controller_spec.rb +86 -0
- data/lib/tasks/turbosack.rake +28 -0
- data/lib/turbosack.rb +6 -0
- data/lib/turbosack/helpers.rb +11 -0
- data/lib/turbosack/railtie.rb +18 -0
- data/lib/turbosack/version.rb +3 -0
- data/turbosack.gemspec +35 -0
- metadata +258 -0
data/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Turbolog
|
|
2
|
+
|
|
3
|
+
Turbolog is a gem to setup devise, omniauth and facebook authentication.
|
|
4
|
+
|
|
5
|
+
For the following configuration:
|
|
6
|
+
|
|
7
|
+
.Rails 5.1.4, 5.2.0.rc1
|
|
8
|
+
.Ruby 2.4.1, 2.5.0
|
|
9
|
+
.Devise
|
|
10
|
+
.Mongoid
|
|
11
|
+
.Omniauth_facebook
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Add this line to your application's Gemfile:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
gem 'turbolog'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
And then execute:
|
|
22
|
+
|
|
23
|
+
$ bundle
|
|
24
|
+
|
|
25
|
+
Or install it yourself as:
|
|
26
|
+
|
|
27
|
+
$ gem install turbolog
|
|
28
|
+
|
|
29
|
+
Once turbolog gem bundled, there are 3 steps to install.
|
|
30
|
+
|
|
31
|
+
Step 1/3 execute :
|
|
32
|
+
|
|
33
|
+
$ rails g turbolog:install
|
|
34
|
+
|
|
35
|
+
It will backup and will include several gems
|
|
36
|
+
|
|
37
|
+
Step 2/3 bundle install
|
|
38
|
+
|
|
39
|
+
$ bundle install
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
Step 3/3 execute :
|
|
43
|
+
|
|
44
|
+
$ rails g turbolog:config
|
|
45
|
+
|
|
46
|
+
It will run mongoid:config, devise install, devise Users and config omniauth and generate scaffold welcome as an example
|
|
47
|
+
|
|
48
|
+
Additional Setup For Facebook in .env
|
|
49
|
+
for example
|
|
50
|
+
FACEBOOK_API="xxxxxxxxxxxxxxxxx"
|
|
51
|
+
FACEBOOK_SECRET="xxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
1. Create new rails app
|
|
55
|
+
|
|
56
|
+
$ rails new sample -B -O -T
|
|
57
|
+
2. Follow Installation 3 steps above
|
|
58
|
+
|
|
59
|
+
Other command:
|
|
60
|
+
|
|
61
|
+
To remove devise line from config/routes by execute the following command
|
|
62
|
+
|
|
63
|
+
$ rake turbolog:clean
|
|
64
|
+
|
|
65
|
+
## Development
|
|
66
|
+
|
|
67
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
68
|
+
|
|
69
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
70
|
+
|
|
71
|
+
## Contributing
|
|
72
|
+
|
|
73
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kul1/turbolog. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
78
|
+
|
|
79
|
+
## Code of Conduct
|
|
80
|
+
|
|
81
|
+
Everyone interacting in the Turbolog project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/kul1/turbolog/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
2
|
+
|
|
3
|
+
#require "rake/testtask"
|
|
4
|
+
# Rake::TestTask.new(:test) do |t|
|
|
5
|
+
# t.libs << "test"
|
|
6
|
+
# t.libs << "lib"
|
|
7
|
+
# t.test_files = FileList["test/**/*_test.rb"]
|
|
8
|
+
# end
|
|
9
|
+
|
|
10
|
+
# task :default => :test
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
require 'rspec/core/rake_task'
|
|
14
|
+
|
|
15
|
+
# Default directory to look in is `/specs`
|
|
16
|
+
# Run with `rake spec`
|
|
17
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
|
18
|
+
task.rspec_opts = ['--color', '--format', 'nested']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
task :default => :spec
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "turbolog"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
require 'turbolog/helpers'
|
|
2
|
+
module Turbolog
|
|
3
|
+
module Generators
|
|
4
|
+
class ConfigGenerator < Rails::Generators::Base
|
|
5
|
+
def self.source_root
|
|
6
|
+
File.dirname(__FILE__) + "/templates"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.blue(mytext)
|
|
10
|
+
"\e[34m#{mytext}\e[0m".center(40)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
desc "Config mongoid"
|
|
14
|
+
puts Color.blue(" .................run mongoid:config....................\n")
|
|
15
|
+
|
|
16
|
+
def config_mongoid
|
|
17
|
+
run "rails g mongoid:config"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def sethost_mongoid
|
|
21
|
+
puts Color.blue("..............change localhost to 127.0.0.1.............\n")
|
|
22
|
+
gsub_file 'config/mongoid.yml','localhost:27017','127.0.0.1:27017'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
desc "Configure Devise"
|
|
26
|
+
def config_devise
|
|
27
|
+
puts Color.blue("..................rails g devise:install................\n")
|
|
28
|
+
run "rails generate devise:install"
|
|
29
|
+
puts Color.blue(" ..............Remove devise from routes.............\n")
|
|
30
|
+
gsub_file 'config/routes.rb',/devise_for.*\n/,''
|
|
31
|
+
puts Color.blue("....................rails g devise User.................\n")
|
|
32
|
+
run "rails generate devise User"
|
|
33
|
+
gsub_file 'config/initializers/devise.rb',/# config.secret_key/,'config.secret_key'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
desc "Create Initial Sample Controller"
|
|
37
|
+
puts Color.blue(".............Create Welcome Initial Controller..........\n")
|
|
38
|
+
def create_welcome
|
|
39
|
+
run "rails g scaffold welcome greeting:text"
|
|
40
|
+
#copy_file "welcomes_controller_spec.rb","spec/controllers"
|
|
41
|
+
#copy_file "welcomes_spec.rb","spec/models"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def config_root
|
|
45
|
+
# set root to Welcome
|
|
46
|
+
puts Color.blue(".................config routes for user ................\n")
|
|
47
|
+
copy_file "routes.rb","config/routes.rb"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def dot_option
|
|
51
|
+
# set root to Welcome
|
|
52
|
+
puts Color.blue("......................config .rspec ....................\n")
|
|
53
|
+
copy_file ".rspec",".rspec"
|
|
54
|
+
copy_file ".env",".env"
|
|
55
|
+
copy_file ".gitignore",".gitignore" #protect .env
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
desc "authenticate_user"
|
|
59
|
+
def authenticate_user
|
|
60
|
+
puts Color.blue("..............Authenticate user in application..........\n")
|
|
61
|
+
inject_into_file 'app/controllers/application_controller.rb', :after => 'class ApplicationController < ActionController::Base' do
|
|
62
|
+
"\n before_action :authenticate_user!\n"
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
desc "Set up omniauth config"
|
|
67
|
+
def setup_omniauth
|
|
68
|
+
puts Color.blue("...............config devise for facebook...............\n")
|
|
69
|
+
inject_into_file 'config/initializers/devise.rb', :after => 'Devise.setup do |config|' do
|
|
70
|
+
"\n config.omniauth :facebook, ENV['FACEBOOK_API'], ENV['FACEBOOK_SECRET']\n"
|
|
71
|
+
end
|
|
72
|
+
puts Color.blue("..............config user model for facebook............\n")
|
|
73
|
+
inject_into_file 'app/models/user.rb', :after => 'include Mongoid::Document' do
|
|
74
|
+
"\n\n include Mongoid::Attributes::Dynamic" +
|
|
75
|
+
"\n devise :omniauthable, :omniauth_providers => [:facebook]" +
|
|
76
|
+
"\n def self.from_omniauth(auth)" +
|
|
77
|
+
"\n where(provider: auth.provider, uid: auth.uid).first_or_create do |user|" +
|
|
78
|
+
"\n user.email = auth.info.email" +
|
|
79
|
+
"\n user.password = Devise.friendly_token[0,20]" +
|
|
80
|
+
"\n end" +
|
|
81
|
+
"\n end\n"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
puts Color.blue("...........Add field [provider] to user model...........\n")
|
|
85
|
+
inject_into_file 'app/models/user.rb', :after => ' field :encrypted_password, type: String, default: ""' do
|
|
86
|
+
"\n field :provider, type: String, default: \"\"\n"
|
|
87
|
+
"\n field :admin, type: Boolean, default: false \n"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
desc "Add Log In/Log Out View in application.html.erb"
|
|
93
|
+
puts Color.blue("......Add Log In/Log Out View in application.html.......\n")
|
|
94
|
+
|
|
95
|
+
def log_in_out
|
|
96
|
+
inject_into_file 'app/views/layouts/application.html.erb', :after => '<body>' do
|
|
97
|
+
"\n "+
|
|
98
|
+
"\n <p class=\"notice\"><%= notice %></p>" +
|
|
99
|
+
"\n <p class=\"alert\"><%= alert %></p>" +
|
|
100
|
+
"\n <% if user_signed_in? %>" +
|
|
101
|
+
"\n <%= link_to \"Log Out\", destroy_user_session_path, method: :delete %>" +
|
|
102
|
+
"\n <% else %>" +
|
|
103
|
+
"\n <%= link_to(\"Log In\", new_user_session_path) %>" +
|
|
104
|
+
"\n <% end %>\n"
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
desc "Config default mail server in development and test"
|
|
109
|
+
puts Color.blue("......Add Log In/Log Out View in application.html.......\n")
|
|
110
|
+
def set_default_mailer
|
|
111
|
+
inject_into_file 'config/environments/development.rb', :after => 'ails.application.configure do' do
|
|
112
|
+
"\n ## config default mail server \n" +
|
|
113
|
+
" config.action_mailer.default_url_options = { host\: \"localhost\:3000\" }\n"
|
|
114
|
+
end
|
|
115
|
+
inject_into_file 'config/environments/test.rb', :after => 'ails.application.configure do' do
|
|
116
|
+
"\n ## config default mail server \n" +
|
|
117
|
+
" config.action_mailer.default_url_options = { host\: \"localhost\:3000\" }\n"
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
desc "Add user spec"
|
|
122
|
+
puts Color.blue("......................Add Spec Data.....................\n")
|
|
123
|
+
def add_spec
|
|
124
|
+
directory "spec"
|
|
125
|
+
# Added sample calculator test
|
|
126
|
+
directory "lib"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def finish
|
|
130
|
+
puts "\n"
|
|
131
|
+
puts Color.blue("________________________________________________________\n")
|
|
132
|
+
puts Color.blue(" Finished Step 3/3\n")
|
|
133
|
+
puts Color.blue("________________________________________________________\n")
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require 'turbosack/helpers'
|
|
2
|
+
module Turbosack
|
|
3
|
+
module Generators
|
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
|
5
|
+
desc "Install Turbosack component to existing Rails app "
|
|
6
|
+
def self.source_root
|
|
7
|
+
File.dirname(__FILE__) + "/templates"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def setup_gems
|
|
11
|
+
puts Color.blue(" ....................Insert Gems....................\n")
|
|
12
|
+
gem 'devise'
|
|
13
|
+
gem 'mongo', '~> 2.2'
|
|
14
|
+
gem 'bson', '~> 4.0'
|
|
15
|
+
gem 'mongoid', github: 'mongodb/mongoid'
|
|
16
|
+
gem 'nokogiri' # use for jinda/doc
|
|
17
|
+
gem 'haml', '~> 5.0', '>= 5.0.4'
|
|
18
|
+
gem 'haml-rails'
|
|
19
|
+
gem 'bcrypt'
|
|
20
|
+
gem 'omniauth-identity'
|
|
21
|
+
gem 'omniauth-facebook'
|
|
22
|
+
gem 'dotenv-rails'
|
|
23
|
+
gem_group :development, :test do
|
|
24
|
+
gem 'rspec'
|
|
25
|
+
gem 'rspec-rails'
|
|
26
|
+
gem 'better_errors'
|
|
27
|
+
gem 'binding_of_caller'
|
|
28
|
+
gem 'pry-byebug'
|
|
29
|
+
gem 'factory_bot_rails'
|
|
30
|
+
gem 'guard'
|
|
31
|
+
gem 'guard-rspec'
|
|
32
|
+
gem 'guard-minitest'
|
|
33
|
+
gem 'capybara'
|
|
34
|
+
gem 'rb-fsevent'
|
|
35
|
+
gem 'simplecov'
|
|
36
|
+
gem 'faker', :git => 'https://github.com/stympy/faker.git', :branch => 'master'
|
|
37
|
+
gem 'database_cleaner'
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def backup_files
|
|
42
|
+
puts Color.blue(" ...................Backup Filess....................\n")
|
|
43
|
+
inside("app/controllers") {(File.file? "Users/omniauth_callbacks_controller.rb") ? (run "mv omniauth_callbacks_controller.rb omniauth_callbacks_controller.rb.bak") : (puts "No omniauth_callbacks_controller.rb")}
|
|
44
|
+
inside("config/initializers") {(File.file? "devise.rb") ? (run "mv devise.rb devise.rb.bak") : (puts "No devise.rb")}
|
|
45
|
+
inside("app/models") {(File.file? "user.rb") ? (run "mv user.rb user.rb.bak") : (puts "No user.rb")}
|
|
46
|
+
inside("app/helpers") {(File.file? "application_helper.rb") ? (run "mv application_helper.rb application_helper.rb.bak") : (puts "No application_helper.rb")}
|
|
47
|
+
inside("app/views/layouts") {(File.file? "application.html.erb") ? (run "cp application.html.erb application.html.erb.bak") : (puts "No application.html.erb")}
|
|
48
|
+
inside("config") {(File.file? "routes.rb") ? (run "cp routes.rb routes.rb.bak") : (puts "No routes.rb")}
|
|
49
|
+
directory "app"
|
|
50
|
+
end
|
|
51
|
+
def remove_devise
|
|
52
|
+
puts Color.blue(" ..............Remove devise from routes.............\n")
|
|
53
|
+
gsub_file 'config/routes.rb',/devise_for.*\n/,''
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def finish
|
|
57
|
+
puts "\n"
|
|
58
|
+
puts Color.blue(" ....................Finish Step 1/3..................\n")
|
|
59
|
+
puts "Next: Please run the following command:\n"
|
|
60
|
+
puts Color.blue("......................................................\n")
|
|
61
|
+
puts "$ bundle install\n"
|
|
62
|
+
puts "$ rails generate turbosack:config\n"
|
|
63
|
+
puts Color.blue("......................................................\n")
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
|
2
|
+
#
|
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
|
6
|
+
|
|
7
|
+
# Ignore bundler config.
|
|
8
|
+
/.bundle
|
|
9
|
+
|
|
10
|
+
# Ignore all logfiles and tempfiles.
|
|
11
|
+
/log/*
|
|
12
|
+
/tmp/*
|
|
13
|
+
!/log/.keep
|
|
14
|
+
!/tmp/.keep
|
|
15
|
+
|
|
16
|
+
/node_modules
|
|
17
|
+
/yarn-error.log
|
|
18
|
+
|
|
19
|
+
.byebug_history
|
|
20
|
+
.env-my
|
|
21
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class User
|
|
2
|
+
include Mongoid::Document
|
|
3
|
+
include Mongoid::Attributes::Dynamic
|
|
4
|
+
## Added
|
|
5
|
+
field :activated, type: Boolean, default: false
|
|
6
|
+
field :activated_at, type: DateTime
|
|
7
|
+
|
|
8
|
+
def User.digest(string)
|
|
9
|
+
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine.cost
|
|
10
|
+
BCrypt::Password.create(string, cost: cost)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require 'rails_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe WelcomesController, type: :controller do
|
|
4
|
+
|
|
5
|
+
let(:valid_attributes) {
|
|
6
|
+
{':greeting'=>'Initial Greeting'}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let(:invalid_attributes) {
|
|
10
|
+
{':greeting' => nil}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let(:valid_session) { {} }
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
before do
|
|
17
|
+
puts '========>'+' '+ 'Run before of FactoryBot for @welcome'
|
|
18
|
+
@authorize_user = FactoryBot.create(:authorize_user)
|
|
19
|
+
@welcome = FactoryBot.create(:welcome)
|
|
20
|
+
@welcome.save
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
describe "GET #index success #{200}" do
|
|
25
|
+
it "returns a success response" do
|
|
26
|
+
sign_in(@authorize_user)
|
|
27
|
+
expect(response).to be_success
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe "Sign_in GET #show" do
|
|
33
|
+
it "returns a success response" do
|
|
34
|
+
sign_in(@authorize_user)
|
|
35
|
+
welcome = Welcome.create!(greeting: 'Greeting by FactoryBot')
|
|
36
|
+
get :show, params: {id: welcome.to_param}, session: valid_session
|
|
37
|
+
#expect(response).to be_success
|
|
38
|
+
assert_response :success
|
|
39
|
+
#assert_response :redirect #302 Sign_in
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe "GET #new redirect to Sign_in #302" do
|
|
45
|
+
it "returns a success response" do
|
|
46
|
+
get :new, params: {}, session: valid_session
|
|
47
|
+
assert_response :redirect #302 Sign_in
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "POST #create" do
|
|
52
|
+
context "create welcome redirect to sign_in" do
|
|
53
|
+
it "it redirect to users/sign_in" do
|
|
54
|
+
post :create, params: {welcome: { greeting: "Lorem ipsum" }}, session: valid_session
|
|
55
|
+
expect(response).to redirect_to("/users/sign_in")
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "login create welcome expect success" do
|
|
60
|
+
sign_in(@authorize_user)
|
|
61
|
+
welcome = Welcome.create!(greeting: 'Greeting by FactoryBot')
|
|
62
|
+
#post :create, params: {welcome: { greeting: "Lorem ipsum" }}, session: valid_session
|
|
63
|
+
expect(response).to be_success
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
describe "DELETE #destroy" do
|
|
69
|
+
|
|
70
|
+
it "can not delete then redirects to users/sign_in" do
|
|
71
|
+
delete :destroy, params: {id: 3333}
|
|
72
|
+
expect(response).to redirect_to("/users/sign_in")
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe "Login user can delete" do
|
|
77
|
+
it "then returns to welcomes" do
|
|
78
|
+
sign_in(@authorize_user)
|
|
79
|
+
puts '========>'+' '+ @welcome.to_param
|
|
80
|
+
@welcome.reload
|
|
81
|
+
delete :destroy, params: {id: @welcome.to_param}
|
|
82
|
+
expect(response).to redirect_to(welcomes_url)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|