From 78e86f00ea3b7eea140bee3ad54a47fe3a03fc56 Mon Sep 17 00:00:00 2001 From: Tanguy PATTE Date: Wed, 23 Sep 2015 10:02:01 +0200 Subject: [PATCH 1/7] [#884] add user --- Gemfile | 2 + Gemfile.lock | 3 + app/assets/stylesheets/application.scss | 1 + app/controllers/start_controller.rb | 1 + .../users/confirmations_controller.rb | 28 +++++ .../users/omniauth_callbacks_controller.rb | 28 +++++ app/controllers/users/passwords_controller.rb | 32 +++++ .../users/registrations_controller.rb | 60 +++++++++ app/controllers/users/sessions_controller.rb | 25 ++++ app/controllers/users/unlocks_controller.rb | 28 +++++ app/controllers/welcome_controller.rb | 6 + app/models/user.rb | 6 + app/views/dossiers/show.html.haml | 2 +- app/views/layouts/application.html.haml | 5 + app/views/users/confirmations/new.html.erb | 16 +++ .../mailer/confirmation_instructions.html.erb | 5 + .../reset_password_instructions.html.erb | 8 ++ .../users/mailer/unlock_instructions.html.erb | 7 ++ app/views/users/passwords/edit.html.erb | 22 ++++ app/views/users/passwords/new.html.erb | 16 +++ app/views/users/registrations/edit.html.erb | 39 ++++++ app/views/users/registrations/new.html.erb | 29 +++++ app/views/users/sessions/new.html.haml | 19 +++ app/views/users/shared/_links.html.erb | 25 ++++ app/views/users/unlocks/new.html.erb | 16 +++ app/views/welcome/index.html.haml | 2 + config/routes.rb | 9 +- db/migrate/20150922141232_create_users.rb | 42 +++++++ db/schema.rb | 22 +++- spec/controllers/start_controller_spec.rb | 117 +++++++++--------- spec/factories/user.rb | 7 ++ spec/features/users/start_demande_spec.rb | 39 ++++++ spec/models/user_spec.rb | 18 +++ 33 files changed, 624 insertions(+), 61 deletions(-) create mode 100644 app/controllers/users/confirmations_controller.rb create mode 100644 app/controllers/users/omniauth_callbacks_controller.rb create mode 100644 app/controllers/users/passwords_controller.rb create mode 100644 app/controllers/users/registrations_controller.rb create mode 100644 app/controllers/users/sessions_controller.rb create mode 100644 app/controllers/users/unlocks_controller.rb create mode 100644 app/controllers/welcome_controller.rb create mode 100644 app/models/user.rb create mode 100644 app/views/users/confirmations/new.html.erb create mode 100644 app/views/users/mailer/confirmation_instructions.html.erb create mode 100644 app/views/users/mailer/reset_password_instructions.html.erb create mode 100644 app/views/users/mailer/unlock_instructions.html.erb create mode 100644 app/views/users/passwords/edit.html.erb create mode 100644 app/views/users/passwords/new.html.erb create mode 100644 app/views/users/registrations/edit.html.erb create mode 100644 app/views/users/registrations/new.html.erb create mode 100644 app/views/users/sessions/new.html.haml create mode 100644 app/views/users/shared/_links.html.erb create mode 100644 app/views/users/unlocks/new.html.erb create mode 100644 app/views/welcome/index.html.haml create mode 100644 db/migrate/20150922141232_create_users.rb create mode 100644 spec/factories/user.rb create mode 100644 spec/features/users/start_demande_spec.rb create mode 100644 spec/models/user_spec.rb diff --git a/Gemfile b/Gemfile index 7fe3f3a66..47c9b9fac 100644 --- a/Gemfile +++ b/Gemfile @@ -59,6 +59,8 @@ gem 'chartkick' gem 'logstasher' +gem "font-awesome-rails" + group :test do gem 'capybara' gem 'factory_girl' diff --git a/Gemfile.lock b/Gemfile.lock index 6db37841d..c456bc24f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -114,6 +114,8 @@ GEM faraday (0.9.1) multipart-post (>= 1.2, < 3) ffi (1.9.6) + font-awesome-rails (4.4.0.0) + railties (>= 3.2, < 5.0) globalid (0.3.5) activesupport (>= 4.1.0) haml (4.0.6) @@ -339,6 +341,7 @@ DEPENDENCIES devise draper factory_girl + font-awesome-rails haml-rails jbuilder (~> 2.0) jquery-rails diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 5df9fdb80..b32a03b94 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -16,6 +16,7 @@ *= require_self *= require bootstrap-datepicker3 *= require leaflet + *= require font-awesome */ @import "bootstrap-sprockets"; @import "bootstrap"; diff --git a/app/controllers/start_controller.rb b/app/controllers/start_controller.rb index 87cbd34fa..51eb5a053 100644 --- a/app/controllers/start_controller.rb +++ b/app/controllers/start_controller.rb @@ -1,4 +1,5 @@ class StartController < ApplicationController + before_action :authenticate_user! def index get_procedure_infos diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb new file mode 100644 index 000000000..1126e23aa --- /dev/null +++ b/app/controllers/users/confirmations_controller.rb @@ -0,0 +1,28 @@ +class Users::ConfirmationsController < Devise::ConfirmationsController + # GET /resource/confirmation/new + # def new + # super + # end + + # POST /resource/confirmation + # def create + # super + # end + + # GET /resource/confirmation?confirmation_token=abcdef + # def show + # super + # end + + # protected + + # The path used after resending confirmation instructions. + # def after_resending_confirmation_instructions_path_for(resource_name) + # super(resource_name) + # end + + # The path used after confirmation. + # def after_confirmation_path_for(resource_name, resource) + # super(resource_name, resource) + # end +end diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb new file mode 100644 index 000000000..6e98c15d1 --- /dev/null +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -0,0 +1,28 @@ +class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController + # You should configure your model like this: + # devise :omniauthable, omniauth_providers: [:twitter] + + # You should also create an action method in this controller like this: + # def twitter + # end + + # More info at: + # https://github.com/plataformatec/devise#omniauth + + # GET|POST /resource/auth/twitter + # def passthru + # super + # end + + # GET|POST /users/auth/twitter/callback + # def failure + # super + # end + + # protected + + # The path used when omniauth fails + # def after_omniauth_failure_path_for(scope) + # super(scope) + # end +end diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb new file mode 100644 index 000000000..53cc34e39 --- /dev/null +++ b/app/controllers/users/passwords_controller.rb @@ -0,0 +1,32 @@ +class Users::PasswordsController < Devise::PasswordsController + # GET /resource/password/new + # def new + # super + # end + + # POST /resource/password + # def create + # super + # end + + # GET /resource/password/edit?reset_password_token=abcdef + # def edit + # super + # end + + # PUT /resource/password + # def update + # super + # end + + # protected + + # def after_resetting_password_path_for(resource) + # super(resource) + # end + + # The path used after sending reset password instructions + # def after_sending_reset_password_instructions_path_for(resource_name) + # super(resource_name) + # end +end diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb new file mode 100644 index 000000000..41c3a9002 --- /dev/null +++ b/app/controllers/users/registrations_controller.rb @@ -0,0 +1,60 @@ +class Users::RegistrationsController < Devise::RegistrationsController +# before_filter :configure_sign_up_params, only: [:create] +# before_filter :configure_account_update_params, only: [:update] + + # GET /resource/sign_up + # def new + # super + # end + + # POST /resource + # def create + # super + # end + + # GET /resource/edit + # def edit + # super + # end + + # PUT /resource + # def update + # super + # end + + # DELETE /resource + # def destroy + # super + # end + + # GET /resource/cancel + # Forces the session data which is usually expired after sign + # in to be expired now. This is useful if the user wants to + # cancel oauth signing in/up in the middle of the process, + # removing all OAuth session data. + # def cancel + # super + # end + + # protected + + # You can put the params you want to permit in the empty array. + # def configure_sign_up_params + # devise_parameter_sanitizer.for(:sign_up) << :attribute + # end + + # You can put the params you want to permit in the empty array. + # def configure_account_update_params + # devise_parameter_sanitizer.for(:account_update) << :attribute + # end + + # The path used after sign up. + # def after_sign_up_path_for(resource) + # super(resource) + # end + + # The path used after sign up for inactive accounts. + # def after_inactive_sign_up_path_for(resource) + # super(resource) + # end +end diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb new file mode 100644 index 000000000..45bf9e8e2 --- /dev/null +++ b/app/controllers/users/sessions_controller.rb @@ -0,0 +1,25 @@ +class Users::SessionsController < Devise::SessionsController +# before_filter :configure_sign_in_params, only: [:create] + + # GET /resource/sign_in + # def new + # super + # end + + # POST /resource/sign_in + # def create + # super + # end + + # DELETE /resource/sign_out + # def destroy + # super + # end + + # protected + + # You can put the params you want to permit in the empty array. + # def configure_sign_in_params + # devise_parameter_sanitizer.for(:sign_in) << :attribute + # end +end diff --git a/app/controllers/users/unlocks_controller.rb b/app/controllers/users/unlocks_controller.rb new file mode 100644 index 000000000..8b9ef8612 --- /dev/null +++ b/app/controllers/users/unlocks_controller.rb @@ -0,0 +1,28 @@ +class Users::UnlocksController < Devise::UnlocksController + # GET /resource/unlock/new + # def new + # super + # end + + # POST /resource/unlock + # def create + # super + # end + + # GET /resource/unlock?unlock_token=abcdef + # def show + # super + # end + + # protected + + # The path used after sending unlock password instructions + # def after_sending_unlock_instructions_path_for(resource) + # super(resource) + # end + + # The path used after unlocking the resource + # def after_unlock_path_for(resource) + # super(resource) + # end +end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb new file mode 100644 index 000000000..0a135b18b --- /dev/null +++ b/app/controllers/welcome_controller.rb @@ -0,0 +1,6 @@ +class WelcomeController < ApplicationController + before_action :authenticate_user! + def index + + end +end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 000000000..c8220270d --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,6 @@ +class User < ActiveRecord::Base + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable +end diff --git a/app/views/dossiers/show.html.haml b/app/views/dossiers/show.html.haml index 166913fbc..42262739c 100644 --- a/app/views/dossiers/show.html.haml +++ b/app/views/dossiers/show.html.haml @@ -1,4 +1,4 @@ -.container +.container#recap_info_entreprise %h2 Récapitulatif de vos informations (récupérées auprès de l'INSEE et d'INFOGREFFE) %br diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 445c8b63a..f9048fa5a 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -17,6 +17,11 @@ %div{style: 'decorate:none; box-shadow:none; float:right; margin-top:8px'} = current_gestionnaire.email = link_to "Déconnexion", '/gestionnaires/sign_out', method: :delete, :class => 'btn btn-md' + - elsif user_signed_in? + %div.user{style: 'decorate:none; box-shadow:none; float:right; margin-top:8px'} + %i.fa.fa-user + = current_user.email + = link_to "Déconnexion", '/users/sign_out', method: :delete, :class => 'btn btn-md' #flash_message.center - if flash.notice diff --git a/app/views/users/confirmations/new.html.erb b/app/views/users/confirmations/new.html.erb new file mode 100644 index 000000000..3df9635f9 --- /dev/null +++ b/app/views/users/confirmations/new.html.erb @@ -0,0 +1,16 @@ +

Resend confirmation instructions

+ +<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %> +
+ +
+ <%= f.submit "Resend confirmation instructions" %> +
+<% end %> + +<%= render "users/shared/links" %> diff --git a/app/views/users/mailer/confirmation_instructions.html.erb b/app/views/users/mailer/confirmation_instructions.html.erb new file mode 100644 index 000000000..dc55f64f6 --- /dev/null +++ b/app/views/users/mailer/confirmation_instructions.html.erb @@ -0,0 +1,5 @@ +

Welcome <%= @email %>!

+ +

You can confirm your account email through the link below:

+ +

<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>

diff --git a/app/views/users/mailer/reset_password_instructions.html.erb b/app/views/users/mailer/reset_password_instructions.html.erb new file mode 100644 index 000000000..f667dc12f --- /dev/null +++ b/app/views/users/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +

Hello <%= @resource.email %>!

+ +

Someone has requested a link to change your password. You can do this through the link below.

+ +

<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>

+ +

If you didn't request this, please ignore this email.

+

Your password won't change until you access the link above and create a new one.

diff --git a/app/views/users/mailer/unlock_instructions.html.erb b/app/views/users/mailer/unlock_instructions.html.erb new file mode 100644 index 000000000..41e148bf2 --- /dev/null +++ b/app/views/users/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +

Hello <%= @resource.email %>!

+ +

Your account has been locked due to an excessive number of unsuccessful sign in attempts.

+ +

Click the link below to unlock your account:

+ +

<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>

diff --git a/app/views/users/passwords/edit.html.erb b/app/views/users/passwords/edit.html.erb new file mode 100644 index 000000000..94404bdb2 --- /dev/null +++ b/app/views/users/passwords/edit.html.erb @@ -0,0 +1,22 @@ +

Change your password

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %> + <%= devise_error_messages! %> + <%= f.hidden_field :reset_password_token %> + +
+ <%= f.label :password, "New password" %>
+ <%= f.password_field :password, autofocus: true, autocomplete: "off" %> +
+ +
+ <%= f.label :password_confirmation, "Confirm new password" %>
+ <%= f.password_field :password_confirmation, autocomplete: "off" %> +
+ +
+ <%= f.submit "Change my password" %> +
+<% end %> + +<%= render "users/shared/links" %> diff --git a/app/views/users/passwords/new.html.erb b/app/views/users/passwords/new.html.erb new file mode 100644 index 000000000..808f4cbc8 --- /dev/null +++ b/app/views/users/passwords/new.html.erb @@ -0,0 +1,16 @@ +

Forgot your password?

+ +<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %> +
+ +
+ <%= f.submit "Send me reset password instructions" %> +
+<% end %> + +<%= render "users/shared/links" %> diff --git a/app/views/users/registrations/edit.html.erb b/app/views/users/registrations/edit.html.erb new file mode 100644 index 000000000..3ea40f014 --- /dev/null +++ b/app/views/users/registrations/edit.html.erb @@ -0,0 +1,39 @@ +

Edit <%= resource_name.to_s.humanize %>

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %> + <%= devise_error_messages! %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %> +
+ + <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> +
Currently waiting confirmation for: <%= resource.unconfirmed_email %>
+ <% end %> + +
+ <%= f.label :password %> (leave blank if you don't want to change it)
+ <%= f.password_field :password, autocomplete: "off" %> +
+ +
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "off" %> +
+ +
+ <%= f.label :current_password %> (we need your current password to confirm your changes)
+ <%= f.password_field :current_password, autocomplete: "off" %> +
+ +
+ <%= f.submit "Update" %> +
+<% end %> + +

Cancel my account

+ +

Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

+ +<%= link_to "Back", :back %> diff --git a/app/views/users/registrations/new.html.erb b/app/views/users/registrations/new.html.erb new file mode 100644 index 000000000..f9bbd8abd --- /dev/null +++ b/app/views/users/registrations/new.html.erb @@ -0,0 +1,29 @@ +

Sign up

+ +<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> + <%= devise_error_messages! %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %> +
+ +
+ <%= f.label :password %> + <% if @validatable %> + (<%= @minimum_password_length %> characters minimum) + <% end %>
+ <%= f.password_field :password, autocomplete: "off" %> +
+ +
+ <%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, autocomplete: "off" %> +
+ +
+ <%= f.submit "Sign up" %> +
+<% end %> + +<%= render "users/shared/links" %> diff --git a/app/views/users/sessions/new.html.haml b/app/views/users/sessions/new.html.haml new file mode 100644 index 000000000..9abc9ef8f --- /dev/null +++ b/app/views/users/sessions/new.html.haml @@ -0,0 +1,19 @@ +%h2#login_user Connexion += form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| + .field + = f.label :email + %br + = f.email_field :email, autofocus: true + .field + = f.label :password + %br + = f.password_field :password, autocomplete: "off" + %br + / - if devise_mapping.rememberable? + / .field + / = f.check_box :remember_me + / = f.label :remember_me + .actions + = f.submit "Se connecter" + += render "users/shared/links" diff --git a/app/views/users/shared/_links.html.erb b/app/views/users/shared/_links.html.erb new file mode 100644 index 000000000..cd795adb6 --- /dev/null +++ b/app/views/users/shared/_links.html.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Log in", new_session_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.registerable? && controller_name != 'registrations' %> + <%= link_to "Sign up", new_registration_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %> + <%= link_to "Forgot your password?", new_password_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %> + <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %> + <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %>
+<% end -%> + +<%- if devise_mapping.omniauthable? %> + <%- resource_class.omniauth_providers.each do |provider| %> + <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %>
+ <% end -%> +<% end -%> diff --git a/app/views/users/unlocks/new.html.erb b/app/views/users/unlocks/new.html.erb new file mode 100644 index 000000000..1eefabbb8 --- /dev/null +++ b/app/views/users/unlocks/new.html.erb @@ -0,0 +1,16 @@ +

Resend unlock instructions

+ +<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %> + <%= devise_error_messages! %> + +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true %> +
+ +
+ <%= f.submit "Resend unlock instructions" %> +
+<% end %> + +<%= render "users/shared/links" %> diff --git a/app/views/welcome/index.html.haml b/app/views/welcome/index.html.haml new file mode 100644 index 000000000..0956bc2a7 --- /dev/null +++ b/app/views/welcome/index.html.haml @@ -0,0 +1,2 @@ +%h1 coucou + diff --git a/config/routes.rb b/config/routes.rb index f4fb5ace6..df5c8f0a3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,17 @@ Rails.application.routes.draw do + + devise_for :users, controllers: { + sessions: 'users/sessions' + } + devise_for :gestionnaires, controllers: { sessions: 'gestionnaires/sessions' - }, skip: [:password, :registrations] - root 'start#index' + root 'welcome#index' + get 'start' => 'start#index' get 'start/index' get 'start/error_siret' get 'start/error_login' diff --git a/db/migrate/20150922141232_create_users.rb b/db/migrate/20150922141232_create_users.rb new file mode 100644 index 000000000..372296c3c --- /dev/null +++ b/db/migrate/20150922141232_create_users.rb @@ -0,0 +1,42 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table(:users) do |t| + ## Database authenticatable + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + t.integer :sign_in_count, default: 0, null: false + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.inet :current_sign_in_ip + t.inet :last_sign_in_ip + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + + t.timestamps + end + + add_index :users, :email, unique: true + add_index :users, :reset_password_token, unique: true + # add_index :users, :confirmation_token, unique: true + # add_index :users, :unlock_token, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 27b66f15f..5008756e3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150922113504) do +ActiveRecord::Schema.define(version: 20150922141232) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -108,7 +108,7 @@ ActiveRecord::Schema.define(version: 20150922113504) do t.integer "type_de_piece_justificative_id" end - add_index "pieces_justificatives", ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_piece_jointe_id", using: :btree + add_index "pieces_justificatives", ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_de_piece_justificative_id", using: :btree create_table "procedures", force: :cascade do |t| t.string "libelle" @@ -130,6 +130,24 @@ ActiveRecord::Schema.define(version: 20150922113504) do t.integer "procedure_id" end + create_table "users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.inet "current_sign_in_ip" + t.inet "last_sign_in_ip" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + add_foreign_key "cerfas", "dossiers" add_foreign_key "commentaires", "dossiers" end diff --git a/spec/controllers/start_controller_spec.rb b/spec/controllers/start_controller_spec.rb index b8d1c3e5d..57a19bf0c 100644 --- a/spec/controllers/start_controller_spec.rb +++ b/spec/controllers/start_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -RSpec.describe StartController, type: :controller do +describe StartController, type: :controller do let!(:procedure) { create(:procedure) } describe 'GET #index' do @@ -10,68 +10,73 @@ RSpec.describe StartController, type: :controller do context 'when params procedure_id is present' do context 'when procedure_id is valid' do - it { expect(response).to have_http_status(:success) } - end - - context 'when procedure_id is not valid' do - let(:procedure) { '' } - it { expect(response).to have_http_status(404) } + context 'when user is logged in' do + before do + sign_in create(:user) + end + subject { get :index, procedure_id: procedure } + it { expect(subject).to have_http_status(:success) } + context 'when procedure_id is not valid' do + let(:procedure) { '' } + it { is_expected.to have_http_status(404) } + end + context 'when params procedure_id is not present' do + subject { get :index } + it { is_expected.to have_http_status(404) } + end + end + context 'when user is not logged' do + it { expect(response).to have_http_status(302) } + end end end - - context 'when params procedure_id is not present' do - before do - get :index - end - it { expect(response).to have_http_status(404) } - end end - describe 'GET #index with bad SIRET' do - before do - get :error_siret, procedure_id: procedure - end + # describe 'GET #index with bad SIRET' do + # before do + # get :error_siret, procedure_id: procedure + # end - it 'returns http success and flash alert is present' do - expect(response).to have_http_status(:success) - end - it 'la flash alert est présente' do - expect(flash[:alert]).to be_present - end - it 'la flash alert a un libellé correct' do - expect(flash[:alert]).to have_content('Ce SIRET n\'est pas valide') - end - end + # it 'returns http success and flash alert is present' do + # expect(response).to have_http_status(:success) + # end + # it 'la flash alert est présente' do + # expect(flash[:alert]).to be_present + # end + # it 'la flash alert a un libellé correct' do + # expect(flash[:alert]).to have_content('Ce SIRET n\'est pas valide') + # end + # end - describe 'GET #index with bad LOGIN' do - before do - get :error_login - end + # describe 'GET #index with bad LOGIN' do + # before do + # get :error_login + # end - it 'returns http success and flash alert is present' do - expect(response).to have_http_status(:success) - end - it 'la flash alert est présente' do - expect(flash[:alert]).to be_present - end - it 'la flash alert a un libellé correct' do - expect(flash[:alert]).to have_content('Ce compte n\'existe pas') - end - end + # it 'returns http success and flash alert is present' do + # expect(response).to have_http_status(:success) + # end + # it 'la flash alert est présente' do + # expect(flash[:alert]).to be_present + # end + # it 'la flash alert a un libellé correct' do + # expect(flash[:alert]).to have_content('Ce compte n\'existe pas') + # end + # end - describe 'GET #index with bad DOSSIER' do - before do - get :error_dossier - end + # describe 'GET #index with bad DOSSIER' do + # before do + # get :error_dossier + # end - it 'returns http success and flash alert is present' do - expect(response).to have_http_status(:success) - end - it 'la flash alert est présente' do - expect(flash[:alert]).to be_present - end - it 'la flash alert a un libellé correct' do - expect(flash[:alert]).to have_content('Ce dossier n\'existe pas') - end - end + # it 'returns http success and flash alert is present' do + # expect(response).to have_http_status(:success) + # end + # it 'la flash alert est présente' do + # expect(flash[:alert]).to be_present + # end + # it 'la flash alert a un libellé correct' do + # expect(flash[:alert]).to have_content('Ce dossier n\'existe pas') + # end + # end end diff --git a/spec/factories/user.rb b/spec/factories/user.rb new file mode 100644 index 000000000..4612d1e12 --- /dev/null +++ b/spec/factories/user.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + sequence(:user_email) { |n| "plop#{n}@plop.com" } + factory :user do + email { generate(:user_email) } + password 'password' + end +end \ No newline at end of file diff --git a/spec/features/users/start_demande_spec.rb b/spec/features/users/start_demande_spec.rb new file mode 100644 index 000000000..c073aab62 --- /dev/null +++ b/spec/features/users/start_demande_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +feature 'user arrive on start page' do + let(:procedure) { create(:procedure) } + let(:user) { create(:user) } + let(:siret) { '42149333900020' } + let(:siren) { siret[0...9] } + context 'when user is not logged in' do + before do + visit start_path(procedure_id: procedure.id) + end + scenario 'he is redirected to login page' do + expect(page).to have_css('#login_user') + end + context 'when he enter login information' do + before do + page.find_by_id('user_email').set user.email + page.find_by_id('user_password').set user.password + page.click_on 'Se connecter' + end + scenario 'he is redirected to start page to enter a siret' do + expect(page).to have_css('#pro_section') + end + context 'when enter a siret' do + before do + stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}") + .to_return(status: 200, body: File.read('spec/support/files/etablissement.json')) + stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}") + .to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) + page.find_by_id('siret').set siret + page.click_on 'Commencer' + end + scenario 'he is redirected to recap info entreprise page' do + expect(page).to have_css('#recap_info_entreprise') + end + end + end + end +end \ No newline at end of file diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 000000000..13fafe562 --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +describe User, type: :model do + describe 'database columns' do + it { is_expected.to have_db_column(:email) } + it { is_expected.to have_db_column(:encrypted_password) } + it { is_expected.to have_db_column(:reset_password_token) } + it { is_expected.to have_db_column(:reset_password_sent_at) } + it { is_expected.to have_db_column(:remember_created_at) } + it { is_expected.to have_db_column(:sign_in_count) } + it { is_expected.to have_db_column(:current_sign_in_at) } + it { is_expected.to have_db_column(:last_sign_in_at) } + it { is_expected.to have_db_column(:current_sign_in_ip) } + it { is_expected.to have_db_column(:last_sign_in_ip) } + it { is_expected.to have_db_column(:created_at) } + it { is_expected.to have_db_column(:updated_at) } + end +end From 8c549bf27bf9d0fc03ac30f1beb9524df4d33c78 Mon Sep 17 00:00:00 2001 From: Tanguy PATTE Date: Wed, 23 Sep 2015 12:04:57 +0200 Subject: [PATCH 2/7] =?UTF-8?q?[#887]=20afficher=20la=20liste=20des=20doss?= =?UTF-8?q?iers=20=C3=A0=20l'utilisateur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users/dossiers_controller.rb | 6 ++++++ app/controllers/welcome_controller.rb | 6 ------ app/views/users/dossiers/index.html.haml | 10 ++++++++++ app/views/welcome/index.html.haml | 2 -- config/routes.rb | 3 ++- db/schema.rb | 3 +-- spec/controllers/dossiers_controller_spec.rb | 2 +- .../users/dossiers_controller_spec.rb | 17 +++++++++++++++++ spec/features/users/list_dossiers_spec.rb | 16 ++++++++++++++++ .../users/dossiers/index.html.haml_spec.rb | 16 ++++++++++++++++ 10 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 app/controllers/users/dossiers_controller.rb delete mode 100644 app/controllers/welcome_controller.rb create mode 100644 app/views/users/dossiers/index.html.haml delete mode 100644 app/views/welcome/index.html.haml create mode 100644 spec/controllers/users/dossiers_controller_spec.rb create mode 100644 spec/features/users/list_dossiers_spec.rb create mode 100644 spec/views/users/dossiers/index.html.haml_spec.rb diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb new file mode 100644 index 000000000..eaf68cfc4 --- /dev/null +++ b/app/controllers/users/dossiers_controller.rb @@ -0,0 +1,6 @@ +class Users::DossiersController < ApplicationController + before_action :authenticate_user! + def index + @dossiers = Dossier.all.decorate + end +end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb deleted file mode 100644 index 0a135b18b..000000000 --- a/app/controllers/welcome_controller.rb +++ /dev/null @@ -1,6 +0,0 @@ -class WelcomeController < ApplicationController - before_action :authenticate_user! - def index - - end -end \ No newline at end of file diff --git a/app/views/users/dossiers/index.html.haml b/app/views/users/dossiers/index.html.haml new file mode 100644 index 000000000..30f4a7fb4 --- /dev/null +++ b/app/views/users/dossiers/index.html.haml @@ -0,0 +1,10 @@ +%h1 Vos dossiers : + +%table.table + %thead + %th Nom du Projet + %th Mise à jour + - @dossiers.each do |dossier| + %tr + %td= dossier.nom_projet + %td= dossier.last_update \ No newline at end of file diff --git a/app/views/welcome/index.html.haml b/app/views/welcome/index.html.haml deleted file mode 100644 index 0956bc2a7..000000000 --- a/app/views/welcome/index.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -%h1 coucou - diff --git a/config/routes.rb b/config/routes.rb index df5c8f0a3..a192e08dd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,7 +9,8 @@ Rails.application.routes.draw do }, skip: [:password, :registrations] - root 'welcome#index' + # root 'welcome#index' + root 'users/dossiers#index' get 'start' => 'start#index' get 'start/index' diff --git a/db/schema.rb b/db/schema.rb index ee8bf168b..2603b24dd 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: 20150922141232) do # These are extensions that must be enabled in order to support this database @@ -47,7 +46,7 @@ ActiveRecord::Schema.define(version: 20150922141232) do t.date "date_previsionnelle" t.datetime "created_at" t.datetime "updated_at" - t.string "state" + t.string "state" end add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree diff --git a/spec/controllers/dossiers_controller_spec.rb b/spec/controllers/dossiers_controller_spec.rb index 65136dbbd..9a235e65f 100644 --- a/spec/controllers/dossiers_controller_spec.rb +++ b/spec/controllers/dossiers_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -RSpec.describe DossiersController, type: :controller do +describe DossiersController, type: :controller do let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } let(:dossier_id) { dossier.id } let(:siret_not_found) { 999_999_999_999 } diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb new file mode 100644 index 000000000..6a136ab38 --- /dev/null +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Users::DossiersController, type: :controller do + describe '.index' do + subject { get :index } + context 'when user is not logged in' do + it { is_expected.to redirect_to('/users/sign_in') } + end + context 'when user is logged in' do + before do + sign_in create(:user) + end + it { is_expected.to render_template('users/dossiers/index') } + it { is_expected.to have_http_status(:success) } + end + end +end \ No newline at end of file diff --git a/spec/features/users/list_dossiers_spec.rb b/spec/features/users/list_dossiers_spec.rb new file mode 100644 index 000000000..2d1db6656 --- /dev/null +++ b/spec/features/users/list_dossiers_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +feature 'user access to the list of his dossier' do + + let(:user) { create(:user) } + let!(:dossier1) { create(:dossier) } + before do + visit root_path + page.find_by_id('user_email').set user.email + page.find_by_id('user_password').set user.password + page.click_on 'Se connecter' + end + scenario 'the list of dossier is displayed' do + expect(page).to have_content(dossier1.nom_projet) + end +end \ No newline at end of file diff --git a/spec/views/users/dossiers/index.html.haml_spec.rb b/spec/views/users/dossiers/index.html.haml_spec.rb new file mode 100644 index 000000000..bd88b8ddc --- /dev/null +++ b/spec/views/users/dossiers/index.html.haml_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe 'users/dossiers/index.html.haml', type: :view do + + describe 'list dossiers' do + let(:dossier1) { create(:dossier).decorate } + let(:dossier2) { create(:dossier).decorate } + before do + assign(:dossiers, [dossier1, dossier2]) + render + end + subject { rendered } + it { expect(subject).to have_content(dossier1.nom_projet) } + end + +end \ No newline at end of file From ede01b024b32c95e41cd4bca5347ddd2614d51fc Mon Sep 17 00:00:00 2001 From: Tanguy PATTE Date: Wed, 23 Sep 2015 12:16:21 +0200 Subject: [PATCH 3/7] [#888] link user to dossier --- app/models/dossier.rb | 1 + app/models/user.rb | 2 ++ db/migrate/20150923101000_add_user_to_dossier.rb | 6 ++++++ db/schema.rb | 9 ++++++--- spec/models/dossier_spec.rb | 1 + spec/models/user_spec.rb | 3 +++ 6 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20150923101000_add_user_to_dossier.rb diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 7c4e1ee1a..dda6f3988 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -12,6 +12,7 @@ class Dossier < ActiveRecord::Base has_one :cerfa has_many :pieces_justificatives belongs_to :procedure + belongs_to :user has_many :commentaires delegate :siren, to: :entreprise diff --git a/app/models/user.rb b/app/models/user.rb index c8220270d..802edb08c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,4 +3,6 @@ class User < ActiveRecord::Base # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable + + has_many :dossiers end diff --git a/db/migrate/20150923101000_add_user_to_dossier.rb b/db/migrate/20150923101000_add_user_to_dossier.rb new file mode 100644 index 000000000..0bf8685b4 --- /dev/null +++ b/db/migrate/20150923101000_add_user_to_dossier.rb @@ -0,0 +1,6 @@ +class AddUserToDossier < ActiveRecord::Migration + def change + add_reference :dossiers, :user, index: true + add_foreign_key :dossiers, :users + end +end diff --git a/db/schema.rb b/db/schema.rb index 2603b24dd..174c2e85a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150922141232) do +ActiveRecord::Schema.define(version: 20150923101000) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -44,12 +44,14 @@ ActiveRecord::Schema.define(version: 20150922141232) do t.string "montant_aide_demande" t.integer "procedure_id" t.date "date_previsionnelle" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", default: '2015-09-22 09:25:29' + t.datetime "updated_at", default: '2015-09-22 09:25:29' t.string "state" + t.integer "user_id" end add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree + add_index "dossiers", ["user_id"], name: "index_dossiers_on_user_id", using: :btree create_table "entreprises", force: :cascade do |t| t.string "siren" @@ -150,4 +152,5 @@ ActiveRecord::Schema.define(version: 20150922141232) do add_foreign_key "cerfas", "dossiers" add_foreign_key "commentaires", "dossiers" + add_foreign_key "dossiers", "users" end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 7814c87ff..13e5274af 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -21,6 +21,7 @@ describe Dossier do it { is_expected.to have_one(:cerfa) } it { is_expected.to have_one(:etablissement) } it { is_expected.to have_one(:entreprise) } + it { is_expected.to belong_to(:user) } end describe 'delegation' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 13fafe562..ca38b1986 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -15,4 +15,7 @@ describe User, type: :model do it { is_expected.to have_db_column(:created_at) } it { is_expected.to have_db_column(:updated_at) } end + describe 'associations' do + it { is_expected.to have_many(:dossiers) } + end end From e0cb736542ca5e8b52a2b98cf69de02a66866bc2 Mon Sep 17 00:00:00 2001 From: Tanguy PATTE Date: Wed, 23 Sep 2015 16:56:30 +0200 Subject: [PATCH 4/7] rename start controller into siret controller and change error handling --- .../stylesheets/{start.scss => siret.scss} | 0 .../backoffice/dossiers_controller.rb | 8 +--- app/controllers/carte_controller.rb | 2 +- app/controllers/description_controller.rb | 3 +- app/controllers/dossiers_controller.rb | 12 ++++-- app/controllers/recapitulatif_controller.rb | 3 +- app/controllers/siret_controller.rb | 13 +++++++ app/controllers/start_controller.rb | 38 ------------------- app/views/{start => siret}/_admin.html.haml | 0 app/views/{start => siret}/_pro.html.haml | 0 app/views/{start => siret}/index.html.haml | 2 +- config/locales/fr.yml | 2 + config/routes.rb | 10 ++--- .../backoffice/dossiers_controller_spec.rb | 2 +- .../description_controller_spec.rb | 2 +- spec/controllers/dossiers_controller_spec.rb | 25 +++++++----- .../recapitulatif_controller_spec.rb | 4 +- ...oller_spec.rb => siret_controller_spec.rb} | 2 +- spec/features/users/start_demande_spec.rb | 6 +-- .../{start => siret}/index.html.haml_spec.rb | 2 +- 20 files changed, 60 insertions(+), 76 deletions(-) rename app/assets/stylesheets/{start.scss => siret.scss} (100%) create mode 100644 app/controllers/siret_controller.rb delete mode 100644 app/controllers/start_controller.rb rename app/views/{start => siret}/_admin.html.haml (100%) rename app/views/{start => siret}/_pro.html.haml (100%) rename app/views/{start => siret}/index.html.haml (92%) rename spec/controllers/{start_controller_spec.rb => siret_controller_spec.rb} (98%) rename spec/views/{start => siret}/index.html.haml_spec.rb (95%) diff --git a/app/assets/stylesheets/start.scss b/app/assets/stylesheets/siret.scss similarity index 100% rename from app/assets/stylesheets/start.scss rename to app/assets/stylesheets/siret.scss diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 189cbab65..e1f4c96ec 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -14,12 +14,8 @@ class Backoffice::DossiersController < ApplicationController @dossier = @dossier.decorate rescue ActiveRecord::RecordNotFound - redirect_start + flash.alert = t('errors.messages.dossier_not_found') + redirect_to url_for(controller: '/backoffice') end - private - - def redirect_start - redirect_to url_for(controller: '/start', action: :error_dossier) - end end diff --git a/app/controllers/carte_controller.rb b/app/controllers/carte_controller.rb index d36f24d14..2e11af799 100644 --- a/app/controllers/carte_controller.rb +++ b/app/controllers/carte_controller.rb @@ -4,7 +4,7 @@ class CarteController < ApplicationController def show @dossier = current_dossier rescue ActiveRecord::RecordNotFound - redirect_to url_for(controller: :start, action: :error_dossier) + redirect_to url_for(controller: :siret, action: :error_dossier) end def save_ref_api_carto diff --git a/app/controllers/description_controller.rb b/app/controllers/description_controller.rb index 7835f1e00..ba492d6b3 100644 --- a/app/controllers/description_controller.rb +++ b/app/controllers/description_controller.rb @@ -6,7 +6,8 @@ class DescriptionController < ApplicationController @procedure = @dossier.procedure rescue ActiveRecord::RecordNotFound - redirect_to url_for(controller: :start, action: :error_dossier) + flash.alert = t('errors.messages.dossier_not_found') + redirect_to url_for(controller: :siret) end def error diff --git a/app/controllers/dossiers_controller.rb b/app/controllers/dossiers_controller.rb index 07e27a368..240400bcd 100644 --- a/app/controllers/dossiers_controller.rb +++ b/app/controllers/dossiers_controller.rb @@ -5,16 +5,18 @@ class DossiersController < ApplicationController @etablissement = @dossier.etablissement @entreprise = @dossier.entreprise.decorate rescue ActiveRecord::RecordNotFound - redirect_to url_for(controller: :start, action: :error_dossier) + flash.alert = t('errors.messages.dossier_not_found') + redirect_to url_for(controller: :siret) end def create + procedure = Procedure.find(params['procedure_id']) @etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params) @entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params) @dossier = Dossier.create @dossier.draft! - @dossier.procedure = Procedure.find(params['procedure_id']) + @dossier.procedure = procedure @dossier.save @entreprise.dossier = @dossier @@ -27,9 +29,11 @@ class DossiersController < ApplicationController redirect_to url_for(controller: :dossiers, action: :show, id: @dossier.id) rescue RestClient::ResourceNotFound - redirect_to url_for(controller: :start, action: :error_siret, procedure_id: params['procedure_id']) + flash.alert = t('errors.messages.invalid_siret') + redirect_to url_for(controller: :siret, procedure_id: params['procedure_id']) rescue ActiveRecord::RecordNotFound - redirect_to url_for(controller: :start, action: :error_dossier) + flash.alert = t('errors.messages.dossier_not_found') + redirect_to url_for(controller: :siret) end def update diff --git a/app/controllers/recapitulatif_controller.rb b/app/controllers/recapitulatif_controller.rb index 194cd0f0e..4552dbc3b 100644 --- a/app/controllers/recapitulatif_controller.rb +++ b/app/controllers/recapitulatif_controller.rb @@ -11,6 +11,7 @@ class RecapitulatifController < ApplicationController #TODO load user email @commentaire_email = 'user@email' rescue ActiveRecord::RecordNotFound - redirect_to url_for(controller: :start, action: :error_dossier) + flash.alert = t('errors.messages.dossier_not_found') + redirect_to url_for(controller: :siret) end end diff --git a/app/controllers/siret_controller.rb b/app/controllers/siret_controller.rb new file mode 100644 index 000000000..5f5bb976f --- /dev/null +++ b/app/controllers/siret_controller.rb @@ -0,0 +1,13 @@ +class SiretController < ApplicationController + before_action :authenticate_user! + def index + @procedure = Procedure.find(params['procedure_id']) + rescue ActiveRecord::RecordNotFound + error_procedure + end + + def error_procedure + render :file => "#{Rails.root}/public/404_procedure_not_found.html", :status => 404 + end + +end diff --git a/app/controllers/start_controller.rb b/app/controllers/start_controller.rb deleted file mode 100644 index 51eb5a053..000000000 --- a/app/controllers/start_controller.rb +++ /dev/null @@ -1,38 +0,0 @@ -class StartController < ApplicationController - before_action :authenticate_user! - def index - get_procedure_infos - - if @procedure.nil? - error_procedure - end - rescue ActiveRecord::RecordNotFound - error_procedure - end - - def error_procedure - render :file => "#{Rails.root}/public/404_procedure_not_found.html", :status => 404 - end - - def error_siret - get_procedure_infos - flash.now.alert = 'Ce SIRET n\'est pas valide' - render 'index' - end - - def error_login - flash.now.alert = 'Ce compte n\'existe pas' - render 'index' - end - - def error_dossier - flash.now.alert = 'Ce dossier n\'existe pas' - render 'index' - end - - private - - def get_procedure_infos - @procedure = Procedure.find(params['procedure_id']) - end -end diff --git a/app/views/start/_admin.html.haml b/app/views/siret/_admin.html.haml similarity index 100% rename from app/views/start/_admin.html.haml rename to app/views/siret/_admin.html.haml diff --git a/app/views/start/_pro.html.haml b/app/views/siret/_pro.html.haml similarity index 100% rename from app/views/start/_pro.html.haml rename to app/views/siret/_pro.html.haml diff --git a/app/views/start/index.html.haml b/app/views/siret/index.html.haml similarity index 92% rename from app/views/start/index.html.haml rename to app/views/siret/index.html.haml index fe9aa62d7..215baf74a 100644 --- a/app/views/start/index.html.haml +++ b/app/views/siret/index.html.haml @@ -5,5 +5,5 @@ Site de démonstration d’un service public de saisie d’un projet ou de dépôt d’une démarche administrative, auprès d’un ou plusieurs organismes publics, simplifié des informations déjà connues des administrations, grâce à la fourniture du numéro SIRET. .row - = render partial: '/start/pro' + = render partial: '/siret/pro' diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 6591b7048..dff830200 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -78,5 +78,7 @@ fr: not_saved: one: "1 erreur a empêché ce(tte) %{resource} d'être sauvegardé(e) :" other: "%{count} erreurs ont empêché ce(tte) %{resource} d'être sauvegardé(e) :" + dossier_not_found: "Le dossier n'existe pas" + invalid_siret: "Le siret est incorrect" diff --git a/config/routes.rb b/config/routes.rb index a192e08dd..69b95450a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,11 +12,11 @@ Rails.application.routes.draw do # root 'welcome#index' root 'users/dossiers#index' - get 'start' => 'start#index' - get 'start/index' - get 'start/error_siret' - get 'start/error_login' - get 'start/error_dossier' + get 'siret' => 'siret#index' + # get 'start/index' + # get 'start/error_siret' + # get 'start/error_login' + # get 'start/error_dossier' resources :dossiers do get '/demande' => 'demandes#show' diff --git a/spec/controllers/backoffice/dossiers_controller_spec.rb b/spec/controllers/backoffice/dossiers_controller_spec.rb index 7023432df..da789d0e4 100644 --- a/spec/controllers/backoffice/dossiers_controller_spec.rb +++ b/spec/controllers/backoffice/dossiers_controller_spec.rb @@ -19,7 +19,7 @@ describe Backoffice::DossiersController, type: :controller do it "le numéro de dossier n'existe pas" do get :show, id: bad_dossier_id - expect(response).to redirect_to('/start/error_dossier') + expect(response).to redirect_to('/backoffice') end end diff --git a/spec/controllers/description_controller_spec.rb b/spec/controllers/description_controller_spec.rb index 894378bd9..1998f2258 100644 --- a/spec/controllers/description_controller_spec.rb +++ b/spec/controllers/description_controller_spec.rb @@ -13,7 +13,7 @@ describe DescriptionController, type: :controller do it 'redirection vers start si mauvais dossier ID' do get :show, dossier_id: bad_dossier_id - expect(response).to redirect_to(controller: :start, action: :error_dossier) + expect(response).to redirect_to(controller: :siret) end end diff --git a/spec/controllers/dossiers_controller_spec.rb b/spec/controllers/dossiers_controller_spec.rb index 9a235e65f..6c2f5d478 100644 --- a/spec/controllers/dossiers_controller_spec.rb +++ b/spec/controllers/dossiers_controller_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe DossiersController, type: :controller do let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } + let(:procedure) { create(:procedure) } let(:dossier_id) { dossier.id } let(:siret_not_found) { 999_999_999_999 } @@ -15,9 +16,9 @@ describe DossiersController, type: :controller do expect(response).to have_http_status(:success) end - it 'redirection vers start si mauvais dossier ID' do + it 'redirection vers siret si mauvais dossier ID' do get :show, id: siret_not_found - expect(response).to redirect_to('/start/error_dossier') + expect(response).to redirect_to('/siret') end end @@ -36,16 +37,16 @@ describe DossiersController, type: :controller do describe 'professionnel fills form' do context 'when pro_dossier_id is empty' do context 'with valid siret ' do - before do - post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last - end + + subject { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last } + it 'create a dossier' do - expect { post :create, siret: siret, pro_dossier_id: '' }.to change { Dossier.count }.by(1) + expect { subject }.to change { Dossier.count }.by(1) end it 'creates entreprise' do - expect { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }.to change { Entreprise.count }.by(1) + expect { subject }.to change { Entreprise.count }.by(1) end it 'links entreprise to dossier' do @@ -53,35 +54,39 @@ describe DossiersController, type: :controller do end it 'creates etablissement for dossier' do - expect { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }.to change { Etablissement.count }.by(1) + expect { subject }.to change { Etablissement.count }.by(1) end it 'links etablissement to dossier' do + subject expect(Etablissement.last.dossier).to eq(Dossier.last) end it 'links etablissement to entreprise' do + subject expect(Etablissement.last.entreprise).to eq(Entreprise.last) end it 'links procedure to dossier' do + subject expect(Dossier.last.procedure).to eq(Procedure.last) end it 'state of dossier is draft' do + subject expect(Dossier.last.state).to eq('draft') end end context 'with non existant siret' do let(:siret_not_found) { '11111111111111' } - subject { post :create, siret: siret_not_found, pro_dossier_id: '' } + subject { post :create, siret: siret_not_found, pro_dossier_id: '', procedure_id: procedure.id } it 'does not create new dossier' do expect { subject }.not_to change { Dossier.count } end it 'redirects to show' do - expect(subject).to redirect_to(controller: :start, action: :error_siret) + expect(subject).to redirect_to(controller: :siret, procedure_id: procedure.id) end end end diff --git a/spec/controllers/recapitulatif_controller_spec.rb b/spec/controllers/recapitulatif_controller_spec.rb index 609ddbf22..1d572121a 100644 --- a/spec/controllers/recapitulatif_controller_spec.rb +++ b/spec/controllers/recapitulatif_controller_spec.rb @@ -11,9 +11,9 @@ RSpec.describe RecapitulatifController, type: :controller do expect(response).to have_http_status(:success) end - it 'redirection vers start si mauvais dossier ID' do + it 'redirection vers siret si mauvais dossier ID' do get :show, dossier_id: bad_dossier_id - expect(response).to redirect_to('/start/error_dossier') + expect(response).to redirect_to('/siret') end end end diff --git a/spec/controllers/start_controller_spec.rb b/spec/controllers/siret_controller_spec.rb similarity index 98% rename from spec/controllers/start_controller_spec.rb rename to spec/controllers/siret_controller_spec.rb index 57a19bf0c..e169a8fd7 100644 --- a/spec/controllers/start_controller_spec.rb +++ b/spec/controllers/siret_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe StartController, type: :controller do +describe SiretController, type: :controller do let!(:procedure) { create(:procedure) } describe 'GET #index' do diff --git a/spec/features/users/start_demande_spec.rb b/spec/features/users/start_demande_spec.rb index c073aab62..1da39fcc2 100644 --- a/spec/features/users/start_demande_spec.rb +++ b/spec/features/users/start_demande_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -feature 'user arrive on start page' do +feature 'user arrive on siret page' do let(:procedure) { create(:procedure) } let(:user) { create(:user) } let(:siret) { '42149333900020' } let(:siren) { siret[0...9] } context 'when user is not logged in' do before do - visit start_path(procedure_id: procedure.id) + visit siret_path(procedure_id: procedure.id) end scenario 'he is redirected to login page' do expect(page).to have_css('#login_user') @@ -18,7 +18,7 @@ feature 'user arrive on start page' do page.find_by_id('user_password').set user.password page.click_on 'Se connecter' end - scenario 'he is redirected to start page to enter a siret' do + scenario 'he is redirected to siret page to enter a siret' do expect(page).to have_css('#pro_section') end context 'when enter a siret' do diff --git a/spec/views/start/index.html.haml_spec.rb b/spec/views/siret/index.html.haml_spec.rb similarity index 95% rename from spec/views/start/index.html.haml_spec.rb rename to spec/views/siret/index.html.haml_spec.rb index b4334cbb7..9d27ae043 100644 --- a/spec/views/start/index.html.haml_spec.rb +++ b/spec/views/siret/index.html.haml_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'start/index.html.haml', type: :view do +describe 'siret/index.html.haml', type: :view do let(:procedure) { create(:procedure, libelle: 'Demande de subvention') } before do assign(:procedure, procedure) From 4f3b35fe4151eaed6da5bca29f8085a9aff4ad89 Mon Sep 17 00:00:00 2001 From: Tanguy PATTE Date: Wed, 23 Sep 2015 16:56:53 +0200 Subject: [PATCH 5/7] remove useless lines --- config/routes.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 69b95450a..d63e90db8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,10 +13,7 @@ Rails.application.routes.draw do root 'users/dossiers#index' get 'siret' => 'siret#index' - # get 'start/index' - # get 'start/error_siret' - # get 'start/error_login' - # get 'start/error_dossier' + resources :dossiers do get '/demande' => 'demandes#show' From 5772b99d4262ca6d495ebba99a2554fa89a00e2a Mon Sep 17 00:00:00 2001 From: Tanguy PATTE Date: Wed, 23 Sep 2015 19:20:03 +0200 Subject: [PATCH 6/7] move controller into users folder --- app/controllers/dossiers_controller.rb | 114 +++++----- .../users/commentaires_controller.rb | 3 + .../{ => users}/description_controller.rb | 2 +- app/controllers/users/dossiers_controller.rb | 75 ++++++- .../{ => users}/recapitulatif_controller.rb | 3 +- .../{ => users}/siret_controller.rb | 4 +- app/controllers/users_controller.rb | 3 + app/views/backoffice/dossiers/show.html.haml | 2 +- app/views/dossiers/_show.html.haml | 13 ++ app/views/dossiers/show.html.haml | 14 +- app/views/siret/_admin.html.haml | 24 --- .../{ => users}/description/show.html.haml | 0 app/views/users/dossiers/show.html.haml | 1 + .../_commentaires_flux.html.haml | 0 .../{ => users}/recapitulatif/show.html.haml | 0 app/views/{ => users}/siret/_pro.html.haml | 0 app/views/{ => users}/siret/index.html.haml | 2 +- config/routes.rb | 46 +++-- .../commentaires_controller_spec.rb | 4 +- .../description_controller_spec.rb | 6 +- spec/controllers/dossiers_controller_spec.rb | 194 +++++++++--------- .../users/dossiers_controller_spec.rb | 131 ++++++++++++ .../recapitulatif_controller_spec.rb | 11 +- .../{ => users}/siret_controller_spec.rb | 2 +- spec/factories/dossier.rb | 6 + spec/features/datepicker_spec.rb | 2 +- .../description_page/show_page_spec.rb | 8 +- .../upload_piece_justificative_spec.rb | 2 +- .../_commentaires_flux_spec.rb | 11 +- .../recapitulatif_page/show_page_spec.rb | 9 +- spec/features/users/start_demande_spec.rb | 2 +- spec/views/dossiers/show.html.haml_spec.rb | 12 +- .../{ => users}/siret/index.html.haml_spec.rb | 4 +- 33 files changed, 460 insertions(+), 250 deletions(-) create mode 100644 app/controllers/users/commentaires_controller.rb rename app/controllers/{ => users}/description_controller.rb (96%) rename app/controllers/{ => users}/recapitulatif_controller.rb (88%) rename app/controllers/{ => users}/siret_controller.rb (75%) create mode 100644 app/controllers/users_controller.rb create mode 100644 app/views/dossiers/_show.html.haml delete mode 100644 app/views/siret/_admin.html.haml rename app/views/{ => users}/description/show.html.haml (100%) create mode 100644 app/views/users/dossiers/show.html.haml rename app/views/{ => users}/recapitulatif/_commentaires_flux.html.haml (100%) rename app/views/{ => users}/recapitulatif/show.html.haml (100%) rename app/views/{ => users}/siret/_pro.html.haml (100%) rename app/views/{ => users}/siret/index.html.haml (92%) rename spec/controllers/{ => users}/recapitulatif_controller_spec.rb (53%) rename spec/controllers/{ => users}/siret_controller_spec.rb (97%) rename spec/views/{ => users}/siret/index.html.haml_spec.rb (87%) diff --git a/app/controllers/dossiers_controller.rb b/app/controllers/dossiers_controller.rb index 240400bcd..8f8ad60f1 100644 --- a/app/controllers/dossiers_controller.rb +++ b/app/controllers/dossiers_controller.rb @@ -1,73 +1,73 @@ class DossiersController < ApplicationController - def show - @dossier = Dossier.find(params[:id]) + # def show + # @dossier = Dossier.find(params[:id]) - @etablissement = @dossier.etablissement - @entreprise = @dossier.entreprise.decorate - rescue ActiveRecord::RecordNotFound - flash.alert = t('errors.messages.dossier_not_found') - redirect_to url_for(controller: :siret) - end + # @etablissement = @dossier.etablissement + # @entreprise = @dossier.entreprise.decorate + # rescue ActiveRecord::RecordNotFound + # flash.alert = t('errors.messages.dossier_not_found') + # redirect_to url_for(controller: :siret) + # end - def create - procedure = Procedure.find(params['procedure_id']) - @etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params) - @entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params) - @dossier = Dossier.create - @dossier.draft! + # def create + # procedure = Procedure.find(params['procedure_id']) + # @etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params) + # @entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params) + # @dossier = Dossier.create + # @dossier.draft! - @dossier.procedure = procedure - @dossier.save + # @dossier.procedure = procedure + # @dossier.save - @entreprise.dossier = @dossier - @entreprise.save + # @entreprise.dossier = @dossier + # @entreprise.save - @etablissement.dossier = @dossier - @etablissement.entreprise = @entreprise - @etablissement.save + # @etablissement.dossier = @dossier + # @etablissement.entreprise = @entreprise + # @etablissement.save - redirect_to url_for(controller: :dossiers, action: :show, id: @dossier.id) + # redirect_to url_for(controller: :dossiers, action: :show, id: @dossier.id) - rescue RestClient::ResourceNotFound - flash.alert = t('errors.messages.invalid_siret') - redirect_to url_for(controller: :siret, procedure_id: params['procedure_id']) - rescue ActiveRecord::RecordNotFound - flash.alert = t('errors.messages.dossier_not_found') - redirect_to url_for(controller: :siret) - end + # rescue RestClient::ResourceNotFound + # flash.alert = t('errors.messages.invalid_siret') + # redirect_to url_for(controller: :siret, procedure_id: params['procedure_id']) + # rescue ActiveRecord::RecordNotFound + # flash.alert = t('errors.messages.dossier_not_found') + # redirect_to url_for(controller: :siret) + # end - def update - @dossier = Dossier.find(params[:id]) - if checked_autorisation_donnees? - @dossier.update_attributes(update_params) - redirect_to url_for(controller: :description, action: :show, dossier_id: @dossier.id) - else - @etablissement = @dossier.etablissement - @entreprise = @dossier.entreprise.decorate - flash.now.alert = 'Les conditions sont obligatoires.' - render 'show' - end - end + # def update + # @dossier = Dossier.find(params[:id]) + # if checked_autorisation_donnees? + # @dossier.update_attributes(update_params) + # redirect_to url_for(controller: :description, action: :show, dossier_id: @dossier.id) + # else + # @etablissement = @dossier.etablissement + # @entreprise = @dossier.entreprise.decorate + # flash.now.alert = 'Les conditions sont obligatoires.' + # render 'show' + # end + # end - private + # private - def update_params - params.require(:dossier).permit(:autorisation_donnees) - end + # def update_params + # params.require(:dossier).permit(:autorisation_donnees) + # end - def dossier_id_is_present? - @dossier_id != '' - end + # def dossier_id_is_present? + # @dossier_id != '' + # end - def checked_autorisation_donnees? - update_params[:autorisation_donnees] == '1' - end + # def checked_autorisation_donnees? + # update_params[:autorisation_donnees] == '1' + # end - def siret - params[:siret] - end + # def siret + # params[:siret] + # end - def siren - siret[0..8] - end + # def siren + # siret[0..8] + # end end diff --git a/app/controllers/users/commentaires_controller.rb b/app/controllers/users/commentaires_controller.rb new file mode 100644 index 000000000..4c0ec854c --- /dev/null +++ b/app/controllers/users/commentaires_controller.rb @@ -0,0 +1,3 @@ +class Users::CommentairesController < CommentairesController + +end \ No newline at end of file diff --git a/app/controllers/description_controller.rb b/app/controllers/users/description_controller.rb similarity index 96% rename from app/controllers/description_controller.rb rename to app/controllers/users/description_controller.rb index ba492d6b3..d952cab2d 100644 --- a/app/controllers/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -1,4 +1,4 @@ -class DescriptionController < ApplicationController +class Users::DescriptionController < ApplicationController def show @dossier = Dossier.find(params[:dossier_id]) @dossier = @dossier.decorate diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index eaf68cfc4..808dca068 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -1,6 +1,79 @@ -class Users::DossiersController < ApplicationController +class Users::DossiersController < UsersController before_action :authenticate_user! def index @dossiers = Dossier.all.decorate end + def show + + @dossier = Dossier.find(params[:id]) + + @etablissement = @dossier.etablissement + @entreprise = @dossier.entreprise.decorate + rescue ActiveRecord::RecordNotFound + flash.alert = t('errors.messages.dossier_not_found') + redirect_to url_for(controller: :siret) + end + + def create + procedure = Procedure.find(params['procedure_id']) + @etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params) + @entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params) + @dossier = Dossier.create + @dossier.draft! + + @dossier.procedure = procedure + @dossier.save + + @entreprise.dossier = @dossier + @entreprise.save + + @etablissement.dossier = @dossier + @etablissement.entreprise = @entreprise + @etablissement.save + + redirect_to url_for(controller: :dossiers, action: :show, id: @dossier.id) + + rescue RestClient::ResourceNotFound + flash.alert = t('errors.messages.invalid_siret') + redirect_to url_for(controller: :siret, procedure_id: params['procedure_id']) + rescue ActiveRecord::RecordNotFound + flash.alert = t('errors.messages.dossier_not_found') + redirect_to url_for(controller: :siret) + end + + def update + + @dossier = Dossier.find(params[:id]) + if checked_autorisation_donnees? + @dossier.update_attributes(update_params) + redirect_to url_for(controller: :description, action: :show, dossier_id: @dossier.id) + else + @etablissement = @dossier.etablissement + @entreprise = @dossier.entreprise.decorate + flash.now.alert = 'Les conditions sont obligatoires.' + render 'show' + end + end + + private + + def update_params + params.require(:dossier).permit(:autorisation_donnees) + end + + def dossier_id_is_present? + @dossier_id != '' + end + + def checked_autorisation_donnees? + update_params[:autorisation_donnees] == '1' + end + + def siret + params[:siret] + end + + def siren + siret[0..8] + end end diff --git a/app/controllers/recapitulatif_controller.rb b/app/controllers/users/recapitulatif_controller.rb similarity index 88% rename from app/controllers/recapitulatif_controller.rb rename to app/controllers/users/recapitulatif_controller.rb index 4552dbc3b..2aa98ee6b 100644 --- a/app/controllers/recapitulatif_controller.rb +++ b/app/controllers/users/recapitulatif_controller.rb @@ -1,5 +1,6 @@ -class RecapitulatifController < ApplicationController +class Users::RecapitulatifController < UsersController def show + @dossier = Dossier.find(params[:dossier_id]) @dossier = @dossier.decorate diff --git a/app/controllers/siret_controller.rb b/app/controllers/users/siret_controller.rb similarity index 75% rename from app/controllers/siret_controller.rb rename to app/controllers/users/siret_controller.rb index 5f5bb976f..99b861f27 100644 --- a/app/controllers/siret_controller.rb +++ b/app/controllers/users/siret_controller.rb @@ -1,5 +1,4 @@ -class SiretController < ApplicationController - before_action :authenticate_user! +class Users::SiretController < UsersController def index @procedure = Procedure.find(params['procedure_id']) rescue ActiveRecord::RecordNotFound @@ -9,5 +8,4 @@ class SiretController < ApplicationController def error_procedure render :file => "#{Rails.root}/public/404_procedure_not_found.html", :status => 404 end - end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 000000000..32cb47327 --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,3 @@ +class UsersController < ApplicationController + before_action :authenticate_user! +end \ No newline at end of file diff --git a/app/views/backoffice/dossiers/show.html.haml b/app/views/backoffice/dossiers/show.html.haml index 55c87ffb9..272893a45 100644 --- a/app/views/backoffice/dossiers/show.html.haml +++ b/app/views/backoffice/dossiers/show.html.haml @@ -44,7 +44,7 @@ = render partial: '/carte/carte_sources_JS_backend' %br -= render partial: '/recapitulatif/commentaires_flux' += render partial: '/users/recapitulatif/commentaires_flux' %br %br diff --git a/app/views/dossiers/_show.html.haml b/app/views/dossiers/_show.html.haml new file mode 100644 index 000000000..d8cff59a9 --- /dev/null +++ b/app/views/dossiers/_show.html.haml @@ -0,0 +1,13 @@ +.container#recap_info_entreprise + %h2 Récapitulatif de vos informations (récupérées auprès de l'INSEE et d'INFOGREFFE) + %br + + %div.row + = render partial: '/dossiers/infos_entreprise' + %br + = form_for @dossier, url: { controller: '/users/dossiers', action: :create } do |f| + %label{ style:'font-weight:normal' } + = f.check_box :autorisation_donnees + J'autorise les organismes publics à vérifier les informations de mon entreprise auprès des administrations concernées. Ces informations resteront strictement confidentielles. + %br + = f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float:right', id: 'etape_suivante' \ No newline at end of file diff --git a/app/views/dossiers/show.html.haml b/app/views/dossiers/show.html.haml index 42262739c..74930f900 100644 --- a/app/views/dossiers/show.html.haml +++ b/app/views/dossiers/show.html.haml @@ -1,13 +1 @@ -.container#recap_info_entreprise - %h2 Récapitulatif de vos informations (récupérées auprès de l'INSEE et d'INFOGREFFE) - %br - - %div.row - = render partial: 'infos_entreprise' - %br - = form_for @dossier do |f| - %label{ style:'font-weight:normal' } - = f.check_box :autorisation_donnees - J'autorise les organismes publics à vérifier les informations de mon entreprise auprès des administrations concernées. Ces informations resteront strictement confidentielles. - %br - = f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float:right', id: 'etape_suivante' \ No newline at end of file += render partial: 'show' \ No newline at end of file diff --git a/app/views/siret/_admin.html.haml b/app/views/siret/_admin.html.haml deleted file mode 100644 index 10a86bcc6..000000000 --- a/app/views/siret/_admin.html.haml +++ /dev/null @@ -1,24 +0,0 @@ -/ %p.lead{id: 'admin_section'} -/ %span{class:'text-info', style:'font-weight:bold'} -/ -if user_signed_in? -/ ='Vous êtes identifié comme une administration' -/ -else -/ ='Si vous êtes une administration, ' - -/ %p.lead -/ -if user_signed_in? -/ = form_tag(url_for({controller: 'admin/dossier', action: :index}), class: 'form-inline', method: 'GET') do -/ .form-group.form-group-lg -/ = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "N° de dossier", :id => "dossier_id", :name => "dossier_id" -/ %br -/ = submit_tag "Accéder", class: %w(btn btn-lg btn-success), style: 'margin-top:20px;', data: { disable_with: "Accéder", submit: true} -/ -else -/ = form_tag(url_for({controller: 'user/sessions', action: :create}), class: 'form-inline', method: 'POST') do -/ .form-group.form-group-lg -/ = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "Identifiant", :id => "user_email", :name => "user[email]" -/ %br -/ = password_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "Mot de passe", :id => "user_password", :name => "user[password]" -/ %br -/ = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "N° de dossier", :id => "dossier_id", :name => "dossier_id" -/ %br -/ = submit_tag "Accéder", class: %w(btn btn-lg btn-success), style: 'margin-top:20px;', data: { disable_with: "Accéder", submit: true} diff --git a/app/views/description/show.html.haml b/app/views/users/description/show.html.haml similarity index 100% rename from app/views/description/show.html.haml rename to app/views/users/description/show.html.haml diff --git a/app/views/users/dossiers/show.html.haml b/app/views/users/dossiers/show.html.haml new file mode 100644 index 000000000..299da569b --- /dev/null +++ b/app/views/users/dossiers/show.html.haml @@ -0,0 +1 @@ += render partial: '/dossiers/show' \ No newline at end of file diff --git a/app/views/recapitulatif/_commentaires_flux.html.haml b/app/views/users/recapitulatif/_commentaires_flux.html.haml similarity index 100% rename from app/views/recapitulatif/_commentaires_flux.html.haml rename to app/views/users/recapitulatif/_commentaires_flux.html.haml diff --git a/app/views/recapitulatif/show.html.haml b/app/views/users/recapitulatif/show.html.haml similarity index 100% rename from app/views/recapitulatif/show.html.haml rename to app/views/users/recapitulatif/show.html.haml diff --git a/app/views/siret/_pro.html.haml b/app/views/users/siret/_pro.html.haml similarity index 100% rename from app/views/siret/_pro.html.haml rename to app/views/users/siret/_pro.html.haml diff --git a/app/views/siret/index.html.haml b/app/views/users/siret/index.html.haml similarity index 92% rename from app/views/siret/index.html.haml rename to app/views/users/siret/index.html.haml index 215baf74a..04e760ffc 100644 --- a/app/views/siret/index.html.haml +++ b/app/views/users/siret/index.html.haml @@ -5,5 +5,5 @@ Site de démonstration d’un service public de saisie d’un projet ou de dépôt d’une démarche administrative, auprès d’un ou plusieurs organismes publics, simplifié des informations déjà connues des administrations, grâce à la fourniture du numéro SIRET. .row - = render partial: '/siret/pro' + = render partial: 'pro' diff --git a/config/routes.rb b/config/routes.rb index d63e90db8..b444f1241 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,27 +12,39 @@ Rails.application.routes.draw do # root 'welcome#index' root 'users/dossiers#index' - get 'siret' => 'siret#index' + namespace :users do + get 'siret' => 'siret#index' + resources :dossiers do + get '/description' => 'description#show' + get '/description/error' => 'description#error' + post 'description' => 'description#create' + get '/recapitulatif' => 'recapitulatif#show' + get '/demande' => 'demandes#show' + post '/demande' => 'demandes#update' + post '/commentaire' => 'commentaires#create' + end + resource :dossiers - - resources :dossiers do - get '/demande' => 'demandes#show' - post '/demande' => 'demandes#update' - - get '/carte/position' => 'carte#get_position' - get '/carte' => 'carte#show' - post '/carte' => 'carte#save_ref_api_carto' - - get '/description' => 'description#show' - get '/description/error' => 'description#error' - post 'description' => 'description#create' - - get '/recapitulatif' => 'recapitulatif#show' - - post '/commentaire' => 'commentaires#create' end + # resources :dossiers do + + + # # get '/carte/position' => 'carte#get_position' + # # get '/carte' => 'carte#show' + # # post '/carte' => 'carte#save_ref_api_carto' + + # # get '/description' => 'description#show' + # # get '/description/error' => 'description#error' + # # post 'description' => 'description#create' + + + # post '/commentaire' => 'commentaires#create' + + # end + + get 'backoffice' => 'backoffice#index' namespace :backoffice do diff --git a/spec/controllers/commentaires_controller_spec.rb b/spec/controllers/commentaires_controller_spec.rb index 1bf28edec..2c25cc324 100644 --- a/spec/controllers/commentaires_controller_spec.rb +++ b/spec/controllers/commentaires_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe CommentairesController, type: :controller do +describe Users::CommentairesController, type: :controller do let(:dossier) { create(:dossier) } let(:dossier_id) { dossier.id } let(:email_commentaire) { 'test@test.com' } @@ -10,7 +10,7 @@ describe CommentairesController, type: :controller do context 'création correct d\'un commentaire' do it 'depuis la page récapitulatif' do post :create, dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire - expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif") + expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif") end end end diff --git a/spec/controllers/description_controller_spec.rb b/spec/controllers/description_controller_spec.rb index 1998f2258..30e15193e 100644 --- a/spec/controllers/description_controller_spec.rb +++ b/spec/controllers/description_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe DescriptionController, type: :controller do +describe Users::DescriptionController, type: :controller do let(:dossier) { create(:dossier, :with_procedure) } let(:dossier_id) { dossier.id } let(:bad_dossier_id) { Dossier.count + 10 } @@ -37,7 +37,7 @@ describe DescriptionController, type: :controller do # TODO separer en deux tests : check donnees et check redirect it 'Premier enregistrement des données' do post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle - expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif") + expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif") end # TODO changer les valeurs des champs et check in bdd @@ -63,7 +63,7 @@ describe DescriptionController, type: :controller do end it 'Redirection vers la page récapitulatif' do - expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif") + expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif") end end end diff --git a/spec/controllers/dossiers_controller_spec.rb b/spec/controllers/dossiers_controller_spec.rb index 6c2f5d478..041b25c4f 100644 --- a/spec/controllers/dossiers_controller_spec.rb +++ b/spec/controllers/dossiers_controller_spec.rb @@ -1,124 +1,124 @@ require 'spec_helper' describe DossiersController, type: :controller do - let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } - let(:procedure) { create(:procedure) } - let(:dossier_id) { dossier.id } - let(:siret_not_found) { 999_999_999_999 } + # let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } + # let(:procedure) { create(:procedure) } + # let(:dossier_id) { dossier.id } + # let(:siret_not_found) { 999_999_999_999 } - let(:siren) { dossier.siren } - let(:siret) { dossier.siret } - let(:bad_siret) { 1 } + # let(:siren) { dossier.siren } + # let(:siret) { dossier.siret } + # let(:bad_siret) { 1 } - describe 'GET #show' do - it 'returns http success with dossier_id valid' do - get :show, id: dossier_id - expect(response).to have_http_status(:success) - end + # describe 'GET #show' do + # it 'returns http success with dossier_id valid' do + # get :show, id: dossier_id + # expect(response).to have_http_status(:success) + # end - it 'redirection vers siret si mauvais dossier ID' do - get :show, id: siret_not_found - expect(response).to redirect_to('/siret') - end - end + # it 'redirection vers siret si mauvais dossier ID' do + # get :show, id: siret_not_found + # expect(response).to redirect_to('/siret') + # end + # end - describe 'POST #create' do - before do - stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret_not_found}?token=#{SIADETOKEN}") - .to_return(status: 404, body: 'fake body') + # describe 'POST #create' do + # before do + # stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret_not_found}?token=#{SIADETOKEN}") + # .to_return(status: 404, body: 'fake body') - stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}") - .to_return(status: 200, body: File.read('spec/support/files/etablissement.json')) + # stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}") + # .to_return(status: 200, body: File.read('spec/support/files/etablissement.json')) - stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}") - .to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) - end + # stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}") + # .to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) + # end - describe 'professionnel fills form' do - context 'when pro_dossier_id is empty' do - context 'with valid siret ' do + # describe 'professionnel fills form' do + # context 'when pro_dossier_id is empty' do + # context 'with valid siret ' do - subject { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last } + # subject { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last } - it 'create a dossier' do - expect { subject }.to change { Dossier.count }.by(1) - end + # it 'create a dossier' do + # expect { subject }.to change { Dossier.count }.by(1) + # end - it 'creates entreprise' do - expect { subject }.to change { Entreprise.count }.by(1) - end + # it 'creates entreprise' do + # expect { subject }.to change { Entreprise.count }.by(1) + # end - it 'links entreprise to dossier' do - expect(Entreprise.last.dossier).to eq(Dossier.last) - end + # it 'links entreprise to dossier' do + # expect(Entreprise.last.dossier).to eq(Dossier.last) + # end - it 'creates etablissement for dossier' do - expect { subject }.to change { Etablissement.count }.by(1) - end + # it 'creates etablissement for dossier' do + # expect { subject }.to change { Etablissement.count }.by(1) + # end - it 'links etablissement to dossier' do - subject - expect(Etablissement.last.dossier).to eq(Dossier.last) - end + # it 'links etablissement to dossier' do + # subject + # expect(Etablissement.last.dossier).to eq(Dossier.last) + # end - it 'links etablissement to entreprise' do - subject - expect(Etablissement.last.entreprise).to eq(Entreprise.last) - end + # it 'links etablissement to entreprise' do + # subject + # expect(Etablissement.last.entreprise).to eq(Entreprise.last) + # end - it 'links procedure to dossier' do - subject - expect(Dossier.last.procedure).to eq(Procedure.last) - end + # it 'links procedure to dossier' do + # subject + # expect(Dossier.last.procedure).to eq(Procedure.last) + # end - it 'state of dossier is draft' do - subject - expect(Dossier.last.state).to eq('draft') - end - end + # it 'state of dossier is draft' do + # subject + # expect(Dossier.last.state).to eq('draft') + # end + # end - context 'with non existant siret' do - let(:siret_not_found) { '11111111111111' } - subject { post :create, siret: siret_not_found, pro_dossier_id: '', procedure_id: procedure.id } - it 'does not create new dossier' do - expect { subject }.not_to change { Dossier.count } - end + # context 'with non existant siret' do + # let(:siret_not_found) { '11111111111111' } + # subject { post :create, siret: siret_not_found, pro_dossier_id: '', procedure_id: procedure.id } + # it 'does not create new dossier' do + # expect { subject }.not_to change { Dossier.count } + # end - it 'redirects to show' do - expect(subject).to redirect_to(controller: :siret, procedure_id: procedure.id) - end - end - end - end - end + # it 'redirects to show' do + # expect(subject).to redirect_to(controller: :siret, procedure_id: procedure.id) + # end + # end + # end + # end + # end - describe 'PUT #update' do - before do - put :update, id: dossier_id, dossier: { autorisation_donnees: autorisation_donnees } - end - context 'when Checkbox is checked' do - let(:autorisation_donnees) { '1' } - it 'redirects to demande' do - expect(response).to redirect_to(controller: :description, action: :show, dossier_id: dossier.id) - end + # describe 'PUT #update' do + # before do + # put :update, id: dossier_id, dossier: { autorisation_donnees: autorisation_donnees } + # end + # context 'when Checkbox is checked' do + # let(:autorisation_donnees) { '1' } + # it 'redirects to demande' do + # expect(response).to redirect_to(controller: :description, action: :show, dossier_id: dossier.id) + # end - it 'update dossier' do - dossier.reload - expect(dossier.autorisation_donnees).to be_truthy - end - end + # it 'update dossier' do + # dossier.reload + # expect(dossier.autorisation_donnees).to be_truthy + # end + # end - context 'when Checkbox is not checked' do - let(:autorisation_donnees) { '0' } - it 'uses flash alert to display message' do - expect(flash[:alert]).to have_content('Les conditions sont obligatoires.') - end + # context 'when Checkbox is not checked' do + # let(:autorisation_donnees) { '0' } + # it 'uses flash alert to display message' do + # expect(flash[:alert]).to have_content('Les conditions sont obligatoires.') + # end - it "doesn't update dossier autorisation_donnees" do - dossier.reload - expect(dossier.autorisation_donnees).to be_falsy - end - end - end + # it "doesn't update dossier autorisation_donnees" do + # dossier.reload + # expect(dossier.autorisation_donnees).to be_falsy + # end + # end + # end end diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 6a136ab38..ac6083304 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -14,4 +14,135 @@ describe Users::DossiersController, type: :controller do it { is_expected.to have_http_status(:success) } end end + let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } + let(:procedure) { create(:procedure) } + let(:dossier_id) { dossier.id } + let(:siret_not_found) { 999_999_999_999 } + + let(:siren) { dossier.siren } + let(:siret) { dossier.siret } + let(:bad_siret) { 1 } + + describe 'GET #show' do + before do + sign_in create(:user) + end + it 'returns http success with dossier_id valid' do + get :show, id: dossier_id + expect(response).to have_http_status(:success) + end + + it 'redirection vers siret si mauvais dossier ID' do + get :show, id: siret_not_found + expect(response).to redirect_to('/users/siret') + end + end + + describe 'POST #create' do + before do + stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret_not_found}?token=#{SIADETOKEN}") + .to_return(status: 404, body: 'fake body') + + stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}") + .to_return(status: 200, body: File.read('spec/support/files/etablissement.json')) + + stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}") + .to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) + end + + describe 'professionnel fills form' do + context 'when pro_dossier_id is empty' do + context 'with valid siret ' do + before do + sign_in create(:user) + end + + subject { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last } + + + it 'create a dossier' do + expect { subject }.to change { Dossier.count }.by(1) + end + + it 'creates entreprise' do + expect { subject }.to change { Entreprise.count }.by(1) + end + + it 'links entreprise to dossier' do + expect(Entreprise.last.dossier).to eq(Dossier.last) + end + + it 'creates etablissement for dossier' do + expect { subject }.to change { Etablissement.count }.by(1) + end + + it 'links etablissement to dossier' do + subject + expect(Etablissement.last.dossier).to eq(Dossier.last) + end + + it 'links etablissement to entreprise' do + subject + expect(Etablissement.last.entreprise).to eq(Entreprise.last) + end + + it 'links procedure to dossier' do + subject + expect(Dossier.last.procedure).to eq(Procedure.last) + end + + it 'state of dossier is draft' do + subject + expect(Dossier.last.state).to eq('draft') + end + end + + context 'with non existant siret' do + before do + sign_in create(:user) + end + + let(:siret_not_found) { '11111111111111' } + subject { post :create, siret: siret_not_found, pro_dossier_id: '', procedure_id: procedure.id } + it 'does not create new dossier' do + expect { subject }.not_to change { Dossier.count } + end + + it 'redirects to show' do + expect(subject).to redirect_to(controller: :siret, procedure_id: procedure.id) + end + end + end + end + end + + describe 'PUT #update' do + before do + sign_in create(:user) + put :update, id: dossier_id, dossier: { autorisation_donnees: autorisation_donnees } + end + context 'when Checkbox is checked' do + let(:autorisation_donnees) { '1' } + it 'redirects to demande' do + expect(response).to redirect_to(controller: :description, action: :show, dossier_id: dossier.id) + end + + it 'update dossier' do + dossier.reload + expect(dossier.autorisation_donnees).to be_truthy + end + end + + context 'when Checkbox is not checked' do + let(:autorisation_donnees) { '0' } + it 'uses flash alert to display message' do + expect(flash[:alert]).to have_content('Les conditions sont obligatoires.') + end + + it "doesn't update dossier autorisation_donnees" do + dossier.reload + expect(dossier.autorisation_donnees).to be_falsy + end + end + end end \ No newline at end of file diff --git a/spec/controllers/recapitulatif_controller_spec.rb b/spec/controllers/users/recapitulatif_controller_spec.rb similarity index 53% rename from spec/controllers/recapitulatif_controller_spec.rb rename to spec/controllers/users/recapitulatif_controller_spec.rb index 1d572121a..e40e48804 100644 --- a/spec/controllers/recapitulatif_controller_spec.rb +++ b/spec/controllers/users/recapitulatif_controller_spec.rb @@ -1,11 +1,14 @@ require 'spec_helper' -RSpec.describe RecapitulatifController, type: :controller do - let(:dossier) { create(:dossier) } +describe Users::RecapitulatifController, type: :controller do + let(:dossier) { create(:dossier, :with_user) } - let(:bad_dossier_id) { Dossier.count + 10 } + let(:bad_dossier_id) { Dossier.count + 100000 } describe 'GET #show' do + before do + sign_in dossier.user + end it 'returns http success' do get :show, dossier_id: dossier.id expect(response).to have_http_status(:success) @@ -13,7 +16,7 @@ RSpec.describe RecapitulatifController, type: :controller do it 'redirection vers siret si mauvais dossier ID' do get :show, dossier_id: bad_dossier_id - expect(response).to redirect_to('/siret') + expect(response).to redirect_to('/users/siret') end end end diff --git a/spec/controllers/siret_controller_spec.rb b/spec/controllers/users/siret_controller_spec.rb similarity index 97% rename from spec/controllers/siret_controller_spec.rb rename to spec/controllers/users/siret_controller_spec.rb index e169a8fd7..cf6b48151 100644 --- a/spec/controllers/siret_controller_spec.rb +++ b/spec/controllers/users/siret_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe SiretController, type: :controller do +describe Users::SiretController, type: :controller do let!(:procedure) { create(:procedure) } describe 'GET #index' do diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index 06fb0057b..239fec250 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -16,5 +16,11 @@ FactoryGirl.define do dossier.procedure = procedure end end + + trait :with_user do + after(:build) do |dossier, _evaluator| + dossier.user = create(:user) + end + end end end diff --git a/spec/features/datepicker_spec.rb b/spec/features/datepicker_spec.rb index 46f23c817..c0643a79f 100644 --- a/spec/features/datepicker_spec.rb +++ b/spec/features/datepicker_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' feature 'On the description page' do let!(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } before do - visit dossier_description_path dossier + visit users_dossier_description_path dossier end scenario 'date_previsionnelle field is present' do expect(page).to have_css('#date_previsionnelle') diff --git a/spec/features/description_page/show_page_spec.rb b/spec/features/description_page/show_page_spec.rb index 226db6a9a..132783c21 100644 --- a/spec/features/description_page/show_page_spec.rb +++ b/spec/features/description_page/show_page_spec.rb @@ -5,12 +5,12 @@ feature 'Description#Show Page' do let(:dossier_id) { dossier.id } before do - visit "/dossiers/#{dossier_id}/description" + visit users_dossier_description_path(dossier_id: dossier_id) end context 'tous les attributs sont présents sur la page' do - scenario 'Le formulaire envoie vers /dossiers/:dossier_id/description en #POST' do - expect(page).to have_selector("form[action='/dossiers/#{dossier_id}/description'][method=post]") + scenario 'Le formulaire envoie vers /users/dossiers/:dossier_id/description en #POST' do + expect(page).to have_selector("form[action='/users/dossiers/#{dossier_id}/description'][method=post]") end scenario 'Nom du projet' do @@ -62,7 +62,7 @@ feature 'Description#Show Page' do context 'si la page précédente est recapitularif' do before do - visit "/dossiers/#{dossier_id}/description?back_url=recapitulatif" + visit "/users/dossiers/#{dossier_id}/description?back_url=recapitulatif" end scenario 'le bouton "Terminer" n\'est pas présent' do diff --git a/spec/features/description_page/upload_piece_justificative_spec.rb b/spec/features/description_page/upload_piece_justificative_spec.rb index 92ad922cc..d0333658c 100644 --- a/spec/features/description_page/upload_piece_justificative_spec.rb +++ b/spec/features/description_page/upload_piece_justificative_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' feature 'user is on description page' do let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } before do - visit dossier_description_path dossier + visit users_dossier_description_path dossier end it { expect(page).to have_css('#description_page') } diff --git a/spec/features/recapitulatif_page/_commentaires_flux_spec.rb b/spec/features/recapitulatif_page/_commentaires_flux_spec.rb index 273fa990b..a50437a0c 100644 --- a/spec/features/recapitulatif_page/_commentaires_flux_spec.rb +++ b/spec/features/recapitulatif_page/_commentaires_flux_spec.rb @@ -1,19 +1,20 @@ require 'spec_helper' feature '_Commentaires_Flux Recapitulatif#Show Page' do - let(:dossier) { create(:dossier) } + let(:dossier) { create(:dossier, :with_user) } let(:dossier_id) { dossier.id } let(:email_commentaire) { 'mon_mail_de_commentaire@test.com' } let!(:commentaire) { create(:commentaire, dossier: dossier, email: email_commentaire, body: 'ma super description') } let(:body) { 'Commentaire de test' } before do - visit "/dossiers/#{dossier_id}/recapitulatif" + login_as(dossier.user, scope: :user) + visit "/users/dossiers/#{dossier_id}/recapitulatif" end context 'Affichage du flux de commentaire' do scenario 'l\'email du contact est présent' do - expect(page).to have_selector('span[id=email_contact]') + expect(page).to have_css('#email_contact') end scenario 'la date du commentaire est présent' do @@ -21,13 +22,13 @@ feature '_Commentaires_Flux Recapitulatif#Show Page' do end scenario 'le corps du commentaire est présent' do - expect(page).to have_selector('div[class=description][id=body]') + expect(page).to have_css('.description#body') end end context 'Affichage du formulaire de commentaire' do scenario 'Le formulaire envoie vers /dossiers/:dossier_id/commentaire en #POST' do - expect(page).to have_selector("form[action='/dossiers/#{dossier_id}/commentaire'][method=post]") + expect(page).to have_selector("form[action='/users/dossiers/#{dossier_id}/commentaire'][method=post]") end scenario 'Champs de texte' do diff --git a/spec/features/recapitulatif_page/show_page_spec.rb b/spec/features/recapitulatif_page/show_page_spec.rb index f5959a26d..2b0d739c5 100644 --- a/spec/features/recapitulatif_page/show_page_spec.rb +++ b/spec/features/recapitulatif_page/show_page_spec.rb @@ -1,12 +1,13 @@ require 'spec_helper' feature 'Recapitulatif#Show Page' do - let(:dossier) { create(:dossier) } + let(:dossier) { create(:dossier, :with_user) } let(:dossier_id) { dossier.id } before do Capybara.current_session.driver.header('Referer', '/description') - visit "/dossiers/#{dossier_id}/recapitulatif" + login_as(dossier.user, :scope => :user) + visit "/users/dossiers/#{dossier_id}/recapitulatif" end context 'sur la page recapitulative' do @@ -42,14 +43,14 @@ feature 'Recapitulatif#Show Page' do scenario 'N\'est pas affiché quand l\'on vient d\'une autre la page que description' do Capybara.current_session.driver.header('Referer', '/') - visit "/dossiers/#{dossier_id}/recapitulatif" + visit "/users/dossiers/#{dossier_id}/recapitulatif" expect(page).to_not have_content('Félicitation') end scenario 'N\'est pas affiché quand l\'on vient de la page description en modification' do Capybara.current_session.driver.header('Referer', '/description?back_url=recapitulatif') - visit "/dossiers/#{dossier_id}/recapitulatif" + visit "/users/dossiers/#{dossier_id}/recapitulatif" expect(page).to_not have_content('Félicitation') end diff --git a/spec/features/users/start_demande_spec.rb b/spec/features/users/start_demande_spec.rb index 1da39fcc2..b1ac18d06 100644 --- a/spec/features/users/start_demande_spec.rb +++ b/spec/features/users/start_demande_spec.rb @@ -7,7 +7,7 @@ feature 'user arrive on siret page' do let(:siren) { siret[0...9] } context 'when user is not logged in' do before do - visit siret_path(procedure_id: procedure.id) + visit users_siret_path(procedure_id: procedure.id) end scenario 'he is redirected to login page' do expect(page).to have_css('#login_user') diff --git a/spec/views/dossiers/show.html.haml_spec.rb b/spec/views/dossiers/show.html.haml_spec.rb index bd53a278a..c5820f8d7 100644 --- a/spec/views/dossiers/show.html.haml_spec.rb +++ b/spec/views/dossiers/show.html.haml_spec.rb @@ -14,20 +14,20 @@ describe 'dossiers/show.html.haml', type: :view do expect(rendered).to have_css('#dossier_autorisation_donnees') end - context 'sur la page d\'information d\'un SIRET' do - it 'Le formulaire envoie vers /dossiers/:dossier_id en #POST' do - expect(rendered).to have_selector("form[action='/dossiers/#{dossier.id}'][method=post]") + context "sur la page d'information d'un SIRET" do + it 'Le formulaire envoie vers /users/dossiers/:dossier_id en #POST' do + expect(rendered).to have_selector("form[action='/users/dossiers'][method=post]") end - it 'la checkbox d\'information est présente' do + it "la checkbox d'information est présente" do expect(rendered).to have_css('#dossier_autorisation_donnees') end - it 'le texte d\'information des droits est correct' do + it "le texte d'information des droits est correct" do expect(rendered).to have_content("J'autorise les organismes publics à vérifier les informations de mon entreprise auprès des administrations concernées. Ces informations resteront strictement confidentielles.") end - it 'les informations de l\'entreprise sont présents' do + it "les informations de l'entreprise sont présents" do expect(rendered).to have_content('Siret') end diff --git a/spec/views/siret/index.html.haml_spec.rb b/spec/views/users/siret/index.html.haml_spec.rb similarity index 87% rename from spec/views/siret/index.html.haml_spec.rb rename to spec/views/users/siret/index.html.haml_spec.rb index 9d27ae043..5740ac7af 100644 --- a/spec/views/siret/index.html.haml_spec.rb +++ b/spec/views/users/siret/index.html.haml_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'siret/index.html.haml', type: :view do +describe 'users/siret/index.html.haml', type: :view do let(:procedure) { create(:procedure, libelle: 'Demande de subvention') } before do assign(:procedure, procedure) @@ -13,7 +13,7 @@ describe 'siret/index.html.haml', type: :view do context 'dans la section professionnel' do it 'le formulaire envoie vers /dossiers en #POST' do - expect(rendered).to have_selector("form[action='/dossiers'][method=post]") + expect(rendered).to have_selector("form[action='/users/dossiers'][method=post]") end it 'le champs "Numéro SIRET" est présent' do From 6eeac88c95dce079195f596e05a7e652fd9720c9 Mon Sep 17 00:00:00 2001 From: Tanguy PATTE Date: Thu, 24 Sep 2015 10:30:29 +0200 Subject: [PATCH 7/7] fix user path and add test full user path --- app/views/dossiers/_show.html.haml | 2 +- app/views/users/recapitulatif/show.html.haml | 3 +- spec/features/users/complete_demande_spec.rb | 63 ++++++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 spec/features/users/complete_demande_spec.rb diff --git a/app/views/dossiers/_show.html.haml b/app/views/dossiers/_show.html.haml index d8cff59a9..2ffdf472d 100644 --- a/app/views/dossiers/_show.html.haml +++ b/app/views/dossiers/_show.html.haml @@ -5,7 +5,7 @@ %div.row = render partial: '/dossiers/infos_entreprise' %br - = form_for @dossier, url: { controller: '/users/dossiers', action: :create } do |f| + = form_for @dossier, url: { controller: '/users/dossiers', action: :update } do |f| %label{ style:'font-weight:normal' } = f.check_box :autorisation_donnees J'autorise les organismes publics à vérifier les informations de mon entreprise auprès des administrations concernées. Ces informations resteront strictement confidentielles. diff --git a/app/views/users/recapitulatif/show.html.haml b/app/views/users/recapitulatif/show.html.haml index 571490579..96d1e714f 100644 --- a/app/views/users/recapitulatif/show.html.haml +++ b/app/views/users/recapitulatif/show.html.haml @@ -1,5 +1,4 @@ -%h2 - ='Récapitulatif' +%h2#recap_dossier Récapitulatif %div{style: 'text-align:center'} -if request.referer != nil diff --git a/spec/features/users/complete_demande_spec.rb b/spec/features/users/complete_demande_spec.rb new file mode 100644 index 000000000..7931177b0 --- /dev/null +++ b/spec/features/users/complete_demande_spec.rb @@ -0,0 +1,63 @@ +require 'spec_helper' + +feature 'user path for dossier creation' do + let(:user) { create(:user) } + let(:procedure) { create(:procedure) } + let(:siret) { '53272417600013' } + let(:siren) { siret[0...9] } + context 'user arrives on siret page' do + before do + visit users_siret_path(procedure_id: procedure.id) + end + + scenario 'he is redirected on login page' do + expect(page).to have_css('#login_user') + end + + context 'user sign_in' do + before do + page.find_by_id('user_email').set user.email + page.find_by_id('user_password').set user.password + page.click_on 'Se connecter' + end + scenario 'redirects to siret page' do + expect(page).to have_css('#siret') + end + context 'sets siret' do + before do + stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}") + .to_return(body: File.read('spec/support/files/etablissement.json', status: 200)) + stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}") + .to_return(status: 200, body: File.read('spec/support/files/entreprise.json')) + page.find_by_id('siret').set siret + page.click_on 'Commencer' + end + scenario 'user is on page recap info entreprise' do + expect(page).to have_css('#recap_info_entreprise') + end + context 'when validating info entreprise recap page' do + before do + page.check('dossier_autorisation_donnees') + page.click_on 'Etape suivante' + end + scenario 'user is on description page' do + expect(page).to have_css('#description_page') + end + context 'user fill and validate description page' do + before do + page.find_by_id('nom_projet').set 'Mon super projet' + page.find_by_id('description').set 'Ma super description' + page.find_by_id('montant_projet').set 10_000 + page.find_by_id('montant_aide_demande').set 1_000 + page.find_by_id('date_previsionnelle').set '09/09/2015' + page.click_on 'Terminer la procédure' + end + scenario 'user is on recap page' do + expect(page).to have_css('#recap_dossier') + end + end + end + end + end + end +end \ No newline at end of file