Skip to content

Commit

Permalink
KBP-175 #time 1h change application_responder setting mechanism and c…
Browse files Browse the repository at this point in the history
…ode refactor for project initialization
  • Loading branch information
İsmail Akbudak committed Jan 9, 2018
1 parent 64838a3 commit 5c3fbd3
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 23 deletions.
28 changes: 14 additions & 14 deletions lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AppGenerator < Rails::Generators::AppGenerator
aliases: nil,
default: false,
group: :cybele,
desc: 'Skip view files. Default: don\'t skip'
desc: 'Skip view files. Default: don\'t skip. Dependent: haml, show-for, simple-form'
class_option :skip_docker,
type: :boolean,
aliases: nil,
Expand Down Expand Up @@ -295,28 +295,28 @@ def get_builder_class
# :reek:TooManyStatements
def ask_questions(options)
say 'Ask cybele options', :green
option_with_ask_limited(:database, DATABASES)
option_with_ask_yes(:skip_create_database)
option_with_ask_yes(:skip_sidekiq)
option_with_ask_yes(:skip_simple_form)
option_with_ask_yes(:skip_show_for)
option_with_ask_yes(:skip_haml)
option_with_ask_yes(:skip_view_files)
option_with_ask_yes(:skip_docker)
option_with_ask_limited(options, :database, DATABASES)
option_with_ask_yes(options, :skip_create_database)
option_with_ask_yes(options, :skip_sidekiq)
option_with_ask_yes(options, :skip_simple_form)
option_with_ask_yes(options, :skip_show_for)
option_with_ask_yes(options, :skip_haml)
option_with_ask_yes(options, :skip_view_files)
option_with_ask_yes(options, :skip_docker)
options.freeze
dependency_control(options)
end

def option_with_ask_yes(key)
def option_with_ask_yes(options, key)
say "==> #{key.to_s.humanize}", :green
say 'Type for answer yes: y|yes', :green
say 'Type for answer no: n|no|any character', :yellow

@options = @options.merge(key => yes?('Ans :', :green))
options.merge!(key => yes?('Ans :', :green))
end

def option_with_ask_limited(key, limits)
@options = @options.merge(key => ask("#{key.to_s.humanize} :", limited_to: limits))
def option_with_ask_limited(options, key, limits)
options.merge!(key => ask("#{key.to_s.humanize} :", limited_to: limits))
end

def dependency_control(selected_options)
Expand All @@ -326,7 +326,6 @@ def dependency_control(selected_options)
# :reek:TooManyStatements
def arg_checker(selected_options, option, option_array)
return if selected_options[option]
puts "#{option} dependency error!"
failed = false
option_array.each do |opt|
if selected_options[opt]
Expand All @@ -335,6 +334,7 @@ def arg_checker(selected_options, option, option_array)
end
end
return unless failed
puts "#{option} dependency error!"
puts
puts 'See --help for more info'
exit 0
Expand Down
5 changes: 2 additions & 3 deletions lib/cybele/helpers/responders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ def replace_responders_file_contents
replace_in_file 'app/controllers/application_controller.rb',
'respond_to :html',
'respond_to :html, :js, :json'
comment_lines 'app/controllers/application_controller.rb',
/self.responder = ApplicationResponder/
replace_in_file 'app/controllers/application_controller.rb',
'require "application_responder"',
"require 'application_responder'"
replace_in_file 'app/controllers/application_controller.rb',
'self.responder = ApplicationResponder',
'self.responder = ApplicationResponder unless :devise_controller?'
# Remove comments in locale/responders.yml
remove_file 'config/locales/responders.en.yml', force: true
copy_file 'config/locales/responders.tr.yml', 'config/locales/responders.tr.yml'
Expand Down
1 change: 0 additions & 1 deletion spec/features/git_and_git_flow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

RSpec.describe 'Create new project without default configuration' do
before do
drop_dummy_database
remove_project_directory
run_cybele(cybele_not_default_parameters)
setup_app_dependencies
Expand Down
5 changes: 2 additions & 3 deletions spec/features/new_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

RSpec.describe 'Create new project with default configuration' do
before(:all) do
drop_dummy_database
remove_project_directory
run_cybele('--skip-create-database')
setup_app_dependencies
Expand Down Expand Up @@ -220,10 +219,10 @@

expect(File).not_to exist(file_project_path('app/assets/stylesheets/application.css'))

application_stylesheets_file = content('app/assets/stylesheets/application.css.sass')
application_stylesheets_file = content('app/assets/stylesheets/application.sass')
expect(application_stylesheets_file).to match('@import "bootstrap"')

hq_stylesheets_js_file = content('app/assets/stylesheets/hq/application.css.sass')
hq_stylesheets_js_file = content('app/assets/stylesheets/hq/application.sass')
expect(hq_stylesheets_js_file).to match('@import "bootstrap"')

application_js_file = content('app/assets/javascripts/application.js')
Expand Down
1 change: 0 additions & 1 deletion spec/features/new_not_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

RSpec.describe 'Create new project without default configuration' do
before(:all) do
drop_dummy_database
remove_project_directory
run_cybele(cybele_not_default_parameters)
setup_app_dependencies
Expand Down
2 changes: 1 addition & 1 deletion spec/support/responder_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def responder_test
def controller_file_test
controller_file = content('app/controllers/application_controller.rb')
expect(controller_file).to match("^require 'application_responder'")
expect(controller_file).to match('self.responder = ApplicationResponder')
expect(controller_file).to match('# self.responder = ApplicationResponder')
expect(controller_file).to match('respond_to :html, :js, :json')
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class Hq::ApplicationController < ApplicationController
before_action :set_audit_user
layout 'hq/application'
self.responder = ApplicationResponder

private

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class User::ApplicationController < ApplicationController
layout 'application'
before_action :authenticate_user!
before_action :set_user_time_zone
self.responder = ApplicationResponder

protected

Expand Down

0 comments on commit 5c3fbd3

Please sign in to comment.