Skip to content

Commit

Permalink
first tests, for simple managing pets
Browse files Browse the repository at this point in the history
  • Loading branch information
Fodoj committed Feb 15, 2012
1 parent b3eb8d0 commit 590e911
Show file tree
Hide file tree
Showing 39 changed files with 117 additions and 632 deletions.
25 changes: 10 additions & 15 deletions .gitignore
@@ -1,15 +1,10 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile ~/.gitignore_global

# Ignore bundler config
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
.bundle
db/*.sqlite3
db/sample/images/*
log/*.log
public/system
tmp/
coverage/
.sass-cache/
*.swp
rails_best_practices_output.html
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--colour
3 changes: 1 addition & 2 deletions Gemfile
Expand Up @@ -44,7 +44,6 @@ group :development, :test do
gem 'rspec'
gem 'rspec-rails'
gem 'email_spec'
gem "autotest"
gem "autotest-rails"
gem "launchy"
end

16 changes: 4 additions & 12 deletions Gemfile.lock
Expand Up @@ -7,7 +7,6 @@ GIT
GEM
remote: https://rubygems.org/
specs:
ZenTest (4.5.0)
actionmailer (3.2.0)
actionpack (= 3.2.0)
mail (~> 2.4.0)
Expand Down Expand Up @@ -35,12 +34,9 @@ GEM
activesupport (3.2.0)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.2.6)
archive-tar-minitar (0.5.2)
arel (3.0.0)
autotest (4.4.6)
ZenTest (>= 4.4.1)
autotest-rails (4.1.1)
ZenTest (= 4.5)
bcrypt-ruby (3.0.1)
builder (3.0.0)
cancan (1.6.7)
Expand Down Expand Up @@ -68,10 +64,6 @@ GEM
gherkin (~> 2.7.1)
json (>= 1.4.6)
term-ansicolor (>= 1.0.6)
cucumber-rails (1.2.1)
capybara (>= 1.1.2)
cucumber (>= 1.1.3)
nokogiri (>= 1.5.0)
database_cleaner (0.7.0)
devise (1.5.2)
bcrypt-ruby (~> 3.0)
Expand Down Expand Up @@ -103,6 +95,8 @@ GEM
kaminari (0.12.4)
rails (>= 3.0.0)
kgio (2.7.2)
launchy (2.0.5)
addressable (~> 2.2.6)
libv8 (3.3.10.4)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
Expand Down Expand Up @@ -218,12 +212,9 @@ PLATFORMS
ruby

DEPENDENCIES
autotest
autotest-rails
cancan
capybara
coffee-rails (~> 3.2.1)
cucumber-rails
database_cleaner
devise
email_spec
Expand All @@ -232,6 +223,7 @@ DEPENDENCIES
forgery
jquery-rails
kaminari
launchy
nested_form!
paperclip
pg
Expand Down
18 changes: 13 additions & 5 deletions app/controllers/admin/pets_controller.rb
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
class Admin::PetsController < Admin::ApplicationController
before_filter :find_photo, :except => [:index, :new, :create]
before_filter :find_pet, :except => [:index, :new, :create]

def index
@pets = Pet.all
Expand All @@ -11,13 +11,15 @@ def show

def new
@pet = Pet.new
@pet.kennel = Person.new
end

def create
@pet = Pet.new(params[:pet])

@pet.save
if @pet.save
flash[:info] = "Добавлен питомец '#{@pet.name}'"
end

redirect_to admin_pets_path
end

Expand All @@ -26,15 +28,21 @@ def edit

def update
if @pet.update_attributes(params[:pet])
flash[:info] = "Питомец успешно обновлен"
flash[:info] = "Питомец '#{@pet.name}' успешно обновлен"
else
flash[:error] = "Что-то пошло не так"
end
redirect_to admin_pets_path
end

def destroy
@pet.destroy
flash[:error] = "Питомец '#{@pet.name}' удалён"
redirect_to :back
end

private
def find_photo
def find_pet
@pet = Pet.find(params[:id])
end
end
1 change: 0 additions & 1 deletion app/models/person.rb
@@ -1,6 +1,5 @@
class Person < ActiveRecord::Base
include Rolify::Roles
# extend Rolify::Dynamic
has_and_belongs_to_many :roles, :join_table => :people_roles
has_many :pets

Expand Down
1 change: 1 addition & 0 deletions app/models/role.rb
@@ -1,4 +1,5 @@
class Role < ActiveRecord::Base
has_and_belongs_to_many :people, :join_table => :people_roles
belongs_to :resource, :polymorphic => true
validates :name, :uniqueness => true
end
6 changes: 3 additions & 3 deletions app/views/admin/pets/_form.html.erb
@@ -1,4 +1,4 @@
<%= nested_form_for [:admin, @pet], :html => { :class => "form-horizontal pet-form", :multipart => true } do |f| %>
<%= nested_form_for [:admin, pet], :html => { :class => "form-horizontal pet-form", :multipart => true } do |f| %>

<div class="row">
<div class="span5">
Expand Down Expand Up @@ -28,10 +28,10 @@
<div class="controls">

<div class="btn-group pet-type-buttons" data-toggle="buttons-radio">
<a class="btn <%== 'active' if @pet.sex %>" data-sex="true" title="Кобель" href="#">
<a class="btn <%== 'active' if pet.sex %>" data-sex="true" title="Кобель" href="#">
Кобель
</a>
<a class="btn <%== 'active' if !@pet.sex %>" data-sex="false" title="Сука" href="#">
<a class="btn <%== 'active' if !pet.sex %>" data-sex="false" title="Сука" href="#">
Сука
</a>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/pets/_pets_table.html.erb
Expand Up @@ -29,8 +29,8 @@
<td><%= pet.kennel_name if pet.kennel.present? %></td>

<td class="pets-actions">
<%= link_to raw("<i class='icon-edit'></i>"), edit_admin_pet_path(pet), :class => "btn btn-small", :title => "Редактировать" %>
<%= link_to raw("<i class='icon-remove'></i>"), admin_pet_path(pet), :method => :delete, :class => "btn btn-small", :title => "Удалить" %>
<%= link_to raw("<i class='icon-edit'></i>"), edit_admin_pet_path(pet), :class => "btn btn-small", :title => "Редактировать питомца '#{pet.name}'" %>
<%= link_to raw("<i class='icon-remove'></i>"), admin_pet_path(pet), :method => :delete, :class => "btn btn-small", :title => "Удалить питомца 'Bobby'" %>
</td>

</tr>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/pets/edit.html.erb
Expand Up @@ -3,6 +3,6 @@

<div class="span10">
<h1>Редактировать питомца</h1>
<%= render "form" %>
<%= render "form", :pet => @pet %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/admin/pets/new.html.erb
Expand Up @@ -3,6 +3,6 @@

<div class="span10">
<h1>Новый питомец</h1>
<%= render "form" %>
<%= render "form", :pet => @pet %>
</div>
</div>
6 changes: 5 additions & 1 deletion app/views/layouts/admin.html.erb
Expand Up @@ -9,7 +9,11 @@
<body id="admin">

<%= render "admin/shared/header" %>

<div class="container">
<% flash.each do |name, msg| %>
<%= render "shared/notification", :name => name, :msg => msg %>
<% end %>
</div>
<div class="container container-main">
<%= yield %>
</div>
Expand Down
4 changes: 4 additions & 0 deletions app/views/shared/_notification.html.erb
@@ -0,0 +1,4 @@
<div class="alert alert-<%= name %>">
<a class='close' data-dismiss="alert">×</a>
<%= msg %>
</div>
2 changes: 2 additions & 0 deletions config/environments/test.rb
Expand Up @@ -35,3 +35,5 @@
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
end

ActiveSupport::Deprecation.silenced = true
2 changes: 2 additions & 0 deletions db/seeds.rb
Expand Up @@ -5,3 +5,5 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)

roles = Role.create( [{ name: "owner"}, { name: "breeder"}, { name: "kennel"}] )
Empty file added log/.gitkeep
Empty file.
157 changes: 0 additions & 157 deletions spec/controllers/admin/users_controller_spec.rb

This file was deleted.

0 comments on commit 590e911

Please sign in to comment.