Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mamhoff committed Dec 12, 2013
1 parent 6726446 commit 6cdcd25
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 41 deletions.
6 changes: 5 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ class User < ActiveRecord::Base
has_and_belongs_to_many :roles

before_create :create_remember_token
before_save { self.email = email.downcase }
before_save do
pp email
self.email = email.downcase
pp self.email
end
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+.\-]+@[a-z\d.\-]+[\w][^\.]\.[a-z]{2,}/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
Expand Down
19 changes: 10 additions & 9 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
<%= csrf_meta_tags %>
</head>
<body>
<div class="container well">
<% flash.each do |key, value| %>
<%= content_tag(:div, value, class: "alert alert-#{key}") %>
<% end %>
<header class="row row-1">
<ul>

<% if signed_in? %>
<li><%= link_to "Sign out", destroy_user_session_path, html_options: {class: 'btn' }, method: "delete" %></li>
<li><%= link_to "Sign out", destroy_user_session_path, class: 'btn', method: "delete" %></li>
<% else %>
<li><%= link_to "Sign up", new_user_registration_path, html_options: {class: 'btn'} %></li>
<li><%= link_to "Sign in", new_user_session_path, html_options: {class: 'btn' } %></li>
</ul>
<li><%= link_to "Sign up", new_user_registration_path, class: 'btn' %></li>
<li><%= link_to "Sign in", new_user_session_path, class: 'btn' %></li>
<% end %>
</ul>
</header>
<div class="container well">
<% flash.each do |key, value| %>
<%= content_tag(:div, value, class: "alert alert-#{key}") %>
<% end %>
<%= yield %>
<%= debug(params) if Rails.env.development? %>
</div>
Expand Down
18 changes: 8 additions & 10 deletions app/views/roles/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<h1>Role index</h1>
<div class="col-md-6 col-md-offset-3">
<% @roles.each do |role| %>
<div class="well">
<p> <%= role.name %>
<%= link_to "delete", role, method: :delete,
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= link_to "Create Role", new_role_path %> <br/>
<% @roles.each do |role| %>
<p> <%= role.name %>
<%= link_to "delete", role, method: :delete,
data: {confirm: "Are you sure?"},
title: role.name %>

</p>
title: role.name %> </p>
<% end %>
</div>
<% end %>
<%= link_to "Create Role", new_role_path %>
</div>
27 changes: 16 additions & 11 deletions app/views/tours/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<h1>Tour index</h1>
<div class="col-md-6 col-md-offset-3">
<% @tours.each do |tour| %>
<div class="well">
<p> <%= tour.name %> <%= link_to "Buchen", new_wish_path %>

<div class="row row-2">
<div class="col-md-6 col-md-offset-3">
<% if user_signed_in? && current_user.has_role?('admin') %>
<%= link_to "delete", tour, method: :delete,
data: {confirm: "Are you sure?"},
title: tour.name %>
<%= link_to "Create tour", new_tour_path %>
<% end %>
<% @tours.each do |tour| %>
<div class="well">
<p> <%= tour.name %> <%= link_to "Buchen", new_wish_path(tour: tour.name) %>
<% if user_signed_in? && current_user.has_role?('admin') %>
<%= link_to "delete", tour, method: :delete,
data: {confirm: "Are you sure?"},
title: tour.name %>
<% end %>
</p>
</div>
<% end %>
</p>
</div>
<% end %>
<%= link_to "Create tour", new_tour_path %>
</div>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
get "users/show"
get "users/index"

resources :wishes, only: [:new]
resources :roles, only: [:new, :create, :index, :destroy]
resources :tours, only: [:new, :create, :destroy, :index, :show]
devise_for :users, :controllers => { registrations: 'users/registrations'}
Expand Down
4 changes: 2 additions & 2 deletions spec/factories.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryGirl.define do
factory :user do
name "Example User"
sequence(:email) { |n| "user-#{n}@example.com" }
email "user-80@example.com"
password "foobar"
password_confirmation "foobar"

Expand Down Expand Up @@ -57,7 +57,7 @@
end

factory :tour do
name "First Tour"
sequence(:name) { |n| "Tour #{n}" }
end

factory :booking_status do
Expand Down
14 changes: 8 additions & 6 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@
describe "email address with mixed case" do
mixed_case_email = "[email protected]"
it "should be saved as all lower-case" do
funny_user = FactoryGirl.create(:user, email: mixed_case_email)
funny_user = FactoryGirl.create(:user)
funny_user.email = mixed_case_email
#require 'pry'; binding.pry
funny_user.confirmed_at = Time.now
funny_user.save
expect(funny_user.reload.email).to eq mixed_case_email.downcase
end
end
Expand All @@ -94,11 +98,9 @@
specify { expect(admin.roles).to eq [Role.find_by(name: "admin")] }
end

it "FactoryGirl can create aa Guide at will" do
guide = FactoryGirl.create(:user, :guide)
pp guide.roles
expect(guide.has_role?("guide")).to eq true

it "FactoryGirl can create a Guide at will" do
guide = FactoryGirl.create(:user, :guide)
expect(guide.has_role?("guide")).to eq true
end

describe "unsetting a role" do
Expand Down
6 changes: 6 additions & 0 deletions spec/views/roles/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
expect(page).to have_link("Create Role")
end

it "should not have bootstrap columns without bootstrap rows as parents" do
expect(page).not_to have_selector(:xpath, \
"//div[contains(@class, 'col') and parent::*[not(contains(@class, 'row'))]]")
end


describe "clicking a delete link" do

it "should decrease the role count by 1" do
Expand Down
33 changes: 31 additions & 2 deletions spec/views/tours/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

describe "roles/index.html.erb" do
before do
FactoryGirl.create(:tour)
5.times { FactoryGirl.create(:tour) }
visit tours_path
end

it "should have the word tour index" do
pp Capybara::default_driver
expect(page).to have_content("Tour index")
end

Expand All @@ -18,6 +19,34 @@
expect(page).to have_link("Buchen")
end

it "should not have bootstrap columns without bootstrap rows as parents" do
expect(page).not_to have_selector(:xpath, \
"//div[contains(@class, 'col') and parent::*[not(contains(@class, 'row'))]]")
end

describe "all the links" do
# extract the urls from the elements found by "find"
let(:links) do
page.all(:xpath, "//div[@class='well']/p/a").map do |link_object|
link_object[:href]
end
end

let(:tournames) { Tour.all.map { |tour| CGI.escape(tour.name) } }

it "should be exactly as many as there are tours" do
expect(links.length).to eq tournames.length
end

it "each tour should have an associated link" do
result = true
tournames.each do |tourname|
result &= links.any? { |link| link[tourname] }
end
expect(result).to eq true
end
end

describe "signed in as admin" do

before do
Expand All @@ -27,7 +56,7 @@
end

it "should have one tour" do
expect(Tour.count).to eq 1
expect(Tour.count).to eq 5
end

it "should have delete links" do
Expand Down

0 comments on commit 6cdcd25

Please sign in to comment.