From 4145ab56515a62721c9322d58c8a80ffabc037bc Mon Sep 17 00:00:00 2001 From: Mateus Furquim Date: Thu, 12 May 2016 16:46:23 -0300 Subject: [PATCH 01/98] =?UTF-8?q?Copyright=20de=20eLugar,=20e=20n=C3=A3o?= =?UTF-8?q?=20mdsgpp2016.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index cf12331..8f97ff7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 mdsgpp20161 +Copyright (c) 2016 eLugar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 36755c62838e76fe7e871fb855878961dc4a78f3 Mon Sep 17 00:00:00 2001 From: MasterCaio Date: Fri, 27 May 2016 13:11:41 -0300 Subject: [PATCH 02/98] =?UTF-8?q?Inserindo=20bot=C3=A3o=20de=20curtir=20e?= =?UTF-8?q?=20compartilhar=20nas=20p=C3=A1ginas=20de=20cada=20cidade=20Sig?= =?UTF-8?q?ned-off-by:=20Gustavo=20=20Signed-of?= =?UTF-8?q?f-by:=20Caio=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helpers/application_helper.rb | 0 app/{ => models}/helpers/cities_helper.rb | 0 .../helpers/static_pages_helper.rb | 0 app/views/cities/show.html.erb | 44 ++++++++++++------- 4 files changed, 27 insertions(+), 17 deletions(-) rename app/{ => models}/helpers/application_helper.rb (100%) rename app/{ => models}/helpers/cities_helper.rb (100%) rename app/{ => models}/helpers/static_pages_helper.rb (100%) diff --git a/app/helpers/application_helper.rb b/app/models/helpers/application_helper.rb similarity index 100% rename from app/helpers/application_helper.rb rename to app/models/helpers/application_helper.rb diff --git a/app/helpers/cities_helper.rb b/app/models/helpers/cities_helper.rb similarity index 100% rename from app/helpers/cities_helper.rb rename to app/models/helpers/cities_helper.rb diff --git a/app/helpers/static_pages_helper.rb b/app/models/helpers/static_pages_helper.rb similarity index 100% rename from app/helpers/static_pages_helper.rb rename to app/models/helpers/static_pages_helper.rb diff --git a/app/views/cities/show.html.erb b/app/views/cities/show.html.erb index fd663d8..8739700 100644 --- a/app/views/cities/show.html.erb +++ b/app/views/cities/show.html.erb @@ -18,16 +18,20 @@ - - - - + - + + +
+ + - + +
@@ -86,7 +90,7 @@




<%=@hash[attr_name]%>

- <%if(attr_name == 'population' || attr_name == 'area')%> + <%if(attr_name == 'population' || attr_name == 'area')%> <%else%> > <%end%> @@ -98,14 +102,21 @@

<%=@hashValue[attr_name]%>

- + <% end %> <% end %> - <%= link_to "Voltar", find_path(:id => nil), :class => "btn btn-default" %>   - <%= link_to "Compare", compare_path(:id => @oldID), :class => "btn btn-primary" %> +
+ <%= link_to "Voltar", find_path(:id => nil), :class => "btn btn-default" %>   + <%= link_to "Compare", compare_path(:id => @oldID), :class => "btn btn-primary" %> + <%= form_tag(cities_show_path, :method => :get) do %> +
+


+
+ <%end%> +
@@ -114,7 +125,6 @@
-
-
- \ No newline at end of file + + From 1de49f6d9379e4d6849f89b974901604ac10562f Mon Sep 17 00:00:00 2001 From: Harrison Date: Sat, 28 May 2016 11:10:27 -0300 Subject: [PATCH 03/98] Preparando ambiente para criacao do Usuario, gems, model e controller. --- Gemfile | 4 + Gemfile.lock | 46 ++++ app/assets/javascripts/users.coffee | 3 + app/assets/stylesheets/users.scss | 3 + app/controllers/users_controller.rb | 4 + app/helpers/users_helper.rb | 2 + app/models/user.rb | 2 + app/views/users/new.html.erb | 2 + config/environments/development.rb | 1 + config/initializers/devise.rb | 268 ++++++++++++++++++++++ config/locales/devise.en.yml | 62 +++++ config/routes.rb | 4 +- db/migrate/20160528140605_create_users.rb | 12 + db/schema.rb | 11 +- spec/controllers/users_controller_spec.rb | 12 + spec/factories/users.rb | 8 + spec/helpers/users_helper_spec.rb | 15 ++ spec/models/user_spec.rb | 5 + spec/rails_helper.rb | 58 +++++ spec/spec_helper.rb | 92 ++++++++ spec/views/users/new.html.erb_spec.rb | 5 + 21 files changed, 617 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/users.coffee create mode 100644 app/assets/stylesheets/users.scss create mode 100644 app/controllers/users_controller.rb create mode 100644 app/helpers/users_helper.rb create mode 100644 app/models/user.rb create mode 100644 app/views/users/new.html.erb create mode 100644 config/initializers/devise.rb create mode 100644 config/locales/devise.en.yml create mode 100644 db/migrate/20160528140605_create_users.rb create mode 100644 spec/controllers/users_controller_spec.rb create mode 100644 spec/factories/users.rb create mode 100644 spec/helpers/users_helper_spec.rb create mode 100644 spec/models/user_spec.rb create mode 100644 spec/rails_helper.rb create mode 100644 spec/spec_helper.rb create mode 100644 spec/views/users/new.html.erb_spec.rb diff --git a/Gemfile b/Gemfile index 01dc13c..55ddaed 100644 --- a/Gemfile +++ b/Gemfile @@ -36,6 +36,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' + gem 'factory_girl_rails' end gem 'simplecov', :require => false, :group => :test @@ -43,6 +44,7 @@ gem 'simplecov', :require => false, :group => :test group :development do # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' + gem "rspec" gem 'bootstrap-sass', '~>3.2.0' gem 'autoprefixer-rails' @@ -50,3 +52,5 @@ group :development do gem 'spring' end +gem "rspec-rails", :group => [:development, :test] +gem 'devise' diff --git a/Gemfile.lock b/Gemfile.lock index 97746fe..d0bfb4b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,6 +39,7 @@ GEM arel (6.0.3) autoprefixer-rails (6.3.6) execjs + bcrypt (3.1.11) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) bootstrap-sass (3.2.0.2) @@ -56,9 +57,21 @@ GEM coffee-script-source (1.10.0) concurrent-ruby (1.0.1) debug_inspector (0.0.2) + devise (4.1.1) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0, < 5.1) + responders + warden (~> 1.2.3) + diff-lcs (1.2.5) docile (1.1.5) erubis (2.7.0) execjs (2.6.0) + factory_girl (4.7.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.7.0) + factory_girl (~> 4.7.0) + railties (>= 3.0.0) globalid (0.3.6) activesupport (>= 4.1.0) i18n (0.7.0) @@ -82,6 +95,7 @@ GEM multi_json (1.11.2) nokogiri (1.6.7.2) mini_portile2 (~> 2.0.0.rc2) + orm_adapter (0.5.0) rack (1.6.4) rack-test (0.6.3) rack (>= 1.0) @@ -112,6 +126,29 @@ GEM rake (11.1.2) rdoc (4.2.2) json (~> 1.4) + responders (2.2.0) + railties (>= 4.2.0, < 5.1) + rspec (3.4.0) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) + rspec-core (3.4.4) + rspec-support (~> 3.4.0) + rspec-expectations (3.4.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-mocks (3.4.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.4.0) + rspec-rails (3.4.2) + actionpack (>= 3.0, < 4.3) + activesupport (>= 3.0, < 4.3) + railties (>= 3.0, < 4.3) + rspec-core (~> 3.4.0) + rspec-expectations (~> 3.4.0) + rspec-mocks (~> 3.4.0) + rspec-support (~> 3.4.0) + rspec-support (3.4.1) sass (3.4.22) sass-rails (5.0.4) railties (>= 4.0.0, < 5.0) @@ -145,6 +182,8 @@ GEM thread_safe (~> 0.1) uglifier (3.0.0) execjs (>= 0.3.0, < 3) + warden (1.2.6) + rack (>= 1.0) web-console (2.3.0) activemodel (>= 4.0) binding_of_caller (>= 0.7.2) @@ -161,9 +200,13 @@ DEPENDENCIES bootstrap-will_paginate (= 0.0.10) byebug coffee-rails (~> 4.1.0) + devise + factory_girl_rails jbuilder (~> 2.0) jquery-rails rails (= 4.2.6) + rspec + rspec-rails sass-rails (~> 5.0) sdoc (~> 0.4.0) simplecov @@ -173,3 +216,6 @@ DEPENDENCIES uglifier (>= 1.3.0) web-console (~> 2.0) will_paginate + +BUNDLED WITH + 1.12.3 diff --git a/app/assets/javascripts/users.coffee b/app/assets/javascripts/users.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/users.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss new file mode 100644 index 0000000..31a2eac --- /dev/null +++ b/app/assets/stylesheets/users.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Users controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000..2ec9ecc --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,4 @@ +class UsersController < ApplicationController + def new + end +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 0000000..2310a24 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,2 @@ +module UsersHelper +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..4a57cf0 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,2 @@ +class User < ActiveRecord::Base +end diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 0000000..c21a1ad --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,2 @@ +

Users#new

+

Find me in app/views/users/new.html.erb

diff --git a/config/environments/development.rb b/config/environments/development.rb index b55e214..24a3245 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -38,4 +38,5 @@ # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + config.action_mailer.default_url_options = { :host => 'localhost:3000' } end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb new file mode 100644 index 0000000..fa60c59 --- /dev/null +++ b/config/initializers/devise.rb @@ -0,0 +1,268 @@ +# Use this hook to configure devise mailer, warden hooks and so forth. +# Many of these configuration options can be set straight in your model. +Devise.setup do |config| + # The secret key used by Devise. Devise uses this key to generate + # random tokens. Changing this key will render invalid all existing + # confirmation, reset password and unlock tokens in the database. + # Devise will use the `secret_key_base` as its `secret_key` + # by default. You can change it below and use your own secret key. + # config.secret_key = 'd3147ed3b4c8706c63e0fde09a600274e6b3006652a6c3985b318ea2b3a84019696aa114d6bbc2bc04ac02dfad27a38f9936cd24f45b79c4a41d197c848f7a6a' + + # ==> Mailer Configuration + # Configure the e-mail address which will be shown in Devise::Mailer, + # note that it will be overwritten if you use your own mailer class + # with default "from" parameter. + config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' + + # Configure the class responsible to send e-mails. + # config.mailer = 'Devise::Mailer' + + # Configure the parent class responsible to send e-mails. + # config.parent_mailer = 'ActionMailer::Base' + + # ==> ORM configuration + # Load and configure the ORM. Supports :active_record (default) and + # :mongoid (bson_ext recommended) by default. Other ORMs may be + # available as additional gems. + require 'devise/orm/active_record' + + # ==> Configuration for any authentication mechanism + # Configure which keys are used when authenticating a user. The default is + # just :email. You can configure it to use [:username, :subdomain], so for + # authenticating a user, both parameters are required. Remember that those + # parameters are used only when authenticating and not when retrieving from + # session. If you need permissions, you should implement that in a before filter. + # You can also supply a hash where the value is a boolean determining whether + # or not authentication should be aborted when the value is not present. + # config.authentication_keys = [:email] + + # Configure parameters from the request object used for authentication. Each entry + # given should be a request method and it will automatically be passed to the + # find_for_authentication method and considered in your model lookup. For instance, + # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. + # The same considerations mentioned for authentication_keys also apply to request_keys. + # config.request_keys = [] + + # Configure which authentication keys should be case-insensitive. + # These keys will be downcased upon creating or modifying a user and when used + # to authenticate or find a user. Default is :email. + config.case_insensitive_keys = [:email] + + # Configure which authentication keys should have whitespace stripped. + # These keys will have whitespace before and after removed upon creating or + # modifying a user and when used to authenticate or find a user. Default is :email. + config.strip_whitespace_keys = [:email] + + # Tell if authentication through request.params is enabled. True by default. + # It can be set to an array that will enable params authentication only for the + # given strategies, for example, `config.params_authenticatable = [:database]` will + # enable it only for database (email + password) authentication. + # config.params_authenticatable = true + + # Tell if authentication through HTTP Auth is enabled. False by default. + # It can be set to an array that will enable http authentication only for the + # given strategies, for example, `config.http_authenticatable = [:database]` will + # enable it only for database authentication. The supported strategies are: + # :database = Support basic authentication with authentication key + password + # config.http_authenticatable = false + + # If 401 status code should be returned for AJAX requests. True by default. + # config.http_authenticatable_on_xhr = true + + # The realm used in Http Basic Authentication. 'Application' by default. + # config.http_authentication_realm = 'Application' + + # It will change confirmation, password recovery and other workflows + # to behave the same regardless if the e-mail provided was right or wrong. + # Does not affect registerable. + # config.paranoid = true + + # By default Devise will store the user in session. You can skip storage for + # particular strategies by setting this option. + # Notice that if you are skipping storage for all authentication paths, you + # may want to disable generating routes to Devise's sessions controller by + # passing skip: :sessions to `devise_for` in your config/routes.rb + config.skip_session_storage = [:http_auth] + + # By default, Devise cleans up the CSRF token on authentication to + # avoid CSRF token fixation attacks. This means that, when using AJAX + # requests for sign in and sign up, you need to get a new CSRF token + # from the server. You can disable this option at your own risk. + # config.clean_up_csrf_token_on_authentication = true + + # ==> Configuration for :database_authenticatable + # For bcrypt, this is the cost for hashing the password and defaults to 11. If + # using other algorithms, it sets how many times you want the password to be hashed. + # + # Limiting the stretches to just one in testing will increase the performance of + # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use + # a value less than 10 in other environments. Note that, for bcrypt (the default + # algorithm), the cost increases exponentially with the number of stretches (e.g. + # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). + config.stretches = Rails.env.test? ? 1 : 11 + + # Set up a pepper to generate the hashed password. + # config.pepper = 'cb3ec4ecad44c943f42d5f9b105a39627584eeeeccf0f1e85e94dbdef6f7119604147554ee0bcdf91c56711d1fc545d8c264a6246c56aa38c95be7af7873bb30' + + # Send a notification email when the user's password is changed + # config.send_password_change_notification = false + + # ==> Configuration for :confirmable + # A period that the user is allowed to access the website even without + # confirming their account. For instance, if set to 2.days, the user will be + # able to access the website for two days without confirming their account, + # access will be blocked just in the third day. Default is 0.days, meaning + # the user cannot access the website without confirming their account. + # config.allow_unconfirmed_access_for = 2.days + + # A period that the user is allowed to confirm their account before their + # token becomes invalid. For example, if set to 3.days, the user can confirm + # their account within 3 days after the mail was sent, but on the fourth day + # their account can't be confirmed with the token any more. + # Default is nil, meaning there is no restriction on how long a user can take + # before confirming their account. + # config.confirm_within = 3.days + + # If true, requires any email changes to be confirmed (exactly the same way as + # initial account confirmation) to be applied. Requires additional unconfirmed_email + # db field (see migrations). Until confirmed, new email is stored in + # unconfirmed_email column, and copied to email column on successful confirmation. + config.reconfirmable = true + + # Defines which key will be used when confirming an account + # config.confirmation_keys = [:email] + + # ==> Configuration for :rememberable + # The time the user will be remembered without asking for credentials again. + # config.remember_for = 2.weeks + + # Invalidates all the remember me tokens when the user signs out. + config.expire_all_remember_me_on_sign_out = true + + # If true, extends the user's remember period when remembered via cookie. + # config.extend_remember_period = false + + # Options to be passed to the created cookie. For instance, you can set + # secure: true in order to force SSL only cookies. + # config.rememberable_options = {} + + # ==> Configuration for :validatable + # Range for password length. + config.password_length = 6..128 + + # Email regex used to validate email formats. It simply asserts that + # one (and only one) @ exists in the given string. This is mainly + # to give user feedback and not to assert the e-mail validity. + config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ + + # ==> Configuration for :timeoutable + # The time you want to timeout the user session without activity. After this + # time the user will be asked for credentials again. Default is 30 minutes. + # config.timeout_in = 30.minutes + + # ==> Configuration for :lockable + # Defines which strategy will be used to lock an account. + # :failed_attempts = Locks an account after a number of failed attempts to sign in. + # :none = No lock strategy. You should handle locking by yourself. + # config.lock_strategy = :failed_attempts + + # Defines which key will be used when locking and unlocking an account + # config.unlock_keys = [:email] + + # Defines which strategy will be used to unlock an account. + # :email = Sends an unlock link to the user email + # :time = Re-enables login after a certain amount of time (see :unlock_in below) + # :both = Enables both strategies + # :none = No unlock strategy. You should handle unlocking by yourself. + # config.unlock_strategy = :both + + # Number of authentication tries before locking an account if lock_strategy + # is failed attempts. + # config.maximum_attempts = 20 + + # Time interval to unlock the account if :time is enabled as unlock_strategy. + # config.unlock_in = 1.hour + + # Warn on the last attempt before the account is locked. + # config.last_attempt_warning = true + + # ==> Configuration for :recoverable + # + # Defines which key will be used when recovering the password for an account + # config.reset_password_keys = [:email] + + # Time interval you can reset your password with a reset password key. + # Don't put a too small interval or your users won't have the time to + # change their passwords. + config.reset_password_within = 6.hours + + # When set to false, does not sign a user in automatically after their password is + # reset. Defaults to true, so a user is signed in automatically after a reset. + # config.sign_in_after_reset_password = true + + # ==> Configuration for :encryptable + # Allow you to use another hashing or encryption algorithm besides bcrypt (default). + # You can use :sha1, :sha512 or algorithms from others authentication tools as + # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20 + # for default behavior) and :restful_authentication_sha1 (then you should set + # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper). + # + # Require the `devise-encryptable` gem when using anything other than bcrypt + # config.encryptor = :sha512 + + # ==> Scopes configuration + # Turn scoped views on. Before rendering "sessions/new", it will first check for + # "users/sessions/new". It's turned off by default because it's slower if you + # are using only default views. + # config.scoped_views = false + + # Configure the default scope given to Warden. By default it's the first + # devise role declared in your routes (usually :user). + # config.default_scope = :user + + # Set this configuration to false if you want /users/sign_out to sign out + # only the current scope. By default, Devise signs out all scopes. + # config.sign_out_all_scopes = true + + # ==> Navigation configuration + # Lists the formats that should be treated as navigational. Formats like + # :html, should redirect to the sign in page when the user does not have + # access, but formats like :xml or :json, should return 401. + # + # If you have any extra navigational formats, like :iphone or :mobile, you + # should add them to the navigational formats lists. + # + # The "*/*" below is required to match Internet Explorer requests. + # config.navigational_formats = ['*/*', :html] + + # The default HTTP method used to sign out a resource. Default is :delete. + config.sign_out_via = :delete + + # ==> OmniAuth + # Add a new OmniAuth provider. Check the wiki for more information on setting + # up on your models and hooks. + # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' + + # ==> Warden configuration + # If you want to use other strategies, that are not supported by Devise, or + # change the failure app, you can configure them inside the config.warden block. + # + # config.warden do |manager| + # manager.intercept_401 = false + # manager.default_strategies(scope: :user).unshift :some_external_strategy + # end + + # ==> Mountable engine configurations + # When using Devise inside an engine, let's call it `MyEngine`, and this engine + # is mountable, there are some extra configurations to be taken into account. + # The following options are available, assuming the engine is mounted as: + # + # mount MyEngine, at: '/my_engine' + # + # The router that invoked `devise_for`, in the example above, would be: + # config.router_name = :my_engine + # + # When using OmniAuth, Devise cannot automatically set OmniAuth path, + # so you need to do it manually. For the users scope, it would be: + # config.omniauth_path_prefix = '/my_engine/users/auth' +end diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml new file mode 100644 index 0000000..bd4c3eb --- /dev/null +++ b/config/locales/devise.en.yml @@ -0,0 +1,62 @@ +# Additional translations at https://github.com/plataformatec/devise/wiki/I18n + +en: + devise: + confirmations: + confirmed: "Your email address has been successfully confirmed." + send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes." + failure: + already_authenticated: "You are already signed in." + inactive: "Your account is not activated yet." + invalid: "Invalid %{authentication_keys} or password." + locked: "Your account is locked." + last_attempt: "You have one more attempt before your account is locked." + not_found_in_database: "Invalid %{authentication_keys} or password." + timeout: "Your session expired. Please sign in again to continue." + unauthenticated: "You need to sign in or sign up before continuing." + unconfirmed: "You have to confirm your email address before continuing." + mailer: + confirmation_instructions: + subject: "Confirmation instructions" + reset_password_instructions: + subject: "Reset password instructions" + unlock_instructions: + subject: "Unlock instructions" + password_change: + subject: "Password Changed" + omniauth_callbacks: + failure: "Could not authenticate you from %{kind} because \"%{reason}\"." + success: "Successfully authenticated from %{kind} account." + passwords: + no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." + send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes." + send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." + updated: "Your password has been changed successfully. You are now signed in." + updated_not_active: "Your password has been changed successfully." + registrations: + destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon." + signed_up: "Welcome! You have signed up successfully." + signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." + signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." + signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account." + update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address." + updated: "Your account has been updated successfully." + sessions: + signed_in: "Signed in successfully." + signed_out: "Signed out successfully." + already_signed_out: "Signed out successfully." + unlocks: + send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes." + send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes." + unlocked: "Your account has been unlocked successfully. Please sign in to continue." + errors: + messages: + already_confirmed: "was already confirmed, please try signing in" + confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" + expired: "has expired, please request a new one" + not_found: "not found" + not_locked: "was not locked" + not_saved: + one: "1 error prohibited this %{resource} from being saved:" + other: "%{count} errors prohibited this %{resource} from being saved:" diff --git a/config/routes.rb b/config/routes.rb index 6bd7935..1ddf9b4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,12 @@ Rails.application.routes.draw do + get 'users/new' + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". # You can have the root of your site routed with "root" resources :cities - + resources :users root 'cities#index' get 'index' => 'cities#index' diff --git a/db/migrate/20160528140605_create_users.rb b/db/migrate/20160528140605_create_users.rb new file mode 100644 index 0000000..a9d7d62 --- /dev/null +++ b/db/migrate/20160528140605_create_users.rb @@ -0,0 +1,12 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :name + t.string :email + t.string :access_token + t.string :uid + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index e04e102..9966bf3 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: 20160416180038) do +ActiveRecord::Schema.define(version: 20160528140605) do create_table "cities", force: :cascade do |t| t.string "name" @@ -29,4 +29,13 @@ t.datetime "updated_at", null: false end + create_table "users", force: :cascade do |t| + t.string "name" + t.string "email" + t.string "access_token" + t.string "uid" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb new file mode 100644 index 0000000..0a86999 --- /dev/null +++ b/spec/controllers/users_controller_spec.rb @@ -0,0 +1,12 @@ +require 'rails_helper' + +RSpec.describe UsersController, type: :controller do + + describe "GET #new" do + it "returns http success" do + get :new + expect(response).to have_http_status(:success) + end + end + +end diff --git a/spec/factories/users.rb b/spec/factories/users.rb new file mode 100644 index 0000000..2086206 --- /dev/null +++ b/spec/factories/users.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :user do + name "MyString" + email "MyString" + access_token "MyString" + uid "MyString" + end +end diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb new file mode 100644 index 0000000..b2e3444 --- /dev/null +++ b/spec/helpers/users_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the UsersHelper. For example: +# +# describe UsersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe UsersHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..47a31bb --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe User, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..a4e30f0 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,58 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +# Prevent database truncation if the environment is production +abort("The Rails environment is running in production mode!") if Rails.env.production? +require 'spec_helper' +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } + +# Checks for pending migration and applies them before tests are run. +# If you are not using ActiveRecord, you can remove this line. +ActiveRecord::Migration.maintain_test_schema! + +RSpec.configure do |config| + config.include FactoryGirl::Syntax::Methods + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/fixtures" + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, remove the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..61e2738 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,92 @@ +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end diff --git a/spec/views/users/new.html.erb_spec.rb b/spec/views/users/new.html.erb_spec.rb new file mode 100644 index 0000000..47b47d3 --- /dev/null +++ b/spec/views/users/new.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe "users/new.html.erb", type: :view do + pending "add some examples to (or delete) #{__FILE__}" +end From 9056b150d9c4b3b881e198a27c732bb77678850c Mon Sep 17 00:00:00 2001 From: Harrison Date: Sat, 28 May 2016 14:12:50 -0300 Subject: [PATCH 04/98] Restricoes e requerimentos concluidos e testados. --- app/models/user.rb | 6 ++ ...0528154503_add_password_digest_to_users.rb | 5 ++ db/schema.rb | 7 ++- spec/factories/users.rb | 10 +-- spec/helpers/users_helper_spec.rb | 4 +- spec/models/user_spec.rb | 63 ++++++++++++++++++- spec/views/users/new.html.erb_spec.rb | 3 - 7 files changed, 82 insertions(+), 16 deletions(-) create mode 100644 db/migrate/20160528154503_add_password_digest_to_users.rb diff --git a/app/models/user.rb b/app/models/user.rb index 4a57cf0..abea803 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,2 +1,8 @@ class User < ActiveRecord::Base + before_save {self.email = self.email.downcase} #self significa o usuario atual (current_user) + validates :name, presence: true, length: { maximum: 50 } + VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i + validates :email, presence:true, format: {with: VALID_EMAIL_REGEX}, uniqueness: { case_sensitive: false } + has_secure_password + validates :password, presence: true, length: { minimum: 6 } end diff --git a/db/migrate/20160528154503_add_password_digest_to_users.rb b/db/migrate/20160528154503_add_password_digest_to_users.rb new file mode 100644 index 0000000..7ad1f62 --- /dev/null +++ b/db/migrate/20160528154503_add_password_digest_to_users.rb @@ -0,0 +1,5 @@ +class AddPasswordDigestToUsers < ActiveRecord::Migration + def change + add_column :users, :password_digest, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 9966bf3..0ba1e4c 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: 20160528140605) do +ActiveRecord::Schema.define(version: 20160528154503) do create_table "cities", force: :cascade do |t| t.string "name" @@ -34,8 +34,9 @@ t.string "email" t.string "access_token" t.string "uid" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "password_digest" end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 2086206..b3e4e09 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,8 +1,10 @@ FactoryGirl.define do factory :user do - name "MyString" - email "MyString" - access_token "MyString" - uid "MyString" + name "Harrison" + email "hpedro1195@gmail.com" + password "123456" + password_confirmation "123456" + # access_token "MyString" + #uid "MyString" end end diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb index b2e3444..988737f 100644 --- a/spec/helpers/users_helper_spec.rb +++ b/spec/helpers/users_helper_spec.rb @@ -10,6 +10,4 @@ # end # end # end -RSpec.describe UsersHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end + diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 47a31bb..f98192d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,5 +1,62 @@ require 'rails_helper' +describe User do + before :each do + @user = User.new + @user.name = "Harrison" + @user.email = "hpedro1195@gmail.com" + end -RSpec.describe User, type: :model do - pending "add some examples to (or delete) #{__FILE__}" -end + + it 'is a valid user' do + expect(build(:user)).to be_valid + end + + it "name should be present" do + expect(build(:user,name: nil)).not_to be_valid + end + + + it "email should be present" do + expect(build(:user, email:nil)).not_to be_valid + end + + + + it "name should not be too long" do + expect(build(:user, name: "a"*51)).not_to be_valid + end + + + + it "email should not be valid" do + expect(build(:user, email: "pedro123,com")).not_to be_valid + end + + + + it "email should be valid" do + expect(build(:user, email: "pedro123@gmail.com")).to be_valid + end + + + + it "email should be unique" do + user2 = @user.dup + user2.email = @user.email.upcase + @user.save + expect(user2).not_to be_valid + end + + it "password confirmation must match password" do + expect(build(:user, password_confirmation: "123456")).to be_valid + end + + it "password should not be blank" do + expect(build(:user, password: ""*6)).not_to be_valid + end + it "password should has atleast 6 chars" do + expect(build(:user, password: "12345", password_confirmation: "12345")).not_to be_valid + end + + +end \ No newline at end of file diff --git a/spec/views/users/new.html.erb_spec.rb b/spec/views/users/new.html.erb_spec.rb index 47b47d3..b66640f 100644 --- a/spec/views/users/new.html.erb_spec.rb +++ b/spec/views/users/new.html.erb_spec.rb @@ -1,5 +1,2 @@ require 'rails_helper' -RSpec.describe "users/new.html.erb", type: :view do - pending "add some examples to (or delete) #{__FILE__}" -end From bfae880999653be0d75f978c802864f8b9a409be Mon Sep 17 00:00:00 2001 From: Harrison Date: Sat, 28 May 2016 18:10:48 -0300 Subject: [PATCH 05/98] Cadastro feito e login iniciado. --- Gemfile | 2 +- Gemfile.lock | 11 ++ app/assets/javascripts/sessions.coffee | 3 + app/assets/stylesheets/bootstrap.css | 11 ++ app/assets/stylesheets/sessions.scss | 3 + app/assets/stylesheets/users.scss | 1 + app/controllers/application_controller.rb | 2 +- app/controllers/sessions_controller.rb | 15 +++ app/controllers/users_controller.rb | 22 ++++ app/helpers/sessions_helper.rb | 13 +++ app/views/cities/compare.html.erb | 8 +- app/views/cities/index.html.erb | 6 ++ app/views/cities/show.html.erb | 9 +- app/views/cities/show_cities.html.erb | 22 ++-- app/views/layouts/application.html.erb | 16 --- app/views/sessions/new.html.erb | 96 +++++++++++++++++ app/views/static_pages/about.html.erb | 22 ++-- app/views/static_pages/contact_us.html.erb | 22 ++-- app/views/static_pages/references.html.erb | 22 ++-- app/views/users/new.html.erb | 103 ++++++++++++++++++- app/views/users/show.html.erb | 1 + config/routes.rb | 8 +- spec/controllers/sessions_controller_spec.rb | 12 +++ spec/controllers/users_controller_spec.rb | 18 ++++ spec/features/users_controller_spec.rb | 13 +++ spec/helpers/sessions_helper_spec.rb | 15 +++ spec/rails_helper.rb | 1 + spec/spec_helper.rb | 1 + spec/views/sessions/new.html.erb_spec.rb | 5 + 29 files changed, 427 insertions(+), 56 deletions(-) create mode 100644 app/assets/javascripts/sessions.coffee create mode 100644 app/assets/stylesheets/sessions.scss create mode 100644 app/controllers/sessions_controller.rb create mode 100644 app/helpers/sessions_helper.rb create mode 100644 app/views/sessions/new.html.erb create mode 100644 app/views/users/show.html.erb create mode 100644 spec/controllers/sessions_controller_spec.rb create mode 100644 spec/features/users_controller_spec.rb create mode 100644 spec/helpers/sessions_helper_spec.rb create mode 100644 spec/views/sessions/new.html.erb_spec.rb diff --git a/Gemfile b/Gemfile index 55ddaed..1bc7d2c 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.1.0' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby - +gem 'capybara' # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks diff --git a/Gemfile.lock b/Gemfile.lock index d0bfb4b..2d3d73e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,6 +36,7 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + addressable (2.4.0) arel (6.0.3) autoprefixer-rails (6.3.6) execjs @@ -48,6 +49,13 @@ GEM will_paginate builder (3.2.2) byebug (8.2.4) + capybara (2.7.1) + addressable + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) coffee-rails (4.1.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.1.x) @@ -190,6 +198,8 @@ GEM railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) will_paginate (3.1.0) + xpath (2.0.0) + nokogiri (~> 1.3) PLATFORMS ruby @@ -199,6 +209,7 @@ DEPENDENCIES bootstrap-sass (~> 3.2.0) bootstrap-will_paginate (= 0.0.10) byebug + capybara coffee-rails (~> 4.1.0) devise factory_girl_rails diff --git a/app/assets/javascripts/sessions.coffee b/app/assets/javascripts/sessions.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/sessions.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/bootstrap.css b/app/assets/stylesheets/bootstrap.css index b018a8b..26e46e5 100644 --- a/app/assets/stylesheets/bootstrap.css +++ b/app/assets/stylesheets/bootstrap.css @@ -6873,4 +6873,15 @@ button.close { .dropdownTeste:hover .dropdownTeste-content { display: block; +} + +input, textarea, select, .uneditable-input { + border: 1px solid #bbb; + width: 100%; + margin-bottom: 15px; + @include box_sizing; +} + +input { + height: auto !important; } \ No newline at end of file diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 0000000..ccb1ed2 --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Sessions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/users.scss b/app/assets/stylesheets/users.scss index 31a2eac..b4dce9d 100644 --- a/app/assets/stylesheets/users.scss +++ b/app/assets/stylesheets/users.scss @@ -1,3 +1,4 @@ // Place all the styles related to the Users controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ + diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2cee466..a65d880 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception - + include SessionsHelper def about end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 0000000..d15221a --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,15 @@ +class SessionsController < ApplicationController + def new + end + + def create + user = User.find_by(email: params[:session][:email].downcase) + if user && user.authenticate(params[:session][:password]) + log_in user + redirect_to user + else + render 'new' + end + end + +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 2ec9ecc..4654631 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,26 @@ class UsersController < ApplicationController def new + @user = User.new end + + def show + @user = User.find(params[:id]) + end + + def create + @user = User.new(user_params) + if @user.save + redirect_to @user + else + render 'new' + end + end + + private + + def user_params + params.require(:user).permit(:name, :email, :password, + :password_confirmation) + end + end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 0000000..ce5cb8d --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,13 @@ +module SessionsHelper + def log_in(user) + session[:user_id] = user.id + end + + def current_user + @current_user ||= User.find_by(id: session[:user_id]) + end + + def logged_in? + !current_user.nil? + end +end diff --git a/app/views/cities/compare.html.erb b/app/views/cities/compare.html.erb index 2cd770e..f54ece1 100644 --- a/app/views/cities/compare.html.erb +++ b/app/views/cities/compare.html.erb @@ -42,6 +42,12 @@ diff --git a/app/views/cities/index.html.erb b/app/views/cities/index.html.erb index 9d11112..7472186 100644 --- a/app/views/cities/index.html.erb +++ b/app/views/cities/index.html.erb @@ -48,6 +48,12 @@ diff --git a/app/views/cities/show_cities.html.erb b/app/views/cities/show_cities.html.erb index cba1c0a..f841f48 100644 --- a/app/views/cities/show_cities.html.erb +++ b/app/views/cities/show_cities.html.erb @@ -47,14 +47,20 @@ diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 8ab5496..e69de29 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,16 +0,0 @@ - - - - êLugar - - - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> - <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> - <%= csrf_meta_tags %> - - - -<%= yield %> - - - diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb new file mode 100644 index 0000000..8e533ba --- /dev/null +++ b/app/views/sessions/new.html.erb @@ -0,0 +1,96 @@ + + + + + + + + + + êLugar + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+

Login

+
+
+
+
+
+ +
+
+ <%= form_for(:session, url: login_path) do |f| %> + + <%= f.label :email %> + <%= f.email_field :email, class: 'form-control' %> + + <%= f.label :password %> + <%= f.password_field :password, class: 'form-control' %> + + <%= f.submit "Log in", class: "btn btn-primary" %> + <% end %> + +

Novo usuário? <%= link_to "Cadastre-se agora!", signup_path %>

+
+
\ No newline at end of file diff --git a/app/views/static_pages/about.html.erb b/app/views/static_pages/about.html.erb index 1e55258..b111123 100644 --- a/app/views/static_pages/about.html.erb +++ b/app/views/static_pages/about.html.erb @@ -47,14 +47,20 @@ diff --git a/app/views/static_pages/contact_us.html.erb b/app/views/static_pages/contact_us.html.erb index 3ef7f26..ffc8197 100644 --- a/app/views/static_pages/contact_us.html.erb +++ b/app/views/static_pages/contact_us.html.erb @@ -47,14 +47,20 @@ diff --git a/app/views/static_pages/references.html.erb b/app/views/static_pages/references.html.erb index 3f12716..1a6ed21 100644 --- a/app/views/static_pages/references.html.erb +++ b/app/views/static_pages/references.html.erb @@ -47,14 +47,20 @@ diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index c21a1ad..d40a57e 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,2 +1,101 @@ -

Users#new

-

Find me in app/views/users/new.html.erb

+ + + + + + + + + + êLugar + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+

Cadastro

+
+
+
+
+
+ + + +
+
+ <%= form_for(@user) do |f| %> + <%= f.label :name %> + <%= f.text_field :name %> + + <%= f.label :email %> + <%= f.email_field :email %> + + <%= f.label :password %> + <%= f.password_field :password %> + + <%= f.label :password_confirmation, "Confirmation" %> + <%= f.password_field :password_confirmation %> + + <%= f.submit "Create my account", class: "btn btn-primary" %> + <% end %> +
+
\ No newline at end of file diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000..e65d224 --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1 @@ +<%= @user.name %>, <%= @user.email %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1ddf9b4..19b1f1e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Rails.application.routes.draw do + get 'sessions/new' + get 'users/new' # The priority is based upon order of creation: first created -> highest priority. @@ -8,7 +10,8 @@ resources :cities resources :users root 'cities#index' - + get 'signup' => 'users#new' + post 'signup' => 'users#create' get 'index' => 'cities#index' get 'find' => 'cities#show_cities' get 'cities/show' @@ -20,6 +23,9 @@ get 'contact' => 'static_pages#contact_us' get 'references' => 'static_pages#references' get "static_pages/download_pdf" + get 'login' => 'sessions#new' + post 'login' => 'sessions#create' + delete 'logout' => 'sessions#destroy' # Example of regular route: diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb new file mode 100644 index 0000000..f524aa5 --- /dev/null +++ b/spec/controllers/sessions_controller_spec.rb @@ -0,0 +1,12 @@ +require 'rails_helper' + +RSpec.describe SessionsController, type: :controller do + + describe "GET #new" do + it "returns http success" do + get :new + expect(response).to have_http_status(:success) + end + end + +end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 0a86999..9492ffa 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -9,4 +9,22 @@ end end + + + # describe "#new" do + # it "invalid sign_up" do + # visit signup_path + # before_count = User.count + # post users_path, user: { name: "", + # email: "user@invalid", + # password: "foo", + # password_confirmation: "bar" } + # after_count = User.count + # expect(before_count).not_to be(after_count) + # end + # end + + + + end diff --git a/spec/features/users_controller_spec.rb b/spec/features/users_controller_spec.rb new file mode 100644 index 0000000..f3a75bf --- /dev/null +++ b/spec/features/users_controller_spec.rb @@ -0,0 +1,13 @@ +# require 'rails_helper' +# feature 'Visitor signs up' do +# scenario 'via email' do +# visit signup_path +# expect(page).to have_content("Name") +# fill_in "user_name", with: "John" +# fill_in "user_email", with: "john@test.com" +# fill_in "user_password", with: "test123" +# fill_in "user_password_confirmation", with: "test123" +# click_button "Create account" +# expect(User.count).to eq(1) +# end +# end diff --git a/spec/helpers/sessions_helper_spec.rb b/spec/helpers/sessions_helper_spec.rb new file mode 100644 index 0000000..9484198 --- /dev/null +++ b/spec/helpers/sessions_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the SessionsHelper. For example: +# +# describe SessionsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe SessionsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index a4e30f0..f68341e 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -27,6 +27,7 @@ ActiveRecord::Migration.maintain_test_schema! RSpec.configure do |config| + config.include Capybara::DSL, :type => :request config.include FactoryGirl::Syntax::Methods # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 61e2738..6ea1a2a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,6 +17,7 @@ # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer. diff --git a/spec/views/sessions/new.html.erb_spec.rb b/spec/views/sessions/new.html.erb_spec.rb new file mode 100644 index 0000000..6de37da --- /dev/null +++ b/spec/views/sessions/new.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe "sessions/new.html.erb", type: :view do + pending "add some examples to (or delete) #{__FILE__}" +end From 3acea6d965180d5d448cfc17c46e268a45f93068 Mon Sep 17 00:00:00 2001 From: Felipe Date: Sat, 28 May 2016 18:20:20 -0300 Subject: [PATCH 06/98] =?UTF-8?q?Eu=20fiz=20uma=20model=20para=20guardar?= =?UTF-8?q?=20os=20coment=C3=A1rios=20que=20est=C3=A1=20relacionado=20com?= =?UTF-8?q?=20cada=20cidade,=20por=C3=A9m=20a=20visualiza=C3=A7=C3=A3o=20d?= =?UTF-8?q?eles=20est=C3=A1=20bastante=20feia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/comments.coffee | 3 ++ app/assets/stylesheets/comments.scss | 3 ++ app/controllers/comments_controller.rb | 12 +++++++ app/helpers/comments_helper.rb | 2 ++ app/models/city.rb | 1 + app/models/comment.rb | 3 ++ app/views/cities/show.html.erb | 37 ++++++++++++++++++-- config/routes.rb | 4 +++ db/migrate/20160528210425_create_comments.rb | 11 ++++++ db/schema.rb | 12 ++++++- test/controllers/comments_controller_test.rb | 7 ++++ test/fixtures/comments.yml | 11 ++++++ test/models/comment_test.rb | 7 ++++ 13 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/comments.coffee create mode 100644 app/assets/stylesheets/comments.scss create mode 100644 app/controllers/comments_controller.rb create mode 100644 app/helpers/comments_helper.rb create mode 100644 app/models/comment.rb create mode 100644 db/migrate/20160528210425_create_comments.rb create mode 100644 test/controllers/comments_controller_test.rb create mode 100644 test/fixtures/comments.yml create mode 100644 test/models/comment_test.rb diff --git a/app/assets/javascripts/comments.coffee b/app/assets/javascripts/comments.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/comments.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/comments.scss b/app/assets/stylesheets/comments.scss new file mode 100644 index 0000000..e730912 --- /dev/null +++ b/app/assets/stylesheets/comments.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Comments controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb new file mode 100644 index 0000000..a1444db --- /dev/null +++ b/app/controllers/comments_controller.rb @@ -0,0 +1,12 @@ +class CommentsController < ApplicationController + def create + @city = City.find(params[:city_id]) + @comment = @city.comments.create(comment_params) + redirect_to city_path(@city) + end + +private + def comment_params + params.require(:comment).permit(:commenter, :body) + end +end diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb new file mode 100644 index 0000000..0ec9ca5 --- /dev/null +++ b/app/helpers/comments_helper.rb @@ -0,0 +1,2 @@ +module CommentsHelper +end diff --git a/app/models/city.rb b/app/models/city.rb index 27cc40c..fa03c0c 100644 --- a/app/models/city.rb +++ b/app/models/city.rb @@ -1,4 +1,5 @@ class City < ActiveRecord::Base + has_many :comments validates :name, presence: true validates :population, presence: true validates :demographic_density, presence: true diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000..e71657a --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,3 @@ +class Comment < ActiveRecord::Base + belongs_to :city +end diff --git a/app/views/cities/show.html.erb b/app/views/cities/show.html.erb index fd663d8..58e5453 100644 --- a/app/views/cities/show.html.erb +++ b/app/views/cities/show.html.erb @@ -105,7 +105,38 @@ <%= link_to "Voltar", find_path(:id => nil), :class => "btn btn-default" %>   - <%= link_to "Compare", compare_path(:id => @oldID), :class => "btn btn-primary" %> + <%= link_to "Compare", compare_path(:id => @oldID), :class => "btn btn-primary" %> + +

Comments

+ <% @city.comments.each do |comment| %> +

+ Commenter: + <%= comment.commenter %> +

+ +

+ Comment: + <%= comment.body %> +

+ <% end %> + +

Add a comment:

+ <%= form_for([@city, @city.comments.build]) do |f| %> +

+ <%= f.label :commenter %>
+ <%= f.text_field :commenter %> +

+

+ <%= f.label :body %>
+ <%= f.text_area :body %> +

+

+ <%= f.submit %> +

+ <% end %> + + <%= link_to 'Edit', edit_city_path(@city) %> | + <%= link_to 'Back', city_path %> @@ -113,8 +144,8 @@ -