Permalink
Browse files

Empezando a poner generar una API rest en los controladores

Los simple forms por defecto son form-horizontal
Añadido encoding a todos los ficheros
Tests de helpers tambien
  • Loading branch information...
1 parent 8b1e814 commit 2831e0c2ee40942285b2d9b87c003b28824eda9c miguel.camba committed May 3, 2012
Showing with 351 additions and 93 deletions.
  1. +8 −3 Gemfile
  2. +7 −0 Gemfile.lock
  3. +1 −0 app/assets/javascripts/application.js
  4. +11 −0 app/assets/javascripts/common.js.coffee
  5. +37 −3 app/assets/javascripts/users.js.coffee
  6. +1 −0 app/controllers/application_controller.rb
  7. +1 −0 app/controllers/issues_controller.rb
  8. +1 −0 app/controllers/projects_controller.rb
  9. +2 −1 app/controllers/sessions_controller.rb
  10. +14 −5 app/controllers/users_controller.rb
  11. +2 −2 app/controllers/welcome_controller.rb
  12. +38 −0 app/helpers/application_helper.rb
  13. +1 −0 app/helpers/issues_helper.rb
  14. +1 −0 app/helpers/projects_helper.rb
  15. +1 −0 app/helpers/sessions_helper.rb
  16. +1 −0 app/helpers/users_helper.rb
  17. +1 −0 app/models/issue.rb
  18. +1 −0 app/models/project.rb
  19. +4 −2 app/models/user.rb
  20. +2 −1 app/models/with_creator.rb
  21. +2 −1 app/models/with_responsable.rb
  22. +5 −4 app/views/layouts/application.html.haml
  23. +1 −1 app/views/sessions/_login_form.html.haml
  24. +2 −2 app/views/sessions/create.js.coffee
  25. +0 −1 app/views/users/create.html.haml
  26. +72 −20 app/views/users/my_profile.html.haml
  27. +5 −15 app/views/users/new.html.haml
  28. +0 −6 app/views/welcome/signup.html.haml
  29. +1 −0 config/application.rb
  30. +1 −0 config/boot.rb
  31. +1 −0 config/environment.rb
  32. +1 −0 config/environments/development.rb
  33. +1 −0 config/environments/production.rb
  34. +1 −0 config/environments/test.rb
  35. +1 −0 config/initializers/backtrace_silencers.rb
  36. +1 −0 config/initializers/inflections.rb
  37. +1 −0 config/initializers/mime_types.rb
  38. +1 −0 config/initializers/secret_token.rb
  39. +1 −0 config/initializers/session_store.rb
  40. +19 −19 config/initializers/simple_form.rb
  41. +1 −0 config/initializers/sorcery.rb
  42. +1 −0 config/initializers/wrap_parameters.rb
  43. +1 −0 config/routes.rb
  44. +1 −0 db/migrate/20120425210953_create_projects.rb
  45. +1 −0 db/migrate/20120425211013_create_issues.rb
  46. +1 −0 db/migrate/20120427064910_create_users.rb
  47. +1 −0 db/migrate/20120427065047_add_creator_to_project.rb
  48. +1 −0 db/migrate/20120427065225_add_responsable_to_issues.rb
  49. +1 −0 db/migrate/20120427124402_add_creator_to_issues.rb
  50. +1 −0 db/migrate/20120427131211_add_responsable_to_project.rb
  51. +11 −0 db/migrate/20120502070424_add_personal_data_to_user.rb
  52. +8 −2 db/schema.rb
  53. +1 −0 db/seeds.rb
  54. +2 −1 spec/factories.rb
  55. +56 −0 spec/helpers/application_helper_spec.rb
  56. +2 −1 spec/models/issue_spec.rb
  57. +2 −1 spec/models/project_spec.rb
  58. +1 −0 spec/models/user_spec.rb
  59. +1 −0 spec/spec_helper.rb
  60. +1 −0 spec/support/models/custom_matchers.rb
  61. +2 −1 spec/support/models/with_creator_shared_examples.rb
  62. +2 −1 spec/support/models/with_responsable_shared_examples.rb
View
11 Gemfile
@@ -22,6 +22,7 @@ group :assets do
end
gem 'jquery-rails'
+gem 'underscore-rails'
gem 'haml-rails'
gem 'decent_exposure'
gem 'bcrypt-ruby'
@@ -39,14 +40,18 @@ group :development do
gem 'quiet_assets'
end
-group :test, :development do
- gem 'foreigner'
+group :test do
gem 'rspec-rails'
- gem 'factory_girl_rails'
+ gem 'rspec-html-matchers'
gem 'shoulda-matchers'
gem 'ipsum'
end
+group :test, :development do
+ gem 'foreigner'
+ gem 'factory_girl_rails'
+end
+
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
View
7 Gemfile.lock
@@ -123,6 +123,7 @@ GEM
mime-types (1.18)
multi_json (1.3.2)
multipart-post (1.1.5)
+ nokogiri (1.5.2)
oauth (0.4.6)
oauth2 (0.5.2)
faraday (~> 0.7)
@@ -168,6 +169,9 @@ GEM
rspec-core (2.9.0)
rspec-expectations (2.9.1)
diff-lcs (~> 1.1.3)
+ rspec-html-matchers (0.3.5)
+ nokogiri (>= 1.4.4)
+ rspec (>= 2.0.0)
rspec-mocks (2.9.0)
rspec-rails (2.9.0)
actionpack (>= 3.0)
@@ -212,6 +216,7 @@ GEM
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
+ underscore-rails (1.3.1)
PLATFORMS
ruby
@@ -233,6 +238,7 @@ DEPENDENCIES
pry-rails
quiet_assets
rails (= 3.2.3)
+ rspec-html-matchers
rspec-rails
sass-rails (~> 3.2.3)
shoulda-matchers
@@ -243,3 +249,4 @@ DEPENDENCIES
thin-rails
twitter-bootstrap-rails!
uglifier (>= 1.0.3)
+ underscore-rails
View
1 app/assets/javascripts/application.js
@@ -12,5 +12,6 @@
//
//= require jquery
//= require jquery_ujs
+//= require underscore
//= require twitter/bootstrap
//= require_tree .
View
11 app/assets/javascripts/common.js.coffee
@@ -0,0 +1,11 @@
+jQuery ->
+ $('.toggle-edition').click (e)->
+ e.preventDefault()
+ $button = $(this)
+ $form = $button.closest('form')
+ if $button.hasClass 'edit'
+ $form.find('input').removeClass('disabled').prop('disabled', false)
+ $button.removeClass('edit').addClass('btn-danger').html('<i class="icon-remove"></i> Cancelar')
+ else
+ $form.find('input').addClass('disabled').prop('disabled', true)
+ $button.addClass('edit').removeClass('btn-danger').html('<i class="icon-edit"></i> Editar')
View
40 app/assets/javascripts/users.js.coffee
@@ -1,3 +1,37 @@
-# 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://jashkenas.github.com/coffee-script/
+# Templates al estilo moustache
+_.templateSettings =
+ interpolate : /\{\{(.+?)\}\}/g
+
+# Función para poner un alert en su sitio predefinido a un form (marcado por .alert-container)
+$.fn.extend
+ bootstrapAlert: (text, level = 'error') ->
+ alertClass = if level then "alert-#{level}" else ''
+ alertTemplate = _.template $('#alertTemplate').html()
+ $(this).find('.alert-container').html alertTemplate({ text: text, klass: alertClass })
+ hideValidationErrors: () ->
+ $(this).find('.control-group').removeClass('error')
+ $(this).find('.help-block.error').remove()
+ $(this).find('.alert-error').alert('close')
+ showValidationErrors: (jsonErrors) ->
+ $(this).hideValidationErrors()
+ for field, errors of jsonErrors
+ $input = $("##{$(this).data('model')}_#{field}")
+ $input.closest('.control-group').addClass('error')
+ $input.after "<p class='help-block error'>#{errors.join('. ')}</p>"
+ bootstrapValidation: (response) ->
+ json = $.parseJSON(response.responseText)
+ $(this).showValidationErrors(json.errors)
+ $(this).bootstrapAlert '<strong>Oh oh!</strong> Parece que hay algún dato erróneo'
+
+jQuery ->
+ # Cuando enviar un formulario de usuario, en realidad se envía una petición de JSON que devuelve
+ # el objeto actualizado o los errores.
+ $('.user_form').submit (e)->
+ $form = $(this)
+ e.preventDefault()
+ $.post("#{@action}.json", $(this).serialize())
+ .success (response) ->
+ $form.hideValidationErrors()
+ $form.bootstrapAlert '<strong>Listo!</strong> Se han actualizado los datos', 'success'
+ .error (response) ->
+ $form.bootstrapValidation(response)
View
1 app/controllers/application_controller.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
class ApplicationController < ActionController::Base
protect_from_forgery
View
1 app/controllers/issues_controller.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
class IssuesController < ApplicationController
def index
View
1 app/controllers/projects_controller.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
class ProjectsController < ApplicationController
#
View
3 app/controllers/sessions_controller.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
class SessionsController < ApplicationController
layout 'login'
@@ -20,7 +21,7 @@ def create
render :new
end
end
- format.js
+ format.js { flash[:success] = "Login correct" }
end
end
View
19 app/controllers/users_controller.rb
@@ -1,4 +1,5 @@
class UsersController < ApplicationController
+ respond_to :html, :json
#
# Filters
#
@@ -12,16 +13,24 @@ class UsersController < ApplicationController
expose(:user)
def new
+ respond_with user
+ end
+
+ def edit
+ respond_with user
end
def create
if user.save
- auto_login(user)
- flash.now.alert = "Email or password was invalid."
- redirect_to root_url, :notice => "Signed up!"
- else
- render :new
+ auto_login user
+ flash[:notice] = "User was created successfully."
end
+ respond_with user, location: root_url
+ end
+
+ def update
+ flash[:notice] = "User was created updated." if user.save
+ respond_with user
end
# def index
View
4 app/controllers/welcome_controller.rb
@@ -1,9 +1,9 @@
+# -*- encoding : utf-8 -*-
class WelcomeController < ApplicationController
before_filter :redirect_to_welcome_unless_logged, only: :index
-
private
def redirect_to_welcome_unless_logged
redirect_to welcome_path unless logged_in?
end
-end
+end
View
38 app/helpers/application_helper.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
module ApplicationHelper
# Sobreescribo link_to para que acepte opciones útiles.
@@ -13,4 +14,41 @@ def link_to(body, url, html_options = {})
super body, url, html_options
end
+ def default_text_for_bootstrap_alert(level)
+ text = case level.to_s
+ when 'notice' then nil
+ when 'error' then '<strong>Oh oh!</strong> Parece que hay algún dato erróneo'
+ when 'alert' then nil
+ when 'success' then '<strong>Listo!</strong> Se han actualizado los datos'
+ else nil
+ end
+ return nil unless text
+ text.html_safe
+ end
+
+ # Renderiza un alert estilado para bootstrap, con boton de cerrar.
+ def bootstrap_alert(text = nil, level = nil)
+ text ||= default_text_for_bootstrap_alert(level)
+ content_tag :div, class: "alert fade in #{flash_class(level)}" do
+ button_tag('×', class: 'close', 'data-dismiss' => "alert") + content_tag(:div, text, class: 'text-center')
+ end
+ end
+
+ # Renderiza los flashes (:notice, :error, :success ...) con estilo de alerts de bootstrap
+ def bootstrap_flashes
+ [:notice, :error, :alert, :success].map do |level|
+ bootstrap_alert(flash[level], level) unless flash[level].blank?
+ end.join.html_safe
+ end
+
+ # Dado un tipo de mensaje flash, devuelve la clase del alert de bootstrap correspondiente
+ def flash_class(level)
+ case level.to_s
+ when 'notice' then "alert-info"
+ when 'error' then "alert-error"
+ when 'alert' then "alert-warning"
+ when 'success' then "alert-success"
+ end
+ end
+
end
View
1 app/helpers/issues_helper.rb
@@ -1,2 +1,3 @@
+# -*- encoding : utf-8 -*-
module IssuesHelper
end
View
1 app/helpers/projects_helper.rb
@@ -1,2 +1,3 @@
+# -*- encoding : utf-8 -*-
module ProjectsHelper
end
View
1 app/helpers/sessions_helper.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
module SessionsHelper
def username_placeholder
View
1 app/helpers/users_helper.rb
@@ -1,2 +1,3 @@
+# -*- encoding : utf-8 -*-
module UsersHelper
end
View
1 app/models/issue.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
class Issue < ActiveRecord::Base
attr_accessible :title, :code, :description, :project, :status, :percentage
include WithResponsable
View
1 app/models/project.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
class Project < ActiveRecord::Base
attr_accessible :name
include WithResponsable
View
6 app/models/user.rb
@@ -1,7 +1,9 @@
+# -*- encoding : utf-8 -*-
class User < ActiveRecord::Base
authenticates_with_sorcery!
- attr_accessible :username, :email, :password, :password_confirmation
+ attr_accessible :username, :email, :password, :password_confirmation, :name, :surname1, :surname2, :twitter,
+ :github
#
# Relations
@@ -14,7 +16,7 @@ class User < ActiveRecord::Base
#
validates :username, presence: true, uniqueness: true, length: 5..20
validates :email, presence: true, uniqueness: true, email: true
- validates :password, presence: { on: :create }, confirmation: true, length: 5..20
+ validates :password, presence: { on: :create }, confirmation: true, length: { in: 5..20, on: :create }
#
# Métodos de instancia
View
3 app/models/with_creator.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
module WithCreator
def self.included(base)
@@ -20,4 +21,4 @@ def created_by?(usr)
creator == usr
end
-end
+end
View
3 app/models/with_responsable.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
module WithResponsable
def self.included(base)
@@ -15,4 +16,4 @@ def assigned_to?(usr)
responsable == usr
end
-end
+end
View
9 app/views/layouts/application.html.haml
@@ -14,14 +14,14 @@
%span.icon-bar
%span.icon-bar
%span.icon-bar
- = link_to 'Pinkmine', '#', class: 'brand'
+ = link_to 'Pinkmine', root_url, class: 'brand'
.btn-group.pull-right
%a.btn.dropdown-toggle{ 'data-toggle' => 'dropdown', href: "#" }
- %i.icon-user= " #{current_user ? current_user.username : 'Username'}"
+ %i.icon-home= " #{current_user ? current_user.username : 'Username'}"
%span.caret
%ul.dropdown-menu
- %li= link_to 'Profile', my_profile_path, icon: 'pencil'
- %li= link_to 'Stats', my_profile_path, icon: 'home'
+ %li= link_to 'Profile', my_profile_path, icon: 'user'
+ %li= link_to 'Stats', my_profile_path, icon: 'calendar'
%li.divider
%li= link_to 'Sign Out', logout_path, icon: 'off'
.nav-collapse
@@ -31,4 +31,5 @@
%li= link_to 'Contact', '#contact'
.container-fluid
+ .row-fluid= bootstrap_flashes
= yield
View
2 app/views/sessions/_login_form.html.haml
@@ -1,5 +1,5 @@
- remote ||= false
-= form_tag sessions_path, remote: remote, class: 'form-horizontal', id: 'loginForm' do |f|
+= form_tag sessions_path, remote: remote, class: 'form-horizontal', id: 'login_form' do |f|
= render 'login_error' if action_name == 'create'
%fieldset
.control-group
View
4 app/views/sessions/create.js.coffee
@@ -2,6 +2,6 @@
window.location = "<%= root_url %>"
<% else %>
$alertError = $("<%= j render 'login_error' %>")
- $('#loginForm .alert-error').remove()
- $('#loginForm fieldset').before $alertError.fadeIn(50)
+ $('#login_form .alert-error').remove()
+ $('#login_form fieldset').before $alertError.fadeIn(50)
<% end %>
View
1 app/views/users/create.html.haml
@@ -1 +0,0 @@
-%h1 Usuario creado!!
View
92 app/views/users/my_profile.html.haml
@@ -1,30 +1,82 @@
+/ Template de alerts
+%script#alertTemplate{ type: "text/template" }
+ .alert{ class: "{{klass}}"}
+ %a.close{ 'data-dismiss' => 'alert', href: "#"}×
+ {{text}}
+
+/ Contenido estático
.row-fluid
.span3
- .well.sidebar-nav
- %ul.nav.nav-tabs.nav-stacked
- %li.nav-header Mis datos
- %li.active= link_to 'Cuenta', '#account', icon: 'user', 'data-toggle' => "tab"
- %li= link_to 'Datos personales', '#personal', icon: 'book', 'data-toggle' => "tab"
- %li= link_to 'Asociaciones', '#associations', icon: 'home', 'data-toggle' => "tab"
- %li= link_to 'Alertas', '#alerts', icon: 'envelope', 'data-toggle' => "tab"
- %li.nav-header Seguridad
- %li= link_to 'RSS Keys', '#rss', icon: 'qrcode', 'data-toggle' => "tab"
- %li= link_to 'API keys', '#api', icon: 'barcode', 'data-toggle' => "tab"
+ .sidebar-nav
+ .well
+ %ul.nav.nav-pills.nav-stacked
+ %li.nav-header Mis datos
+ %li.active= link_to 'Cuenta', '#account', icon: 'user', 'data-toggle' => "tab"
+ %li= link_to 'Datos personales', '#personal', icon: 'book', 'data-toggle' => "tab"
+ %li= link_to 'Asociaciones', '#associations', icon: 'home', 'data-toggle' => "tab"
+ %li= link_to 'Alertas', '#alerts', icon: 'envelope', 'data-toggle' => "tab"
+ %li.nav-header Seguridad
+ %li= link_to 'RSS Keys', '#rss', icon: 'qrcode', 'data-toggle' => "tab"
+ %li= link_to 'API keys', '#api', icon: 'barcode', 'data-toggle' => "tab"
+ %li.divider
+ %li= link_to 'Help', '#help', icon: 'question-sign', 'data-toggle' => "tab"
.span9
.tab-content
#account.tab-pane.active
- %h2 Cuenta
- .row
- .span2
- %label Email
- .span3 info@pinkmine.com
- .span2
- %label Otro dato
- .span3 03/09/1986
+ = simple_form_for current_user, html: { class: 'user_form', 'data-model' => 'user' } do |f|
+ %fieldset
+ .row-fluid
+ %legend
+ Mi cuenta
+ = link_to ' Editar', '#', class: 'btn btn-mini pull-right toggle-edition edit', icon: 'edit'
+ .alert-container.text-center
+ .row-fluid
+ .span6
+ = f.input :username, disabled: true
+ = f.input :email, disabled: true
+ .span6
+ = f.input :password, disabled: true
+ = f.input :password_confirmation, disabled: true
+ .row-fluid
+ .span12.text-center
+ = f.button :submit, class: 'btn-primary', disabled: true
#personal.tab-pane
- %h2 Datos personales
+ = simple_form_for current_user, html: { class: 'user_form', 'data-model' => 'user' } do |f|
+ %fieldset
+ .row-fluid
+ %legend
+ Datos personales
+ = link_to ' Editar', '#', class: 'btn btn-mini pull-right toggle-edition edit', icon: 'edit'
+ .alert-container.text-center
+ .row-fluid
+ .span6
+ = f.input :name, disabled: true
+ = f.input :surname1, disabled: true
+ = f.input :surname2, disabled: true
+ .span6
+ = f.input :twitter, disabled: true
+ = f.input :github, disabled: true
+ .row-fluid
+ .span12.text-center
+ = f.button :submit, class: 'btn-primary', disabled: true
#associations.tab-pane
- %h2 Asociaciones
+ = simple_form_for current_user, html: { class: 'user_form', 'data-model' => 'user' } do |f|
+ %fieldset
+ .row-fluid
+ %legend
+ Asociaciones
+ = link_to ' Editar', '#', class: 'btn btn-mini pull-right toggle-edition edit', icon: 'edit'
+ .alert-container.text-center
+ .row-fluid
+ .span6
+ = f.input :username, disabled: true
+ = f.input :email, disabled: true
+ .span6
+ = f.input :password, disabled: true
+ = f.input :password_confirmation, disabled: true
+ .row-fluid
+ .span12.text-center
+ = f.button :submit, class: 'btn-primary', disabled: true
#alerts.tab-pane
%h2 Alertas
#rss.tab-pane
View
20 app/views/users/new.html.haml
@@ -1,10 +1,13 @@
-- remote ||= false
-= simple_form_for user, html: { class: 'form-horizontal', id: 'signupForm' } do |f|
+= simple_form_for user do |f|
.row-fluid
.span2
.span8
%fieldset
%legend Datos de usuario
+ - if f.object.errors.any?
+ .row-fluid
+ .margin-1em
+ .span12= bootstrap_alert nil, :error
.row-fluid
.margin-1em
.span6
@@ -13,19 +16,6 @@
.span6
= f.input :password
= f.input :password_confirmation
- / .row-fluid.margin-1em
- / .span2
- / .span8
- / %fieldset
- / %legend Datos personales
- / .row-fluid
- / .margin-1em
- / .span6
- / = f.input :username #, input_html: { class: 'input-xlarge' }
- / = f.input :email #, input_html: { class: 'input-xlarge' }
- / .span6
- / = f.input :password
- / = f.input :password_confirmation
.row-fluid
.span2
.span8
View
6 app/views/welcome/signup.html.haml
@@ -1,6 +0,0 @@
-.row-fluid
- = form_for '/signup' do |f|
- .span3.offset2
- %p Email
- .span6
- = f.text_field :login
View
1 config/application.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require File.expand_path('../boot', __FILE__)
require 'rails/all'
View
1 config/boot.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require 'rubygems'
# Set up gems listed in the Gemfile.
View
1 config/environment.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
# Load the rails application
require File.expand_path('../application', __FILE__)
View
1 config/environments/development.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
Pinkmine::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
View
1 config/environments/production.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
Pinkmine::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
View
1 config/environments/test.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
Pinkmine::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
View
1 config/initializers/backtrace_silencers.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
View
1 config/initializers/inflections.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
View
1 config/initializers/mime_types.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
View
1 config/initializers/secret_token.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
# Be sure to restart your server when you modify this file.
# Your secret key for verifying the integrity of signed cookies.
View
1 config/initializers/session_store.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
# Be sure to restart your server when you modify this file.
Pinkmine::Application.config.session_store :cookie_store, key: '_pinkmine_session'
View
38 config/initializers/simple_form.rb
@@ -1,12 +1,12 @@
+# -*- encoding : utf-8 -*-
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Wrappers are used by the form builder to generate a
# complete input. You can remove any component from the
# wrapper, change the order or even add your own to the
# stack. The options given below are used to wrap the
# whole input.
- config.wrappers :default, :class => :input,
- :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
+ config.wrappers :default, class: :input, hint_class: :field_with_hint, error_class: :field_with_errors do |b|
## Extensions enabled by default
# Any of these extensions can be disabled for a
# given input by passing: `f.input EXTENSION_NAME => false`.
@@ -41,44 +41,44 @@
## Inputs
b.use :label_input
- b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
- b.use :error, :wrap_with => { :tag => :span, :class => :error }
+ b.use :hint, wrap_with: { tag: :span, class: :hint }
+ b.use :error, wrap_with: { tag: :span, class: :error }
end
- config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
+ config.wrappers :bootstrap, tag: 'div', class: 'control-group', error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
- b.wrapper :tag => 'div', :class => 'controls' do |ba|
+ b.wrapper tag: 'div', class: 'controls' do |ba|
ba.use :input
- ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
- ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
+ ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
end
- config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
+ config.wrappers :prepend, tag: 'div', class: "control-group", error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
- b.wrapper :tag => 'div', :class => 'controls' do |input|
- input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend|
+ b.wrapper tag: 'div', class: 'controls' do |input|
+ input.wrapper tag: 'div', class: 'input-prepend' do |prepend|
prepend.use :input
end
- input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
- input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
+ input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
+ input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
end
end
- config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
+ config.wrappers :append, tag: 'div', class: "control-group", error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
- b.wrapper :tag => 'div', :class => 'controls' do |input|
- input.wrapper :tag => 'div', :class => 'input-append' do |append|
+ b.wrapper tag: 'div', class: 'controls' do |input|
+ input.wrapper tag: 'div', class: 'input-append' do |append|
append.use :input
end
- input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
- input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
+ input.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
+ input.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
end
end
@@ -136,7 +136,7 @@
config.label_class = 'control-label'
# You can define the class to use on all forms. Default is simple_form.
- # config.form_class = :simple_form
+ config.form_class = 'simple_form form-horizontal'
# You can define which elements should obtain additional classes
# config.generate_additional_classes_for = [:wrapper, :label, :input]
View
1 config/initializers/sorcery.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
# The first thing you need to configure is which modules you need in your app.
# The default is nothing which will include only core features (password encryption, login/logout).
# Available submodules are: :user_activation, :http_basic_auth, :remember_me,
View
1 config/initializers/wrap_parameters.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
# Be sure to restart your server when you modify this file.
#
# This file contains settings for ActionController::ParamsWrapper which
View
1 config/routes.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
Pinkmine::Application.routes.draw do
get "logout" => "sessions#destroy", as: "logout"
get "login" => "sessions#new", as: "login"
View
1 db/migrate/20120425210953_create_projects.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
class CreateProjects < ActiveRecord::Migration
def change
create_table :projects do |t|
View
1 db/migrate/20120425211013_create_issues.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
class CreateIssues < ActiveRecord::Migration
def change
create_table :issues do |t|
View
1 db/migrate/20120427064910_create_users.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
View
1 db/migrate/20120427065047_add_creator_to_project.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
class AddCreatorToProject < ActiveRecord::Migration
def change
add_column :projects, :creator_id, :integer
View
1 db/migrate/20120427065225_add_responsable_to_issues.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
class AddResponsableToIssues < ActiveRecord::Migration
def change
add_column :issues, :responsable_id, :integer
View
1 db/migrate/20120427124402_add_creator_to_issues.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
class AddCreatorToIssues < ActiveRecord::Migration
def change
add_column :issues, :creator_id, :integer
View
1 db/migrate/20120427131211_add_responsable_to_project.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
class AddResponsableToProject < ActiveRecord::Migration
def change
add_column :projects, :responsable_id, :integer
View
11 db/migrate/20120502070424_add_personal_data_to_user.rb
@@ -0,0 +1,11 @@
+# -*- encoding : utf-8 -*-
+class AddPersonalDataToUser < ActiveRecord::Migration
+ def change
+ add_column :users, :name, :string
+ add_column :users, :surname1, :string
+ add_column :users, :surname2, :string
+ add_column :users, :born_on, :date
+ add_column :users, :twitter, :string
+ add_column :users, :github, :string
+ end
+end
View
10 db/schema.rb
@@ -1,4 +1,4 @@
-# encoding: UTF-8
+# -*- encoding : utf-8 -*-
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120427131211) do
+ActiveRecord::Schema.define(:version => 20120502070424) do
create_table "issues", :force => true do |t|
t.string "title"
@@ -43,6 +43,12 @@
t.datetime "remember_me_token_expires_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.string "name"
+ t.string "surname1"
+ t.string "surname2"
+ t.date "born_on"
+ t.string "twitter"
+ t.string "github"
end
add_index "users", ["remember_me_token"], :name => "index_users_on_remember_me_token"
View
1 db/seeds.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
View
3 spec/factories.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
FactoryGirl.define do
#
@@ -30,4 +31,4 @@
status 'unstarted'
end
-end
+end
View
56 spec/helpers/application_helper_spec.rb
@@ -0,0 +1,56 @@
+# -*- encoding : utf-8 -*-
+describe ApplicationHelper do
+
+ describe '#link_to' do
+ it 'accepts an :icon option that outputs an icon class attribute' do
+ link_to('Nowhere', '/route', icon: 'user').should have_tag('a i.icon-user')
+ end
+ end
+
+ describe '#default_text_for_bootstrap_alert' do
+ it "should have default texts for notice and success alerts" do
+ helper.default_text_for_bootstrap_alert(:success).should == '<strong>Listo!</strong> Se han actualizado los datos'
+ helper.default_text_for_bootstrap_alert('error').should == '<strong>Oh oh!</strong> Parece que hay algún dato erróneo'
+ helper.default_text_for_bootstrap_alert(:other_thing).should be_nil
+ end
+ end
+
+ describe '#bootstrap_alert' do
+ let(:alert) { helper.bootstrap_alert(received_text, :success) }
+ context 'when it dont receives any text' do
+ let(:received_text) { nil }
+ it 'should render a boostrap-styled alerts, fetching for a default text for that kind of alert' do
+ alert.should have_tag('.alert.alert-success') { with_tag('button.close') }
+ alert.should =~ /Se han actualizado los datos/
+ end
+ end
+ context 'when it receives a text' do
+ let(:received_text) { 'Alert de prueba' }
+ it 'should render a boostrap-styled alerts with that text' do
+ alert.should have_tag('.alert.alert-success') { with_tag('button.close') }
+ alert.should =~ /Alert de prueba/
+ end
+ end
+ end
+
+ describe '#bootstrap_flashes' do
+ let(:flashes){ helper.bootstrap_flashes }
+ it "should display an alert for each kind of flash entry" do
+ flash[:notice] = "Flash notice"
+ flash[:success] = "Flash success"
+ flash[:error] = "Flash explaining error"
+ flashes.should have_tag('.alert.alert-info', text: 'Flash notice')
+ flashes.should have_tag('.alert.alert-success', text: 'Flash success')
+ flashes.should have_tag('.alert.alert-error', text: 'Flash explaining error')
+ end
+ end
+
+ describe '#flash_class' do
+ it "should return the proper bootstrap class for the alert" do
+ helper.flash_class(:notice).should == 'alert-info'
+ helper.flash_class(:alert).should == 'alert-warning'
+ helper.flash_class('error').should == 'alert-error'
+ end
+ end
+
+end
View
3 spec/models/issue_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
describe Issue do
it_behaves_like "an object with responsable"
@@ -96,4 +97,4 @@
subject.should_not be_opened
end
-end
+end
View
3 spec/models/project_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
describe Project do
let(:saved_project){ Project.create }
@@ -25,4 +26,4 @@
saved_project.highest_code.should == '5'
end
-end
+end
View
1 spec/models/user_spec.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
describe User do
#
View
1 spec/spec_helper.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
View
1 spec/support/models/custom_matchers.rb
@@ -0,0 +1 @@
+# -*- encoding : utf-8 -*-
View
3 spec/support/models/with_creator_shared_examples.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
shared_examples_for "an object with creator" do
#
# Relations
@@ -19,4 +20,4 @@
subject.should be_created_by user
end
-end
+end
View
3 spec/support/models/with_responsable_shared_examples.rb
@@ -1,3 +1,4 @@
+# -*- encoding : utf-8 -*-
shared_examples_for "an object with responsable" do
#
# Relations
@@ -13,4 +14,4 @@
subject.should be_assigned_to user
end
-end
+end

0 comments on commit 2831e0c

Please sign in to comment.