From 25e340fc400a294232a8f340bd12de098bddacac Mon Sep 17 00:00:00 2001 From: Arnaud Doucerain Date: Thu, 20 Apr 2017 23:02:28 +0200 Subject: [PATCH] Adding i18n-tasks, Rubocop, FactoryGirl and Shoulda Matchers --- .rubocop.yml | 20 ++-- Gemfile | 12 +++ Gemfile.lock | 39 +++++++ Rakefile | 2 + app/channels/application_cable/channel.rb | 2 + app/channels/application_cable/connection.rb | 2 + app/controllers/application_controller.rb | 2 + app/controllers/companies_controller.rb | 6 +- app/controllers/home_controller.rb | 5 +- app/helpers/application_helper.rb | 2 + app/helpers/companies_helper.rb | 2 - app/jobs/application_job.rb | 2 + app/mailers/application_mailer.rb | 2 + app/models/application_record.rb | 2 + app/models/company.rb | 3 + app/views/companies/show.html.haml | 12 ++- app/views/home/index.html.haml | 6 +- app/views/layouts/_footer.html.haml | 4 + app/views/layouts/_navbar.html.haml | 8 +- app/views/layouts/application.html.haml | 9 +- bin/bundle | 2 + bin/rails | 2 + bin/rake | 2 + bin/setup | 2 + bin/spring | 1 + bin/update | 2 + config.ru | 2 + config/application.rb | 2 + config/boot.rb | 2 + config/database.yml | 8 +- config/environment.rb | 2 + config/environments/development.rb | 2 + config/environments/production.rb | 2 + config/environments/test.rb | 2 + config/i18n-tasks.yml | 101 ++++++++++++++++++ .../application_controller_renderer.rb | 1 + config/initializers/assets.rb | 2 + config/initializers/backtrace_silencers.rb | 1 + config/initializers/cookies_serializer.rb | 2 + .../initializers/filter_parameter_logging.rb | 2 + config/initializers/inflections.rb | 1 + config/initializers/mime_types.rb | 1 + config/initializers/new_framework_defaults.rb | 2 + config/initializers/session_store.rb | 2 + config/initializers/wrap_parameters.rb | 2 + config/locales/en.yml | 23 ---- config/locales/views/home.fr.yml | 4 +- config/puma.rb | 2 + config/routes.rb | 6 +- config/spring.rb | 2 + db/migrate/20170404124550_create_companies.rb | 2 + db/schema.rb | 2 - db/seeds.rb | 1 + spec/controllers/companies_controller_spec.rb | 16 +-- spec/controllers/home_controller_spec.rb | 8 +- spec/factories/companies.rb | 8 ++ spec/helpers/companies_helper_spec.rb | 15 --- spec/i18n_spec.rb | 19 ++++ spec/models/company_spec.rb | 6 +- spec/rails_helper.rb | 11 ++ spec/spec_helper.rb | 2 + spec/views/companies/index.html.haml_spec.rb | 10 +- spec/views/companies/show.html.haml_spec.rb | 15 ++- spec/views/home/index.html.haml_spec.rb | 10 +- 64 files changed, 356 insertions(+), 98 deletions(-) delete mode 100644 app/helpers/companies_helper.rb create mode 100644 app/views/layouts/_footer.html.haml create mode 100644 config/i18n-tasks.yml delete mode 100644 config/locales/en.yml create mode 100644 spec/factories/companies.rb delete mode 100644 spec/helpers/companies_helper_spec.rb create mode 100644 spec/i18n_spec.rb diff --git a/.rubocop.yml b/.rubocop.yml index 5115ccdd0e..8af4b90d11 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,18 +6,16 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 28 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https +require: rubocop-rspec + +AllCops: + TargetRubyVersion: 2.4 + Exclude: + - 'db/schema.rb' + - 'tmp/**/*' + Metrics/LineLength: Max: 120 -# Offense count: 4 Style/Documentation: - Exclude: - - 'spec/**/*' - - 'test/**/*' - - 'app/controllers/application_controller.rb' - - 'app/helpers/application_helper.rb' - - 'app/mailers/application_mailer.rb' - - 'app/models/application_record.rb' + Enabled: false \ No newline at end of file diff --git a/Gemfile b/Gemfile index 080bdfb127..657dfc535c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' git_source(:github) do |repo_name| @@ -5,6 +7,8 @@ git_source(:github) do |repo_name| "https://github.com/#{repo_name}.git" end +ruby '2.4.1' + gem 'coffee-rails', '~> 4.2' gem 'haml-rails', '~> 0.9' gem 'pg' @@ -23,6 +27,8 @@ gem 'turbolinks', '~> 5' gem 'semantic-ui-sass', '~> 2' +gem 'i18n-tasks', '~> 0.8.3' + # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 3.0' # Use ActiveModel has_secure_password @@ -31,9 +37,14 @@ gem 'semantic-ui-sass', '~> 2' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +group :test do + gem 'shoulda-matchers', '~> 3.1' +end + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri + gem 'factory_girl_rails' gem 'rspec-rails', '~> 3.5' end @@ -46,6 +57,7 @@ group :development do gem 'spring-watcher-listen', '~> 2.0.0' gem 'rubocop', require: false + gem 'rubocop-rspec', require: false end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem diff --git a/Gemfile.lock b/Gemfile.lock index 8ad89cb610..41421fbd38 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,8 +52,17 @@ GEM coffee-script-source (1.12.2) concurrent-ruby (1.0.5) diff-lcs (1.3) + easy_translate (0.5.0) + json + thread + thread_safe erubis (2.7.0) execjs (2.7.0) + factory_girl (4.8.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.8.0) + factory_girl (~> 4.8.0) + railties (>= 3.0.0) ffi (1.9.18) foreman (0.83.0) thor (~> 0.19.1) @@ -67,12 +76,21 @@ GEM haml (>= 4.0.6, < 5.0) html2haml (>= 1.0.1) railties (>= 4.0.1) + highline (1.7.8) html2haml (2.1.0) erubis (~> 2.7.0) haml (~> 4.0) nokogiri (>= 1.6.0) ruby_parser (~> 3.5) i18n (0.8.1) + i18n-tasks (0.8.7) + activesupport (>= 2.3.18) + easy_translate (>= 0.5.0) + erubis + highline (>= 1.7.3) + i18n + term-ansicolor (>= 1.3.2) + terminal-table (>= 1.5.1) jbuilder (2.6.3) activesupport (>= 3.0.0, < 5.2) multi_json (~> 1.2) @@ -80,6 +98,7 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + json (2.0.3) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -156,6 +175,8 @@ GEM rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) + rubocop-rspec (1.15.0) + rubocop (>= 0.42.0) ruby-progressbar (1.8.1) ruby_parser (3.8.4) sexp_processor (~> 4.1) @@ -169,6 +190,8 @@ GEM semantic-ui-sass (2.2.9.3) sass (>= 3.2) sexp_processor (4.8.0) + shoulda-matchers (3.1.1) + activesupport (>= 4.0.0) spring (2.0.1) activesupport (>= 4.2) spring-watcher-listen (2.0.1) @@ -181,9 +204,15 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + term-ansicolor (1.5.0) + tins (~> 1.0) + terminal-table (1.7.3) + unicode-display_width (~> 1.1.1) thor (0.19.4) + thread (0.2.2) thread_safe (0.3.6) tilt (2.0.7) + tins (1.13.2) turbolinks (5.0.1) turbolinks-source (~> 5) turbolinks-source (5.0.0) @@ -207,8 +236,13 @@ PLATFORMS DEPENDENCIES byebug coffee-rails (~> 4.2) +<<<<<<< HEAD foreman +======= + factory_girl_rails +>>>>>>> Adding i18n-tasks, Rubocop, FactoryGirl and Shoulda Matchers haml-rails (~> 0.9) + i18n-tasks (~> 0.8.3) jbuilder (~> 2.5) jquery-rails listen (~> 3.0.5) @@ -217,8 +251,10 @@ DEPENDENCIES rails (~> 5.0.2) rspec-rails (~> 3.5) rubocop + rubocop-rspec sass-rails (~> 5.0) semantic-ui-sass (~> 2) + shoulda-matchers (~> 3.1) spring spring-watcher-listen (~> 2.0.0) turbolinks (~> 5) @@ -226,5 +262,8 @@ DEPENDENCIES uglifier (>= 1.3.0) web-console (>= 3.3.0) +RUBY VERSION + ruby 2.4.1p111 + BUNDLED WITH 1.14.6 diff --git a/Rakefile b/Rakefile index e85f913914..488c551fee 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index d672697283..9aec230539 100644 --- a/app/channels/application_cable/channel.rb +++ b/app/channels/application_cable/channel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb index 0ff5442f47..8d6c2a1bf4 100644 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1c07694e9d..280cc28ce2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base protect_from_forgery with: :exception end diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb index 354889b942..7cf65976a6 100644 --- a/app/controllers/companies_controller.rb +++ b/app/controllers/companies_controller.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + class CompaniesController < ApplicationController - def index - end + def index; end def show + @company = Company.find params[:id] end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 95f29929ca..a0ac1f802f 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,4 +1,5 @@ +# frozen_string_literal: true + class HomeController < ApplicationController - def index - end + def index; end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be7945c..15b06f0f67 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/app/helpers/companies_helper.rb b/app/helpers/companies_helper.rb deleted file mode 100644 index 099b151b99..0000000000 --- a/app/helpers/companies_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module CompaniesHelper -end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index a009ace51c..d92ffddcb5 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b2239d1..d84cb6e71e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba84d..71fbba5b32 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end diff --git a/app/models/company.rb b/app/models/company.rb index a149860a31..8899e4652d 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -1,2 +1,5 @@ +# frozen_string_literal: true + class Company < ApplicationRecord + validates :name, presence: true end diff --git a/app/views/companies/show.html.haml b/app/views/companies/show.html.haml index 511774e1fb..c0e5535013 100644 --- a/app/views/companies/show.html.haml +++ b/app/views/companies/show.html.haml @@ -1,2 +1,10 @@ -%h1 Companies#show -%p Find me in app/views/companies/show.html.haml +%h1= @company.name +%table + %thead + %tr + %th + %th + %tbody + %tr + %td= 'Siren' + %td= @company.siren \ No newline at end of file diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index ad0d896ddb..21f75ef3e3 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -1,5 +1,3 @@ .ui.main.text.container - %h1 - = t('.welcome_title') - %p - = t('.welcome_message') \ No newline at end of file + %h1= t('.welcome_title') + %p= t('.welcome_message') \ No newline at end of file diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml new file mode 100644 index 0000000000..f1c4b01694 --- /dev/null +++ b/app/views/layouts/_footer.html.haml @@ -0,0 +1,4 @@ +%footer.ui.bottom.fixed.menu + .ui.container + .item + = 'Footer with information.' \ No newline at end of file diff --git a/app/views/layouts/_navbar.html.haml b/app/views/layouts/_navbar.html.haml index c17f3c2139..6be301ccfc 100644 --- a/app/views/layouts/_navbar.html.haml +++ b/app/views/layouts/_navbar.html.haml @@ -1,6 +1,10 @@ %header.ui.top.fixed.menu .ui.container .header.item - = link_to semantic_icon('home') + t('.home') , root_path + = link_to root_path do + = semantic_icon('home') + = t('.home') .header.item - = link_to semantic_icon('building outline') + t('.search') , companies_path \ No newline at end of file + = link_to companies_path do + = semantic_icon('building outline') + = t('.search') \ No newline at end of file diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index af5e8b00fa..5e6bdf67cc 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -1,15 +1,12 @@ !!! %html %head - %title EConseils + %title= 'EConseils' = csrf_meta_tags - = stylesheet_link_tag 'application', media: 'all', data: {turbolinks_track: 'reload'} + = stylesheet_link_tag 'application', media: 'all', data: {turbolinks_track: 'reload'} = javascript_include_tag 'application', data: {turbolinks_track: 'reload'} %body = render 'layouts/navbar' .main.container = yield - %footer.ui.bottom.fixed.menu - .ui.container - .item - Footer with information. + = render 'layouts/footer' \ No newline at end of file diff --git a/bin/bundle b/bin/bundle index 66e9889e8b..58115ecf30 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,3 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails index 5badb2fde0..a36553922a 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + begin load File.expand_path('../spring', __FILE__) rescue LoadError => e diff --git a/bin/rake b/bin/rake index d87d5f5781..169c939614 100755 --- a/bin/rake +++ b/bin/rake @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + begin load File.expand_path('../spring', __FILE__) rescue LoadError => e diff --git a/bin/setup b/bin/setup index e620b4dadb..629e3584a2 100755 --- a/bin/setup +++ b/bin/setup @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'pathname' require 'fileutils' include FileUtils diff --git a/bin/spring b/bin/spring index 991bd4ef95..9bd27ec6ce 100755 --- a/bin/spring +++ b/bin/spring @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true # This file loads spring without using Bundler, in order to be fast. # It gets overwritten when you run the `spring binstub` command. diff --git a/bin/update b/bin/update index a8e4462f20..fdac831bbb 100755 --- a/bin/update +++ b/bin/update @@ -1,4 +1,6 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'pathname' require 'fileutils' include FileUtils diff --git a/config.ru b/config.ru index f7ba0b527b..842bccc340 100644 --- a/config.ru +++ b/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require_relative 'config/environment' diff --git a/config/application.rb b/config/application.rb index 7fbb5b4bf9..604045e0ed 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative 'boot' require 'rails/all' diff --git a/config/boot.rb b/config/boot.rb index 30f5120df6..30e594e23c 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/database.yml b/config/database.yml index b63094970b..b78a5a7c19 100644 --- a/config/database.yml +++ b/config/database.yml @@ -8,15 +8,15 @@ development: <<: *default database: econseils-development host: localhost - username: antoineboileau - password: + username: postgres + password: postgres test: <<: *default database: econseils-test host: localhost - username: antoineboileau - password: + username: postgres + password: postgres production: <<: *default diff --git a/config/environment.rb b/config/environment.rb index 426333bb46..d5abe55806 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Load the Rails application. require_relative 'application' diff --git a/config/environments/development.rb b/config/environments/development.rb index 6f7197045a..40dadfae2d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/config/environments/production.rb b/config/environments/production.rb index 8b154b59ae..f991cd72f5 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/config/environments/test.rb b/config/environments/test.rb index 30587ef6d5..5344748cf4 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml new file mode 100644 index 0000000000..c03695b54e --- /dev/null +++ b/config/i18n-tasks.yml @@ -0,0 +1,101 @@ +# i18n-tasks finds and manages missing and unused translations: https://github.com/glebm/i18n-tasks + +# The "main" locale. +base_locale: fr +## All available locales are inferred from the data by default. Alternatively, specify them explicitly: +# locales: [es, fr] +## Reporting locale, default: en. Available: en, ru. +# internal_locale: en + +# Read and write translations. +data: + ## Translations are read from the file system. Supported format: YAML, JSON. + ## Provide a custom adapter: + # adapter: I18n::Tasks::Data::FileSystem + + # Locale files or `File.find` patterns where translations are read from: + read: + - config/locales/%{locale}.yml + - config/locales/**/*.%{locale}.yml + ## Another gem (replace %#= with %=): + # - "<%#= %x[bundle show vagrant].chomp %>/templates/locales/%{locale}.yml" + + # Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom: + # `i18n-tasks normalize -p` will force move the keys according to these rules + write: + ## For example, write devise and simple form keys to their respective files: + # - ['{devise, simple_form}.*', 'config/locales/\1.%{locale}.yml'] + ## Catch-all default: + # - config/locales/%{locale}.yml + + ## Specify the router (see Readme for details). Valid values: conservative_router, pattern_router, or a custom class. + # router: convervative_router + + yaml: + write: + # do not wrap lines at 80 characters + line_width: -1 + + ## Pretty-print JSON: + # json: + # write: + # indent: ' ' + # space: ' ' + # object_nl: "\n" + # array_nl: "\n" + +# Find translate calls +search: + ## Paths or `File.find` patterns to search in: + # paths: + # - app/ + + ## Root directories for relative keys resolution. + # relative_roots: + # - app/controllers + # - app/helpers + # - app/mailers + # - app/presenters + # - app/views + + ## Files or `File.fnmatch` patterns to exclude from search. Some files are always excluded regardless of this setting: + ## %w(*.jpg *.png *.gif *.svg *.ico *.eot *.otf *.ttf *.woff *.woff2 *.pdf *.css *.sass *.scss *.less *.yml *.json) + exclude: + - app/assets/images + - app/assets/fonts + + ## Alternatively, the only files or `File.fnmatch patterns` to search in `paths`: + ## If specified, this settings takes priority over `exclude`, but `exclude` still applies. + # include: ["*.rb", "*.html.slim"] + + ## Default scanner finds t() and I18n.t() calls. + # scanner: I18n::Tasks::Scanners::PatternWithScopeScanner + +## Google Translate +# translation: +# # Get an API key and set billing info at https://code.google.com/apis/console to use Google Translate +# api_key: "AbC-dEf5" + +## Do not consider these keys missing: +# ignore_missing: +# - 'errors.messages.{accepted,blank,invalid,too_short,too_long}' +# - '{devise,simple_form}.*' + +## Consider these keys used: +# ignore_unused: +# - 'activerecord.attributes.*' +# - '{devise,kaminari,will_paginate}.*' +# - 'simple_form.{yes,no}' +# - 'simple_form.{placeholders,hints,labels}.*' +# - 'simple_form.{error_notification,required}.:' + +## Exclude these keys from the `i18n-tasks eq-base' report: +# ignore_eq_base: +# all: +# - common.ok +# fr,es: +# - common.brand + +## Ignore these keys completely: +# ignore: +# - kaminari.* diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 51639b67a0..315ac48a9a 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # ApplicationController.renderer.defaults.merge!( diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 01ef3e6630..678efe9fa3 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 59385cdf37..d0f0d3b5df 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 5a6a32d371..ee8dff9c99 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Specify a serializer for the signed and encrypted cookie jars. diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 4a994e1e7b..7a4f47b4c2 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ac033bf9dc..aa7435fbc9 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index dc1899682b..6e1d16f027 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb index 671abb69a3..050fcec38a 100644 --- a/config/initializers/new_framework_defaults.rb +++ b/config/initializers/new_framework_defaults.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # # This file contains migration options to ease your Rails 5.0 upgrade. diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index b832cfb92e..22dc7eb9aa 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. Rails.application.config.session_store :cookie_store, key: '_EConseils_session' diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index bbfc3961bf..2f3c0db471 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which diff --git a/config/locales/en.yml b/config/locales/en.yml deleted file mode 100644 index 0653957166..0000000000 --- a/config/locales/en.yml +++ /dev/null @@ -1,23 +0,0 @@ -# Files in the config/locales directory are used for internationalization -# and are automatically loaded by Rails. If you want to use locales other -# than English, add the necessary files in this directory. -# -# To use the locales, use `I18n.t`: -# -# I18n.t 'hello' -# -# In views, this is aliased to just `t`: -# -# <%= t('hello') %> -# -# To use a different locale, set it with `I18n.locale`: -# -# I18n.locale = :es -# -# This would use the information in config/locales/es.yml. -# -# To learn more, please read the Rails Internationalization guide -# available at http://guides.rubyonrails.org/i18n.html. - -en: - hello: "Hello world" diff --git a/config/locales/views/home.fr.yml b/config/locales/views/home.fr.yml index 2fd7140cb1..84be98d226 100644 --- a/config/locales/views/home.fr.yml +++ b/config/locales/views/home.fr.yml @@ -1,5 +1,5 @@ fr: home: index: - welcome_title: Bienvenu sur la plateforme e-conseils - welcome_message: Bienvenu sur la plateforme e-conseils \ No newline at end of file + welcome_title: Bienvenue sur la plateforme e-conseils + welcome_message: Vous trouverez ici tous les conseils que vous n'avez pas pu avoir avant. \ No newline at end of file diff --git a/config/puma.rb b/config/puma.rb index 786af492e4..03a2824370 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers a minimum and maximum. # Any libraries that use thread pools should be configured to match diff --git a/config/routes.rb b/config/routes.rb index 58df765761..1037513e4a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,9 @@ -Rails.application.routes.draw do +# frozen_string_literal: true +Rails.application.routes.draw do root to: 'home#index' - resources :companies, only: [:index, :show] - + resources :companies, only: %i[index show] # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/config/spring.rb b/config/spring.rb index 9fa7863f99..c5933e491b 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + %w[ .ruby-version .rbenv-vars diff --git a/db/migrate/20170404124550_create_companies.rb b/db/migrate/20170404124550_create_companies.rb index 0ab4953fcc..52bf3695d3 100644 --- a/db/migrate/20170404124550_create_companies.rb +++ b/db/migrate/20170404124550_create_companies.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateCompanies < ActiveRecord::Migration[5.0] def change create_table :companies do |t| diff --git a/db/schema.rb b/db/schema.rb index bd93df8e4c..61bf0bec52 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,6 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 20170404124550) do - # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -21,5 +20,4 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false end - end diff --git a/db/seeds.rb b/db/seeds.rb index 1beea2accd..8744e3c59b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). # diff --git a/spec/controllers/companies_controller_spec.rb b/spec/controllers/companies_controller_spec.rb index beb10d35d4..6674006417 100644 --- a/spec/controllers/companies_controller_spec.rb +++ b/spec/controllers/companies_controller_spec.rb @@ -1,19 +1,21 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe CompaniesController, type: :controller do - - describe "GET #index" do - it "returns http success" do + describe 'GET #index' do + it 'returns http success' do get :index expect(response).to have_http_status(:success) end end - describe "GET #show" do - it "returns http success" do - get :show + describe 'GET #show' do + let(:company) { create :company } + + it 'returns http success' do + get :show, params: { id: company.id } expect(response).to have_http_status(:success) end end - end diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 6fd68742e5..5691521531 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -1,12 +1,12 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe HomeController, type: :controller do - - describe "GET #index" do - it "returns http success" do + describe 'GET #index' do + it 'returns http success' do get :index expect(response).to have_http_status(:success) end end - end diff --git a/spec/factories/companies.rb b/spec/factories/companies.rb new file mode 100644 index 0000000000..008700bb88 --- /dev/null +++ b/spec/factories/companies.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryGirl.define do + factory :company do + sequence(:name) { |i| "company#{i}" } + sequence(:siren) { rand(100_000_000..999_999_999).to_s } + end +end diff --git a/spec/helpers/companies_helper_spec.rb b/spec/helpers/companies_helper_spec.rb deleted file mode 100644 index ce86131a50..0000000000 --- a/spec/helpers/companies_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the CompaniesHelper. For example: -# -# describe CompaniesHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe CompaniesHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb new file mode 100644 index 0000000000..41719861c2 --- /dev/null +++ b/spec/i18n_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'i18n/tasks' + +RSpec.describe I18n do + let(:i18n) { I18n::Tasks::BaseTask.new } + let(:missing_keys) { i18n.missing_keys } + let(:unused_keys) { i18n.unused_keys } + + it 'does not have missing keys' do + expect(missing_keys).to be_empty, + "Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them" + end + + it 'does not have unused keys' do + expect(unused_keys).to be_empty, + "#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused' to show them" + end +end diff --git a/spec/models/company_spec.rb b/spec/models/company_spec.rb index 23c199c6c5..28178ae487 100644 --- a/spec/models/company_spec.rb +++ b/spec/models/company_spec.rb @@ -1,5 +1,9 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Company, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + describe 'validations' do + it { is_expected.to validate_presence_of :name } + end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 0c2dfd6389..283010a193 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is copied to spec/ when you run 'rails generate rspec:install' ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) @@ -35,6 +37,8 @@ # instead of true. config.use_transactional_fixtures = true + config.include FactoryGirl::Syntax::Methods + # RSpec Rails can automatically mix in different behaviours to your tests # based on their file location, for example enabling you to call `get` and # `post` in specs under `spec/controllers`. @@ -55,3 +59,10 @@ # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") end + +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ef76a6225a..3d7df43a8b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by the `rails generate rspec:install` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause diff --git a/spec/views/companies/index.html.haml_spec.rb b/spec/views/companies/index.html.haml_spec.rb index a378df2de7..df12991028 100644 --- a/spec/views/companies/index.html.haml_spec.rb +++ b/spec/views/companies/index.html.haml_spec.rb @@ -1,5 +1,11 @@ +# frozen_string_literal: true + require 'rails_helper' -RSpec.describe "companies/index.html.haml", type: :view do - pending "add some examples to (or delete) #{__FILE__}" +RSpec.describe 'companies/index.html.haml', type: :view do + it 'displays a title' do + render + + expect(rendered).to match(/Companies#index/) + end end diff --git a/spec/views/companies/show.html.haml_spec.rb b/spec/views/companies/show.html.haml_spec.rb index 31b8283c9e..6000cbad64 100644 --- a/spec/views/companies/show.html.haml_spec.rb +++ b/spec/views/companies/show.html.haml_spec.rb @@ -1,5 +1,16 @@ +# frozen_string_literal: true + require 'rails_helper' -RSpec.describe "companies/show.html.haml", type: :view do - pending "add some examples to (or delete) #{__FILE__}" +RSpec.describe 'companies/show.html.haml', type: :view do + let(:company) { create :company } + + before { assign :company, company } + + it 'does not render a list of weekly_must_read_emails' do + render + assert_select 'h1', text: company.name, count: 1 + assert_select 'tr>td', text: 'Siren', count: 1 + assert_select 'tr>td', text: company.siren, count: 1 + end end diff --git a/spec/views/home/index.html.haml_spec.rb b/spec/views/home/index.html.haml_spec.rb index 675335616b..9661a2d26c 100644 --- a/spec/views/home/index.html.haml_spec.rb +++ b/spec/views/home/index.html.haml_spec.rb @@ -1,5 +1,11 @@ +# frozen_string_literal: true + require 'rails_helper' -RSpec.describe "home/index.html.haml", type: :view do - pending "add some examples to (or delete) #{__FILE__}" +RSpec.describe 'home/index.html.haml', type: :view do + it 'displays a title' do + render + + expect(rendered).to match(/Bienvenue sur la plateforme/) + end end