aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2012-02-15 12:10:49 +0100
committerLuc Donnet2012-02-15 12:10:49 +0100
commitfa26c241d19bea9b15ada7392a4a8de682794c09 (patch)
tree353a5a74b50eb3b550ccd0cd182e767ec361a268
parentd2121da8941e8e4154fe6970badcd44278e86074 (diff)
downloadchouette-core-fa26c241d19bea9b15ada7392a4a8de682794c09.tar.bz2
Add line to the model
-rw-r--r--app/controllers/application_controller.rb1
-rw-r--r--app/controllers/lines_controller.rb6
-rw-r--r--app/helpers/application_helper.rb16
-rw-r--r--app/helpers/lines_helper.rb6
-rw-r--r--app/views/lines/_form.erb2
-rw-r--r--app/views/lines/_line.erb4
-rw-r--r--app/views/lines/index.html.erb11
-rw-r--r--app/views/lines/show.html.erb4
-rw-r--r--config/initializers/apartment.rb3
-rw-r--r--config/initializers/ninoxe.rb42
-rw-r--r--db/migrate/20120213131553_create_chouette_line.rb26
-rw-r--r--spec/factories/chouette_lines.rb9
-rw-r--r--spec/spec_helper.rb1
-rw-r--r--spec/views/lines/edit.html.erb_spec.rb16
-rw-r--r--spec/views/lines/index.html.erb_spec.rb12
-rw-r--r--spec/views/lines/new.html.erb_spec.rb6
-rw-r--r--spec/views/lines/show.html.erb_spec.rb17
17 files changed, 125 insertions, 57 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index e8065d950..7050568de 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,3 +1,4 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+
end
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb
index 83ab01674..2ee4d8729 100644
--- a/app/controllers/lines_controller.rb
+++ b/app/controllers/lines_controller.rb
@@ -1,4 +1,4 @@
-class LinesController < InheritedResources::Base
+class LinesController < ChouetteController
defaults :resource_class => Chouette::Line
helper_method :sort_column, :sort_direction
respond_to :html
@@ -8,11 +8,9 @@ class LinesController < InheritedResources::Base
protected
def collection
- @lines ||= Chouette::Line.all.order_by [[sort_column.to_sym, sort_direction.to_sym]]
+ @lines ||= referential.lines.order_by [[sort_column.to_sym, sort_direction.to_sym]]
end
- private
-
def sort_column
%w(name number).include?(params[:sort]) ? params[:sort] : "name"
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index a16d32d46..ef354cc30 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -3,5 +3,21 @@ module ApplicationHelper
def chouette_line_path(line)
line_path(line)
end
+
+ def chouette_network_path(line)
+ network_path(line)
+ end
+
+ def chouette_company_path(line)
+ company_path(line)
+ end
+
+ def link_to_order(name, column)
+ css_class = (column == sort_column) ? "current #{sort_direction}" : nil
+ Rails.logger.debug sort_direction.inspect
+ direction = (column == sort_column && sort_direction == "asc") ? "desc" : "asc"
+ Rails.logger.debug direction.inspect
+ link_to name, { :sort => column, :direction => direction}, {:class => css_class}
+ end
end
diff --git a/app/helpers/lines_helper.rb b/app/helpers/lines_helper.rb
index 45bd8c6c3..a03868a0a 100644
--- a/app/helpers/lines_helper.rb
+++ b/app/helpers/lines_helper.rb
@@ -1,8 +1,2 @@
module LinesHelper
- def order(column)
- title ||= Chouette::Line.human_attribute_name(column).titleize
- css_class = (column == sort_column) ? "current #{sort_direction}" : nil
- direction = (column == sort_column && sort_direction == "asc") ? "desc" : "asc"
- link_to title, { :sort => column, :direction => direction}, {:class => css_class}
- end
end
diff --git a/app/views/lines/_form.erb b/app/views/lines/_form.erb
index 76c2ec53d..19a3b8b84 100644
--- a/app/views/lines/_form.erb
+++ b/app/views/lines/_form.erb
@@ -1,4 +1,4 @@
-<%= semantic_form_for @line do |form| %>
+<%= semantic_form_for [@referential, @line] do |form| %>
<%= form.inputs do %>
<%= form.input :network, :as => :select, :collection => Chouette::Network.all, :include_blank => false %>
<%= form.input :company, :as => :select, :collection => Chouette::Company.all, :include_blank => false%>
diff --git a/app/views/lines/_line.erb b/app/views/lines/_line.erb
index 7fd0daded..f594c7f9d 100644
--- a/app/views/lines/_line.erb
+++ b/app/views/lines/_line.erb
@@ -1,10 +1,10 @@
<%= div_for(line) do %>
- <%= link_to(line, :class => "preview") do %>
+ <%= link_to([@referential, line], :class => "preview") do %>
<div class="color" style="background-color: grey ">
<div class="number"><%= line.number %></div>
</div>
<% end %>
- <%= link_to line.name, line %>
+ <%= link_to line.name, [@referential, line] %>
<div class="info">
</div>
diff --git a/app/views/lines/index.html.erb b/app/views/lines/index.html.erb
index 7ac2aab8c..03f5331e0 100644
--- a/app/views/lines/index.html.erb
+++ b/app/views/lines/index.html.erb
@@ -1,7 +1,8 @@
-<div class="order">
- Trier par
- <%= order "name" %> |
- <%= order "number" %>
+<div class="order">
+ Trier par
+ <%= link_to_order "Code", "code" %> |
+ <%= link_to_order "Priorité", "priority" %> |
+ <%= link_to_order "Nom", "name" %>
</div>
<%= title_tag Chouette::Line.model_name.human.pluralize %>
@@ -10,7 +11,7 @@
<% content_for :sidebar do %>
<ul class="actions">
- <li><%= link_to t('lines.actions.new'), new_line_path, :class => "add" %></li>
+ <li><%= link_to t('lines.actions.new'), new_referential_line_path(@referential), :class => "add" %></li>
<br>
</ul>
<% end %>
diff --git a/app/views/lines/show.html.erb b/app/views/lines/show.html.erb
index 50932fef6..f0d987d3f 100644
--- a/app/views/lines/show.html.erb
+++ b/app/views/lines/show.html.erb
@@ -40,8 +40,8 @@
<% content_for :sidebar do %>
<ul class="actions">
- <li><%= link_to t('lines.actions.edit'), edit_line_path(@line), :class => "edit" %></li>
- <li><%= link_to t('lines.actions.destroy'), line_path(@line), :method => :delete, :confirm => t('lines.actions.destroy_confirm'), :class => "remove" %></li>
+ <li><%= link_to t('lines.actions.edit'), edit_referential_line_path(@referential, @line), :class => "edit" %></li>
+ <li><%= link_to t('lines.actions.destroy'), referential_line_path(@referential, @line), :method => :delete, :confirm => t('lines.actions.destroy_confirm'), :class => "remove" %></li>
<br>
</ul>
<% end %>
diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb
index d51724a04..6c345f7f8 100644
--- a/config/initializers/apartment.rb
+++ b/config/initializers/apartment.rb
@@ -1,4 +1,7 @@
Apartment.configure do |config|
# set your options (described below) here
config.excluded_models = ["Referential"] # these models will not be multi-tenanted, but remain in the global (public) namespace
+
+ # Dynamically get database names to migrate
+ config.database_names = lambda{ Referential.select(:slug).map(&:slug) }
end \ No newline at end of file
diff --git a/config/initializers/ninoxe.rb b/config/initializers/ninoxe.rb
index 10ac5e02d..5e168d549 100644
--- a/config/initializers/ninoxe.rb
+++ b/config/initializers/ninoxe.rb
@@ -1,10 +1,32 @@
-class Chouette::Line
- def self.model_name
- name = "Line"
- def name.name
- self
- end
- ActiveModel::Name.new name
- end
-
-end
+# class Chouette::Line
+# def self.model_name
+# name = "Line"
+# def name.name
+# self
+# end
+# ActiveModel::Name.new name
+# end
+
+# end
+
+# class Chouette::Network
+# def self.model_name
+# name = "Network"
+# def name.name
+# self
+# end
+# ActiveModel::Name.new name
+# end
+
+# end
+
+# class Chouette::Company
+# def self.model_name
+# name = "Company"
+# def name.name
+# self
+# end
+# ActiveModel::Name.new name
+# end
+
+# end
diff --git a/db/migrate/20120213131553_create_chouette_line.rb b/db/migrate/20120213131553_create_chouette_line.rb
new file mode 100644
index 000000000..09a674183
--- /dev/null
+++ b/db/migrate/20120213131553_create_chouette_line.rb
@@ -0,0 +1,26 @@
+class CreateChouetteLine < ActiveRecord::Migration
+ def up
+ create_table "line", :force => true do |t|
+ t.integer "ptnetworkid", :limit => 8
+ t.integer "companyid", :limit => 8
+ t.string "objectid"
+ t.integer "objectversion"
+ t.datetime "creationtime"
+ t.string "creatorid"
+ t.string "name"
+ t.string "number"
+ t.string "publishedname"
+ t.string "transportmodename"
+ t.string "registrationnumber"
+ t.string "comment"
+ t.boolean "mobilityrestrictedsuitable"
+ t.integer "userneeds", :limit => 8
+ end
+
+ add_index "line", ["objectid"], :name => "line_objectid_key", :unique => true
+ add_index "line", ["registrationnumber"], :name => "line_registrationnumber_key", :unique => true
+ end
+
+ def down
+ end
+end
diff --git a/spec/factories/chouette_lines.rb b/spec/factories/chouette_lines.rb
index 913b88538..b43583330 100644
--- a/spec/factories/chouette_lines.rb
+++ b/spec/factories/chouette_lines.rb
@@ -1,4 +1,5 @@
-Factory.define :chouette_line, :class => "Chouette::Line" do |f|
- f.sequence(:name) { |n| "Line #{n}" }
- f.objectid
-end \ No newline at end of file
+Factory.define :line, :class => "Chouette::Line" do |line|
+ line.sequence(:name) { |n| "Line #{n}" }
+ line.association :network, :factory => :network
+ line.association :company, :factory => :company
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index e66d9802c..41ce1fde6 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -29,4 +29,5 @@ RSpec.configure do |config|
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
+
end
diff --git a/spec/views/lines/edit.html.erb_spec.rb b/spec/views/lines/edit.html.erb_spec.rb
index f889410ee..98216eb52 100644
--- a/spec/views/lines/edit.html.erb_spec.rb
+++ b/spec/views/lines/edit.html.erb_spec.rb
@@ -1,15 +1,17 @@
require 'spec_helper'
describe "/lines/edit" do
- let!(:network) { assign(:network, Factory(:network)) }
- let!(:line) { assign(:line, Factory(:line, :network => network)) }
- let!(:lines) { Array.new(2) { Factory(:line, :network => network) } }
+ let!(:referential) { assign(:referential, Factory(:referential)) }
+ let!(:network) { Factory(:network) }
+ let!(:company) { Factory(:company) }
+ let!(:line) { assign(:line, Factory(:line, :network => network, :company => company)) }
+ let!(:lines) { Array.new(2) { Factory(:line, :network => network, :company => company) } }
describe "test" do
- it "should render h2 with the group name" do
- render
- rendered.should have_selector("h2", :text => Regexp.new(line.name))
- end
+ it "should render h2 with the group name" do
+ render
+ rendered.should have_selector("h2", :text => Regexp.new(line.name))
+ end
end
describe "form" do
diff --git a/spec/views/lines/index.html.erb_spec.rb b/spec/views/lines/index.html.erb_spec.rb
index dee3565f4..a290080eb 100644
--- a/spec/views/lines/index.html.erb_spec.rb
+++ b/spec/views/lines/index.html.erb_spec.rb
@@ -2,24 +2,26 @@ require 'spec_helper'
describe "/lines/index" do
- let!(:network) { assign( :network, Factory(:network) ) }
- let!(:lines) { assign( :lines, Array.new(2) { Factory(:line, :network => network) } ) }
+ 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) } ) }
before :each do
- rendered.stub(:collection).and_return( lines.order_by [[:code, :asc]] )
+ rendered.stub(:collection).and_return( lines.order_by [[:number, :asc]] )
view.stub(:link_to_order).and_return( "#" )
end
it "should render a show link for each group" do
render
lines.each do |line|
- rendered.should have_selector(".line a[href='#{view.line_path(line)}']", :text => line.name)
+ rendered.should have_selector(".line a[href='#{view.referential_line_path(referential, line)}']", :text => line.name)
end
end
it "should render a link to create a new group" do
render
- view.content_for(:sidebar).should have_selector(".actions a[href='#{new_network_line_path(network)}']")
+ view.content_for(:sidebar).should have_selector(".actions a[href='#{new_referential_line_path(referential)}']")
end
end
diff --git a/spec/views/lines/new.html.erb_spec.rb b/spec/views/lines/new.html.erb_spec.rb
index b50f73356..48f36a036 100644
--- a/spec/views/lines/new.html.erb_spec.rb
+++ b/spec/views/lines/new.html.erb_spec.rb
@@ -1,8 +1,10 @@
require 'spec_helper'
describe "/lines/new" do
- let!(:network) { assign(:network, Factory(:network)) }
- let!(:line) { assign(:line, Factory.build(:line, :network => network)) }
+ let!(:referential) { assign(:referential, Factory(:referential)) }
+ let!(:network) { Factory(:network) }
+ let!(:company) { Factory(:company) }
+ let!(:line) { assign(:line, Factory.build(:line, :network => network, :company => company )) }
describe "form" do
diff --git a/spec/views/lines/show.html.erb_spec.rb b/spec/views/lines/show.html.erb_spec.rb
index 14f315333..9d5b53cd3 100644
--- a/spec/views/lines/show.html.erb_spec.rb
+++ b/spec/views/lines/show.html.erb_spec.rb
@@ -2,28 +2,27 @@ require 'spec_helper'
describe "/lines/show" do
- let!(:network) { assign(:network, Factory(:network)) }
- let!(:line) { assign(:line, Factory(:line, :network => network)) }
- let!(:map) { assign(:map, LineMap.new(line) ) }
+ let!(:referential) { assign(:referential, Factory(:referential)) }
+ let!(:line) { assign(:line, Factory(:line)) }
it "should render h2 with the line name" do
render
rendered.should have_selector("h2", :text => Regexp.new(line.name))
end
- it "should display a map with class 'line'" do
- render
- rendered.should have_selector("#map", :class => 'line')
- end
+ # it "should display a map with class 'line'" do
+ # render
+ # rendered.should have_selector("#map", :class => 'line')
+ # end
it "should render a link to edit the line" do
render
- view.content_for(:sidebar).should have_selector(".actions a[href='#{view.edit_line_path(line)}']")
+ view.content_for(:sidebar).should have_selector(".actions a[href='#{view.edit_referential_line_path(referential, line)}']")
end
it "should render a link to remove the line" do
render
- view.content_for(:sidebar).should have_selector(".actions a[href='#{view.line_path(line)}'][class='remove']")
+ view.content_for(:sidebar).should have_selector(".actions a[href='#{view.referential_line_path(referential, line)}'][class='remove']")
end
end