aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlban Peignier2012-03-11 11:54:00 +0100
committerAlban Peignier2012-03-11 11:54:12 +0100
commitdc8a6f7f9182996ea3f39986b45c3a71927a8e4a (patch)
treef6c2e5c48a896dc43f8c0795eb1f557b82483c80
parentae88454853f146acc6f1368a14e1180be2650d03 (diff)
downloadchouette-core-dc8a6f7f9182996ea3f39986b45c3a71927a8e4a.tar.bz2
Add validations. Fixes specs
-rw-r--r--.gitignore1
-rw-r--r--Gemfile4
-rw-r--r--Gemfile.lock13
-rw-r--r--Guardfile19
-rw-r--r--app/helpers/search_helper.rb11
-rw-r--r--app/models/referential.rb10
-rw-r--r--app/views/lines/_form.erb6
-rw-r--r--app/views/lines/_line.erb2
-rw-r--r--app/views/lines/index.html.erb8
-rw-r--r--spec/factories/chouette_lines.rb5
-rw-r--r--spec/factories/referential.rb8
-rw-r--r--spec/models/chouette/line_spec.rb15
-rw-r--r--spec/requests/companies_spec.rb7
-rw-r--r--spec/requests/lines_spec.rb5
-rw-r--r--spec/requests/networks_spec.rb5
-rw-r--r--spec/requests/referentials_spec.rb5
-rw-r--r--spec/spec_helper.rb3
-rw-r--r--spec/views/lines/index.html.erb_spec.rb12
-rw-r--r--spec/views/lines/show.html.erb_spec.rb4
19 files changed, 105 insertions, 38 deletions
diff --git a/.gitignore b/.gitignore
index eb3489a98..6ae23e215 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,3 +13,4 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
+*~
diff --git a/Gemfile b/Gemfile
index 4fad5fc98..b575b61d1 100644
--- a/Gemfile
+++ b/Gemfile
@@ -52,13 +52,15 @@ gem 'will_paginate', '~> 3.0'
gem 'ransack'
gem 'squeel'
-gem 'chouette-ninoxe', :git => 'git://chouette.dryade.priv/ninoxe'#, :path => '~/Projects/Ninoxe'
+gem 'chouette-ninoxe', :git => 'git://chouette.dryade.priv/ninoxe' #, :path => '~/Projects/Ninoxe'
group :development do
gem 'autotest-rails'
gem 'autotest-notification'
gem 'capistrano'
gem 'capistrano-ext'
+ gem 'guard'
+ gem 'guard-rspec'
end
group :test, :development, :cucumber do
diff --git a/Gemfile.lock b/Gemfile.lock
index acda1dfbd..7c6a67447 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: git://chouette.dryade.priv/ninoxe
- revision: 5ffbe157e7d72379da01834a6f0830f0500d7526
+ revision: ba81d9e4b2d6c9d72cd06632d167078a671ce7b8
specs:
chouette-ninoxe (0.0.8)
GeoRuby
@@ -89,7 +89,7 @@ GEM
activesupport (3.1.3)
multi_json (~> 1.0)
addressable (2.2.6)
- arel (2.2.2)
+ arel (2.2.3)
autotest-notification (2.3.4)
autotest-standalone (~> 4.5)
autotest-rails (4.1.1)
@@ -153,6 +153,11 @@ GEM
json (>= 1.4.6)
gherkin (2.7.6-java)
json (>= 1.4.6)
+ guard (1.0.1)
+ ffi (>= 0.5.0)
+ thor (~> 0.14.6)
+ guard-rspec (0.6.0)
+ guard (>= 0.10.0)
has_scope (0.5.1)
highline (1.6.11)
hike (1.2.1)
@@ -280,7 +285,7 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
- tzinfo (0.3.31)
+ tzinfo (0.3.32)
uglifier (1.2.1)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
@@ -316,6 +321,8 @@ DEPENDENCIES
factory_girl
factory_girl_rails
formtastic
+ guard
+ guard-rspec
inherited_resources
jquery-rails
jruby-openssl
diff --git a/Guardfile b/Guardfile
new file mode 100644
index 000000000..1cba9ca4a
--- /dev/null
+++ b/Guardfile
@@ -0,0 +1,19 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+ # Capybara request specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+end
+
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb
new file mode 100644
index 000000000..eaeac99d8
--- /dev/null
+++ b/app/helpers/search_helper.rb
@@ -0,0 +1,11 @@
+module SearchHelper
+
+ def link_with_search(name, search, html_options = {})
+ is_current = (@q and search.all? { |k,v| @q.send(k) == v })
+ if is_current
+ html_options[:class] = [html_options[:class], "current"].compact.join(" ")
+ end
+ link_to name, params.deep_merge("q" => search), html_options
+ end
+
+end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index b08f6be4c..d0fdbd676 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -17,14 +17,20 @@ class Referential < ActiveRecord::Base
Chouette::Company.scoped
end
+ def switch
+ raise "Referential not created" if new_record?
+ Apartment::Database.switch(slug)
+ self
+ end
+
private
def create_schema
- Apartment::Database.create self.slug
+ Apartment::Database.create slug
end
def destroy_schema
- Apartment::Database.drop self.slug
+ Apartment::Database.drop slug
end
end
diff --git a/app/views/lines/_form.erb b/app/views/lines/_form.erb
index 4a6285e6e..a3eb8f6f1 100644
--- a/app/views/lines/_form.erb
+++ b/app/views/lines/_form.erb
@@ -1,9 +1,11 @@
+<!-- <%= @line.errors.inspect %> -->
<%= semantic_form_for [@referential, @line] do |form| %>
<%= form.inputs do %>
+ <%= form.input :name %>
+ <%= form.input :objectid %>
+ <%= form.input :registration_number %>
<%= form.input :network, :as => :select, :collection => Chouette::Network.all, :include_blank => false %>
<%= form.input :company, :as => :select, :collection => Chouette::Company.all, :include_blank => false%>
- <%= form.input :registration_number %>
- <%= form.input :name %>
<%= form.input :published_name %>
<%= form.input :number %>
<%= form.input :transport_mode_name, :as => :select, :collection => Chouette::TransportMode.definitions, :include_blank => false, :member_label => Proc.new { |a| t("#{a[0]}") } %>
diff --git a/app/views/lines/_line.erb b/app/views/lines/_line.erb
index 66b6b8529..f38bbc193 100644
--- a/app/views/lines/_line.erb
+++ b/app/views/lines/_line.erb
@@ -1,7 +1,7 @@
<%= div_for(line) do %>
<%= link_to([@referential, line], :class => "preview", :title => "Ligne #{line.number}") do %>
<div class="color">
- <% if line.number.length <= 3 %>
+ <% if line.number and line.number.length <= 3 %>
<div class="number"><%= line.number %></div>
<% end %>
</div>
diff --git a/app/views/lines/index.html.erb b/app/views/lines/index.html.erb
index aa36bfb99..46a41534f 100644
--- a/app/views/lines/index.html.erb
+++ b/app/views/lines/index.html.erb
@@ -41,18 +41,18 @@
<ul class="selection">
<% @referential.companies.each do |company| %>
-<li><%= link_to company.name, params.deep_merge("q" => {"company_id_eq" => company.id}), :class => ("current" if @q.company_id_eq == company.id) %></li>
+<li><%= link_with_search company.name, "company_id_eq" => company.id %></li>
<% end %>
-<li><%= link_to "Toutes", params.deep_merge("q" => {"company_id_eq" => nil}), :class => ["all", ("current" if @q.company_id_eq.blank?)].compact.join(" ") %></li>
+<li><%= link_with_search "Toutes", {"company_id_eq" => nil}, :class => "all" %></li>
</ul>
<h4><%= Chouette::Network.model_name.human.pluralize %></h4>
<ul class="selection">
<% @referential.networks.each do |network| %>
-<li><%= link_to network.name, params.deep_merge("q" => {"network_id_eq" => network.id}), :class => ("current" if @q.network_id_eq == network.id) %></li>
+<li><%= link_with_search network.name, "network_id_eq" => network.id %></li>
<% end %>
-<li><%= link_to "Tous", params.deep_merge("q" => {"network_id_eq" => nil}), :class => ["all", ("current" if @q.network_id_eq.blank?)].compact.join(" ") %></li>
+<li><%= link_with_search "Tous", {"network_id_eq" => nil}, :class => "all" %></li>
</ul>
<% end %>
diff --git a/spec/factories/chouette_lines.rb b/spec/factories/chouette_lines.rb
index 5fff06778..2f5b1d2a5 100644
--- a/spec/factories/chouette_lines.rb
+++ b/spec/factories/chouette_lines.rb
@@ -1,6 +1,9 @@
Factory.define :line, :class => "Chouette::Line" do |line|
line.sequence(:name) { |n| "Line #{n}" }
- line.sequence(:objectid) { |n| "Line:#{n}" }
+ line.sequence(:objectid) { |n| "test:Line:#{n}" }
+
line.association :network, :factory => :network
line.association :company, :factory => :company
+
+ line.sequence(:registration_number) { |n| "test-#{n}" }
end
diff --git a/spec/factories/referential.rb b/spec/factories/referential.rb
index 4bdacb8c7..5c87a5427 100644
--- a/spec/factories/referential.rb
+++ b/spec/factories/referential.rb
@@ -1,4 +1,4 @@
-Factory.define :referential, :class => "Referential" do |f|
- f.sequence(:name) { |n| "Referential #{n}" }
- f.sequence(:slug) { |n| "referential_#{n}" }
-end \ No newline at end of file
+Factory.define :referential do |f|
+ f.sequence(:name) { |n| "Test #{n}" }
+ f.sequence(:slug) { |n| "test_#{n}" }
+end
diff --git a/spec/models/chouette/line_spec.rb b/spec/models/chouette/line_spec.rb
new file mode 100644
index 000000000..f5f7286c3
--- /dev/null
+++ b/spec/models/chouette/line_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe Chouette::Line do
+
+ subject { Factory :line }
+
+ it { should validate_presence_of :name }
+
+ it { should validate_presence_of :objectid }
+
+ it { should validate_numericality_of :version }
+
+ it { should validate_uniqueness_of :registrationnumber }
+
+end
diff --git a/spec/requests/companies_spec.rb b/spec/requests/companies_spec.rb
index b7a938977..be3f28c9d 100644
--- a/spec/requests/companies_spec.rb
+++ b/spec/requests/companies_spec.rb
@@ -1,12 +1,11 @@
require 'spec_helper'
describe "Companies" do
- let!(:referential) { Factory(:referential) }
- let!(:companies) { Array.new(2) { Factory(:company) } }
+ let!(:referential) { Factory(:referential).switch }
+ let!(:companies) { referential; Array.new(2) { Factory(:company) } }
describe "GET /companies" do
- it "works! (now write some real specs)" do
- # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
+ it "should display company names" do
visit referential_companies_path(referential)
page.should have_content(companies.first.name)
end
diff --git a/spec/requests/lines_spec.rb b/spec/requests/lines_spec.rb
index 8633ee220..d5c9eea2f 100644
--- a/spec/requests/lines_spec.rb
+++ b/spec/requests/lines_spec.rb
@@ -1,8 +1,9 @@
require 'spec_helper'
describe "Lines" do
- let!(:referential) { Factory(:referential) }
- let!(:lines) { Array.new(2) { Factory(:line) } }
+
+ let!(:referential) { Factory(:referential).switch }
+ let!(:lines) { referential; Array.new(2) { Factory(:line) } }
describe "GET /lines" do
it "works! (now write some real specs)" do
diff --git a/spec/requests/networks_spec.rb b/spec/requests/networks_spec.rb
index 17386b00a..b8b7fc8b4 100644
--- a/spec/requests/networks_spec.rb
+++ b/spec/requests/networks_spec.rb
@@ -1,12 +1,11 @@
require 'spec_helper'
describe "Networks" do
- let!(:referential) { Factory(:referential) }
- let!(:networks) { Array.new(2) { Factory(:network) } }
+ let!(:referential) { Factory(:referential).switch }
+ let!(:networks) { referential; Array.new(2) { Factory(:network) } }
describe "GET /networks" do
it "works! (now write some real specs)" do
- # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
visit referential_networks_path(referential)
page.should have_content(networks.first.name)
end
diff --git a/spec/requests/referentials_spec.rb b/spec/requests/referentials_spec.rb
index c3ed49234..4dc378780 100644
--- a/spec/requests/referentials_spec.rb
+++ b/spec/requests/referentials_spec.rb
@@ -29,13 +29,12 @@ describe "Referentials" do
end
describe "destroy" do
- let(:referential) { Factory(:referential, :slug => "Referential destroyed") }
+ let(:referential) { Factory(:referential) }
it "should" do
visit referential_path(referential)
click_link "Supprimer"
- Referential.where(:slug => "Referential destroyed").should be_nil
- # DELETE SCHEMA
+ Referential.where(:slug => referential.slug).should be_blank
end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 1fd4d6894..d838f18e5 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -12,6 +12,8 @@ require 'capybara/rails'
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+require 'will_paginate/array'
+
RSpec.configure do |config|
DatabaseCleaner.logger = Rails.logger
# ## Mock Framework
@@ -45,6 +47,7 @@ RSpec.configure do |config|
end
config.after(:each) do
+ Apartment::Database.switch(nil)
DatabaseCleaner.clean
end
diff --git a/spec/views/lines/index.html.erb_spec.rb b/spec/views/lines/index.html.erb_spec.rb
index a290080eb..ddd7d9c76 100644
--- a/spec/views/lines/index.html.erb_spec.rb
+++ b/spec/views/lines/index.html.erb_spec.rb
@@ -2,14 +2,14 @@ require 'spec_helper'
describe "/lines/index" do
- let!(:referential) { assign( :referential, Factory(:referential) ) }
- let!(:network) { Factory(:network) }
- let!(:company) { Factory(:company) }
- let!(:lines) { assign( :lines, Array.new(2) { Factory(:line, :network => network, :company => company) } ) }
+ let!(:referential) { assign :referential, Factory(:referential) }
+ let!(:network) { Factory :network }
+ let!(:company) { Factory :company }
+ let!(:lines) { assign :lines, Array.new(2) { Factory(:line, :network => network, :company => company) }.paginate }
+ let!(:q) { assign :q, Ransack::Search.new(Chouette::Line) }
before :each do
- rendered.stub(:collection).and_return( lines.order_by [[:number, :asc]] )
- view.stub(:link_to_order).and_return( "#" )
+ view.stub(:link_with_search).and_return("#")
end
it "should render a show link for each group" do
diff --git a/spec/views/lines/show.html.erb_spec.rb b/spec/views/lines/show.html.erb_spec.rb
index 9d5b53cd3..edb7e8741 100644
--- a/spec/views/lines/show.html.erb_spec.rb
+++ b/spec/views/lines/show.html.erb_spec.rb
@@ -2,8 +2,8 @@ require 'spec_helper'
describe "/lines/show" do
- let!(:referential) { assign(:referential, Factory(:referential)) }
- let!(:line) { assign(:line, Factory(:line)) }
+ let!(:referential) { assign :referential, Factory(:referential) }
+ let!(:line) { assign :line, Factory(:line) }
it "should render h2 with the line name" do
render