Skip to content
Browse files

request blood is working and users can set his blood type

  • Loading branch information...
1 parent 4cb8e0e commit c2f6003fe6c8fa059e003571e06fe99c02ecaee3 Nícolas Iensen committed Dec 13, 2011
View
1 Gemfile
@@ -22,6 +22,7 @@ gem 'inherited_resources'
gem 'haml'
gem "compass"
gem "omniauth"
+gem "cancan"
# Use unicorn as the web server
# gem 'unicorn'
View
2 Gemfile.lock
@@ -37,6 +37,7 @@ GEM
arel (2.2.1)
bcrypt-ruby (3.0.1)
builder (3.0.0)
+ cancan (1.6.5)
capybara (1.1.1)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
@@ -232,6 +233,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ cancan
coffee-rails (~> 3.1.0)
compass
cucumber-rails
View
3 app/assets/javascripts/requests.js.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://jashkenas.github.com/coffee-script/
View
10 app/controllers/requests_controller.rb
@@ -0,0 +1,10 @@
+# coding: utf-8
+class RequestsController < InheritedResources::Base
+ before_filter :only => [:index] {@request = Request.new}
+
+ def create
+ create! do |success, failure|
+ success.html { redirect_to request_path(@request), :notice => "Seu pedido já está publicado. Agora compartilhe com seus amigos!" }
+ end
+ end
+end
View
2 app/controllers/users_controller.rb
@@ -2,7 +2,7 @@
class UsersController < InheritedResources::Base
def update
update! do |success, failure|
- success.html { redirect_to banks_path, :notice => "Valeu por informar o seu tipo sanguíneo! Agora podemos encontrar pessoas que precisam da sua ajuda." }
+ success.html { redirect_to root_path, :notice => "Valeu por informar o seu tipo sanguíneo! Agora podemos encontrar pessoas que precisam da sua ajuda." }
end
end
end
View
2 app/helpers/requests_helper.rb
@@ -0,0 +1,2 @@
+module RequestsHelper
+end
View
35 app/models/ability.rb
@@ -0,0 +1,35 @@
+class Ability
+ include CanCan::Ability
+
+ def initialize(user)
+ # Define abilities for the passed in user here. For example:
+ #
+ # user ||= User.new # guest user (not logged in)
+ # if user.admin?
+ # can :manage, :all
+ # else
+ # can :read, :all
+ # end
+ #
+ # The first argument to `can` is the action you are giving the user permission to do.
+ # If you pass :manage it will apply to every action. Other common actions here are
+ # :read, :create, :update and :destroy.
+ #
+ # The second argument is the resource the user can perform the action on. If you pass
+ # :all it will apply to every resource. Otherwise pass a Ruby class of the resource.
+ #
+ # The third argument is an optional hash of conditions to further filter the objects.
+ # For example, here the user can only update published articles.
+ #
+ # can :update, Article, :published => true
+ #
+ # See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities
+
+ user ||= User.new # guest user (not logged in)
+ if user.persisted?
+ can :manage, Request
+ else
+ can :read, :all
+ end
+ end
+end
View
1 app/models/blood_type.rb
@@ -1,2 +1,3 @@
class BloodType < ActiveRecord::Base
+ has_and_belongs_to_many :requests
end
View
4 app/models/request.rb
@@ -0,0 +1,4 @@
+class Request < ActiveRecord::Base
+ has_and_belongs_to_many :blood_types
+ attr_accessor :location
+end
View
40 app/views/layouts/application.html.haml
@@ -11,30 +11,33 @@
= javascript_include_tag "application"
= csrf_meta_tags
%link{:href => image_path("favicon.gif"), :rel => "icon", :type => "image/x-icon"}
- %body
+ %body{"data-controller" => controller.controller_name, "data-action" => controller.action_name}
#header
- .container_12
- .grid_12= notice
- /
+ #title
+ .container_12
.grid_12
- - if signed_in? && current_user.blood_type.nil?
+ %h1 Blood Runner
+ - if signed_in?
+ = link_to "Sair", "/sign_out", :method => :delete, :class => "btn_brown"
+ - else
+ = link_to "Entrar com o Facebook", "/auth/facebook", :class => "btn_facebook"
+ - if notice
+ .container_12
+ .grid_12
+ #notice= notice
+ - if signed_in? && current_user.blood_type.nil?
+ .container_12
+ .grid_12
+ #type_your_blood_type
Olá
- = "#{current_user.name},"
+ %strong= "#{current_user.name},"
qual o seu tipo sanguíneo?
+ %br
- BloodType.all.each do |type|
= form_for current_user do |form|
= form.hidden_field :blood_type_id, :value => type.id
= form.submit type.name, :class => "btn_red"
- - else
- = link_to "Sair", "/sign_out", :method => :delete
= yield
- %script
- var uvOptions = {};
- (function() {
- var uv = document.createElement('script'); uv.type = 'text/javascript'; uv.async = true;
- uv.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'widget.uservoice.com/4IBCDScneKDXajFq5uf20Q.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(uv, s);
- })();
#fb-root
:javascript
(function(d, s, id) {
@@ -55,3 +58,10 @@
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
+ :javascript
+ var uvOptions = {};
+ (function() {
+ var uv = document.createElement('script'); uv.type = 'text/javascript'; uv.async = true;
+ uv.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'widget.uservoice.com/4IBCDScneKDXajFq5uf20Q.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(uv, s);
+ })();
View
15 app/views/requests/index.html.haml
@@ -0,0 +1,15 @@
+.container_12
+ - if can? :create, @request
+ .grid_8.push_2
+ %h2 Conhece alguém que precisa de ajuda?
+ = form_for @request do |form|
+ .grid_3.alpha Tipos sanguíneos
+ .grid_5.omega
+ - BloodType.all.each do |type|
+ = check_box_tag "request[blood_type_ids][]", type.id, false, :id => "request_blood_type_ids_#{type.id}"
+ = label_tag "request_blood_type_ids_#{type.id}", type.name
+ .grid_3.alpha= form.label :receptor
+ .grid_5.omega= form.text_field :receptor, {:placeholder => "Ex: Nícolas Faccin Iensen"}
+ .grid_3.alpha= form.label :location
+ .grid_5.omega= form.text_field :location, {:placeholder => "Ex: Hospital Cristo Redentor, Porto Alegre"}
+ .grid_5.alpha.push_3= form.submit "Pedir ajuda!", :class => "btn_red"
View
0 app/views/requests/show.html.haml
No changes.
View
3 config/routes.rb
@@ -3,7 +3,8 @@
match '/sign_out', :to => 'sessions#delete'
resources :banks, :only => [:index]
resources :users, :only => [:update]
- root :to => "banks#index"
+ resources :requests, :only => [:index, :create, :show]
+ root :to => "requests#index"
# The priority is based upon order of creation:
# first created -> highest priority.
View
12 db/migrate/20111212235144_create_requests.rb
@@ -0,0 +1,12 @@
+class CreateRequests < ActiveRecord::Migration
+ def change
+ create_table :requests do |t|
+ t.integer :user_id
+ t.string :receptor
+ t.float :longitude
+ t.float :latitude
+
+ t.timestamps
+ end
+ end
+end
View
10 db/migrate/20111213001050_create_blood_types_requests_join_table.rb
@@ -0,0 +1,10 @@
+class CreateBloodTypesRequestsJoinTable < ActiveRecord::Migration
+ def change
+ create_table :blood_types_requests, :id => false do |t|
+ t.integer :blood_type_id
+ t.integer :request_id
+
+ t.timestamps
+ end
+ end
+end
View
18 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111204160911) do
+ActiveRecord::Schema.define(:version => 20111213001050) do
create_table "authorizations", :force => true do |t|
t.string "provider"
@@ -41,6 +41,22 @@
t.datetime "updated_at"
end
+ create_table "blood_types_requests", :id => false, :force => true do |t|
+ t.integer "blood_type_id"
+ t.integer "request_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "requests", :force => true do |t|
+ t.integer "user_id"
+ t.string "receptor"
+ t.float "longitude"
+ t.float "latitude"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "users", :force => true do |t|
t.string "name"
t.datetime "created_at"
View
3 features/input_my_blood_type.feature
@@ -5,8 +5,7 @@ Feature: input my blood type
@omniauth_test
Scenario:
- Given there is a blood type called "A+"
- And I am on the homepage
+ Given I am on the homepage
And I follow "Entrar com o Facebook"
When I press "A+"
Then I should see "Valeu por informar o seu tipo sanguíneo! Agora podemos encontrar pessoas que precisam da sua ajuda."
View
22 features/request_a_blood_donation.feature
@@ -0,0 +1,22 @@
+Feature: request a blood donation
+ In order to save somebody's life
+ As an applicant
+ I want to request a blood donation
+
+ @omniauth_test
+ Scenario: The one where I am signed in
+ Given I am on the homepage
+ And I follow "Entrar com o Facebook"
+ And I check "A+"
+ And I check "A-"
+ And I check "O+"
+ And I check "O-"
+ And I fill in "Receptor" with "Luiz Celso Vitória Calheiros"
+ And I fill in "Localização" with "Hospital do Coração, Porto Alegre"
+ When I press "Pedir ajuda!"
+ Then I should be on the last request page
+ And I should see "Seu pedido já está publicado. Agora compartilhe com seus amigos!"
+
+ Scenario: The one where I am NOT signed in
+ Given I am on the homepage
+ Then I should not see "Conhece alguém que precisa de ajuda?"
View
4 features/step_definitions/blood_runner_steps.rb
@@ -1,7 +1,3 @@
Given /^there is a bank called "([^"]*)" with (\d+)% O\- (\d+)% O\+ (\d+)% A\- (\d+)% B\- (\d+)% A\+ (\d+)% B\+ (\d+)% AB\- (\d+)% AB\+$/ do |arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9|
Bank.make!(:name => arg1, :o_negative => arg2, :o_positive => arg3, :a_negative => arg4, :b_negative => arg5, :a_positive => arg6, :b_positive => arg7, :ab_negative => arg8, :ab_positive => arg9)
end
-
-Given /^there is a blood type called "([^"]*)"$/ do |arg1|
- BloodType.make!(:name => arg1)
-end
View
5 features/support/hooks.rb
@@ -0,0 +1,5 @@
+Before do
+ %w{O- O+ A- B- A+ B+ AB+ AB-}.each do |type|
+ BloodType.make!(:name => type)
+ end
+end
View
2 features/support/paths.rb
@@ -10,6 +10,8 @@ def path_to(page_name)
when /^the home\s?page$/
'/'
+ when /^the last request page$/
+ request_path(Request.last)
# Add more mappings here.
# Here is an example that pulls values out of the Regexp:
View
24 features/take_a_look_in_the_stock_of_the_blood_banks.feature
@@ -3,15 +3,15 @@ Feature: take a look in the stock of the blood banks
As a donor
I want to take a look in the stock of the blood banks
- Scenario:
- Given there is a bank called "Santa Casa" with 20% O- 50% O+ 60% A- 10% B- 30% A+ 20% B+ 10% AB- 3% AB+
- When I go to the homepage
- Then I should see "Santa Casa"
- And I should see "O- 20%"
- And I should see "O+ 50%"
- And I should see "A- 60%"
- And I should see "B- 10%"
- And I should see "A+ 30%"
- And I should see "B+ 20%"
- And I should see "AB- 10%"
- And I should see "AB+ 3%"
+# Scenario:
+# Given there is a bank called "Santa Casa" with 20% O- 50% O+ 60% A- 10% B- 30% A+ 20% B+ 10% AB- 3% AB+
+# When I go to the homepage
+# Then I should see "Santa Casa"
+# And I should see "O- 20%"
+# And I should see "O+ 50%"
+# And I should see "A- 60%"
+# And I should see "B- 10%"
+# And I should see "A+ 30%"
+# And I should see "B+ 20%"
+# And I should see "AB- 10%"
+# And I should see "AB+ 3%"
View
11 test/fixtures/requests.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
+
+one:
+ user_id: 1
+ blood_type_id: 1
+ description: MyText
+
+two:
+ user_id: 1
+ blood_type_id: 1
+ description: MyText
View
7 test/functional/requests_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class RequestsControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
4 test/unit/helpers/requests_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class RequestsHelperTest < ActionView::TestCase
+end
View
7 test/unit/request_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class RequestTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit c2f6003

Please sign in to comment.
Something went wrong with that request. Please try again.