gensearch 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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 +307 -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/gensearch.gemspec +35 -0
- data/lib/generators/gensearch/config_generator.rb +138 -0
- data/lib/generators/gensearch/install_generator.rb +67 -0
- data/lib/generators/gensearch/templates/.env +2 -0
- data/lib/generators/gensearch/templates/.gitignore +21 -0
- data/lib/generators/gensearch/templates/.rspec +2 -0
- data/lib/generators/gensearch/templates/app/controllers/Users/omniauth_callbacks_controller.rb +6 -0
- data/lib/generators/gensearch/templates/app/helpers/application_helper.rb +10 -0
- data/lib/generators/gensearch/templates/app/models/user.rb +12 -0
- data/lib/generators/gensearch/templates/application_controller_spec.rb +8 -0
- data/lib/generators/gensearch/templates/lib/string_calculator.rb +12 -0
- data/lib/generators/gensearch/templates/routes.rb +6 -0
- data/lib/generators/gensearch/templates/spec/controllers/welcomes_controller_spec.rb +86 -0
- data/lib/generators/gensearch/templates/spec/factories/users.rb +15 -0
- data/lib/generators/gensearch/templates/spec/factories/welcomes.rb +5 -0
- data/lib/generators/gensearch/templates/spec/helpers/welcomes_helper_spec.rb +23 -0
- data/lib/generators/gensearch/templates/spec/models/welcome_spec.rb +17 -0
- data/lib/generators/gensearch/templates/spec/rails_helper.rb +23 -0
- data/lib/generators/gensearch/templates/spec/requests/welcomes_spec.rb +16 -0
- data/lib/generators/gensearch/templates/spec/spec_helper.rb +96 -0
- data/lib/generators/gensearch/templates/spec/support/controller_helper.rb +12 -0
- data/lib/generators/gensearch/templates/spec/support/database_cleaner.rb +73 -0
- data/lib/generators/gensearch/templates/spec/support/devise.rb +8 -0
- data/lib/generators/gensearch/templates/spec/welcomes_controller_spec.rb +86 -0
- data/lib/gensearch.rb +6 -0
- data/lib/gensearch/helpers.rb +11 -0
- data/lib/gensearch/railtie.rb +18 -0
- data/lib/gensearch/version.rb +3 -0
- data/lib/tasks/gensearch.rake +28 -0
- metadata +258 -0
@@ -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
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :user do |f|
|
3
|
+
f.email Faker::Internet.free_email #=> "freddy@gmail.com"
|
4
|
+
f.password "secret"
|
5
|
+
end
|
6
|
+
|
7
|
+
factory :authorize_user, :class => :user do
|
8
|
+
# name "Tim Example"
|
9
|
+
email "a_user@example.com"
|
10
|
+
password '123456'
|
11
|
+
activated true
|
12
|
+
activated_at Time.zone.now
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
# Specs in this file have access to a helper object that includes
|
4
|
+
# the WelcomesHelper. For example:
|
5
|
+
#
|
6
|
+
# describe WelcomesHelper do
|
7
|
+
# describe "string concat" do
|
8
|
+
# it "concats two strings with spaces" do
|
9
|
+
# expect(helper.concat_strings("this","that")).to eq("this that")
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
RSpec.describe WelcomesHelper, type: :helper do
|
14
|
+
describe "title" do
|
15
|
+
it "display greeting" do
|
16
|
+
expect(helper.title).to eq "Greeting"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "title with parameter" do
|
20
|
+
expect(helper.title("Hola")).to eq "Hola | Greeting"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe Welcome, type: :model do
|
4
|
+
|
5
|
+
context "Created authorize_user using FactoryBot" do
|
6
|
+
before do
|
7
|
+
@user = FactoryBot.build(:authorize_user)
|
8
|
+
@user.save
|
9
|
+
end
|
10
|
+
|
11
|
+
it "Expected valid user created" do
|
12
|
+
expect(@user).to be_valid
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV['RAILS_ENV'] ||= 'test'
|
3
|
+
require File.expand_path('../../config/environment', __FILE__)
|
4
|
+
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
5
|
+
require 'rspec/rails'
|
6
|
+
require 'spec_helper'
|
7
|
+
require 'capybara/rspec'
|
8
|
+
require 'simplecov'
|
9
|
+
require 'factory_bot'
|
10
|
+
SimpleCov.start
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
14
|
+
config.infer_spec_type_from_file_location!
|
15
|
+
config.filter_rails_from_backtrace!
|
16
|
+
# Setup capybara
|
17
|
+
#config.include Warden::Test::Helpers #deplecated
|
18
|
+
config.include Capybara::DSL
|
19
|
+
# config.after :each do
|
20
|
+
# Warden.test_reset!
|
21
|
+
# end
|
22
|
+
# End Setup capybara
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe "Welcomes", type: :request do
|
4
|
+
describe "GET /welcomes" do
|
5
|
+
it "email fakeuser when requesting password reset" do
|
6
|
+
fakeuser = FactoryBot.create(:authorize_user)
|
7
|
+
puts fakeuser.email
|
8
|
+
visit new_user_session_path
|
9
|
+
click_link "Forgot your password?"
|
10
|
+
fill_in "Email", :with => fakeuser.email
|
11
|
+
click_button "reset password"
|
12
|
+
expect(page).to have_content("email with instructions")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
16
|
+
RSpec.configure do |config|
|
17
|
+
# rspec-expectations config goes here. You can use an alternate
|
18
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
19
|
+
# assertions if you prefer.
|
20
|
+
config.expect_with :rspec do |expectations|
|
21
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
22
|
+
# and `failure_message` of custom matchers include text for helper methods
|
23
|
+
# defined using `chain`, e.g.:
|
24
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
25
|
+
# # => "be bigger than 2 and smaller than 4"
|
26
|
+
# ...rather than:
|
27
|
+
# # => "be bigger than 2"
|
28
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
29
|
+
end
|
30
|
+
|
31
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
32
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
33
|
+
config.mock_with :rspec do |mocks|
|
34
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
35
|
+
# a real object. This is generally recommended, and will default to
|
36
|
+
# `true` in RSpec 4.
|
37
|
+
mocks.verify_partial_doubles = true
|
38
|
+
end
|
39
|
+
|
40
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
41
|
+
# have no way to turn it off -- the option exists only for backwards
|
42
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
43
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
44
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
45
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
46
|
+
|
47
|
+
# The settings below are suggested to provide a good initial experience
|
48
|
+
# with RSpec, but feel free to customize to your heart's content.
|
49
|
+
=begin
|
50
|
+
# This allows you to limit a spec run to individual examples or groups
|
51
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
52
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
53
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
54
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
55
|
+
config.filter_run_when_matching :focus
|
56
|
+
|
57
|
+
# Allows RSpec to persist some state between runs in order to support
|
58
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
59
|
+
# you configure your source control system to ignore this file.
|
60
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
61
|
+
|
62
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
63
|
+
# recommended. For more details, see:
|
64
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
65
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
66
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
67
|
+
config.disable_monkey_patching!
|
68
|
+
|
69
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
70
|
+
# file, and it's useful to allow more verbose output when running an
|
71
|
+
# individual spec file.
|
72
|
+
if config.files_to_run.one?
|
73
|
+
# Use the documentation formatter for detailed output,
|
74
|
+
# unless a formatter has already been configured
|
75
|
+
# (e.g. via a command-line flag).
|
76
|
+
config.default_formatter = "doc"
|
77
|
+
end
|
78
|
+
|
79
|
+
# Print the 10 slowest examples and example groups at the
|
80
|
+
# end of the spec run, to help surface which specs are running
|
81
|
+
# particularly slow.
|
82
|
+
config.profile_examples = 10
|
83
|
+
|
84
|
+
# Run specs in random order to surface order dependencies. If you find an
|
85
|
+
# order dependency and want to debug it, you can fix the order by providing
|
86
|
+
# the seed, which is printed after each run.
|
87
|
+
# --seed 1234
|
88
|
+
config.order = :random
|
89
|
+
|
90
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
91
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
92
|
+
# test failures related to randomization by passing the same `--seed` value
|
93
|
+
# as the one that triggered the failure.
|
94
|
+
Kernel.srand config.seed
|
95
|
+
=end
|
96
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#https://github.com/plataformatec/devise/wiki/How-To:-Stub-authentication-in-controller-specs
|
2
|
+
module ControllerHelpers
|
3
|
+
def sign_in(user = double('user'))
|
4
|
+
if user.nil?
|
5
|
+
allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, {:scope => :user})
|
6
|
+
allow(controller).to receive(:current_user).and_return(nil)
|
7
|
+
else
|
8
|
+
allow(request.env['warden']).to receive(:authenticate!).and_return(user)
|
9
|
+
allow(controller).to receive(:current_user).and_return(user)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Installing database_cleaner:
|
2
|
+
|
3
|
+
# 0. Check spec/support dir is auto-required in spec/rails_helper.rb.
|
4
|
+
#
|
5
|
+
# 1. Add database_cleaner to Gemfile:
|
6
|
+
#
|
7
|
+
# group :test do
|
8
|
+
# gem 'database_cleaner'
|
9
|
+
# end
|
10
|
+
|
11
|
+
# 2. IMPORTANT! Delete the "config.use_transactional_fixtures = ..." line
|
12
|
+
# in spec/rails_helper.rb (we're going to configure it in this file you're
|
13
|
+
# reading instead).
|
14
|
+
|
15
|
+
# 3. Create a file like this one you're reading in spec/support/database_cleaner.rb:
|
16
|
+
RSpec.configure do |config|
|
17
|
+
|
18
|
+
config.use_transactional_fixtures = false
|
19
|
+
|
20
|
+
config.before(:suite) do
|
21
|
+
if config.use_transactional_fixtures?
|
22
|
+
|
23
|
+
raise(<<-MSG)
|
24
|
+
Delete line `config.use_transactional_fixtures = true` from rails_helper.rb
|
25
|
+
(or set it to false) to prevent uncommitted transactions being used in
|
26
|
+
JavaScript-dependent specs.
|
27
|
+
During testing, the Ruby app server that the JavaScript browser driver
|
28
|
+
connects to uses a different database connection to the database connection
|
29
|
+
used by the spec.
|
30
|
+
|
31
|
+
This Ruby app server database connection would not be able to see data that
|
32
|
+
has been setup by the spec's database connection inside an uncommitted
|
33
|
+
transaction.
|
34
|
+
Disabling the use_transactional_fixtures setting helps avoid uncommitted
|
35
|
+
transactions in JavaScript-dependent specs, meaning that the Ruby app server
|
36
|
+
database connection can see any data set up by the specs.
|
37
|
+
MSG
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
config.before(:suite) do
|
43
|
+
DatabaseCleaner.clean_with(:truncation)
|
44
|
+
end
|
45
|
+
|
46
|
+
config.before(:each) do
|
47
|
+
DatabaseCleaner.strategy = :truncation
|
48
|
+
end
|
49
|
+
|
50
|
+
config.before(:each, type: :feature) do
|
51
|
+
# :rack_test driver's Rack app under test shares database connection
|
52
|
+
# with the specs, so we can use transaction strategy for speed.
|
53
|
+
driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test
|
54
|
+
|
55
|
+
if driver_shares_db_connection_with_specs
|
56
|
+
DatabaseCleaner.strategy = :truncation
|
57
|
+
else
|
58
|
+
# Non-:rack_test driver is probably a driver for a JavaScript browser
|
59
|
+
# with a Rack app under test that does *not* share a database
|
60
|
+
# connection with the specs, so we must use truncation strategy.
|
61
|
+
DatabaseCleaner.strategy = :truncation
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
config.before(:each) do
|
66
|
+
DatabaseCleaner.start
|
67
|
+
end
|
68
|
+
|
69
|
+
config.after(:each) do
|
70
|
+
DatabaseCleaner.clean
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
#include Devise::TestHelpers
|
2
|
+
#require 'support/controller_helpers'
|
3
|
+
RSpec.configure do |config|
|
4
|
+
# Setup TestHelper for Rails 5
|
5
|
+
config.include Devise::Test::ControllerHelpers, type: :controller
|
6
|
+
config.include Devise::Test::ControllerHelpers, type: :view
|
7
|
+
config.include Devise::Test::IntegrationHelpers, type: :feature
|
8
|
+
end
|