diff options
| author | Edouard Maffert | 2016-05-12 17:14:18 +0200 | 
|---|---|---|
| committer | Edouard Maffert | 2016-05-12 17:14:18 +0200 | 
| commit | 020cf3b06409acae569c23636ee91085fbeb5699 (patch) | |
| tree | a93afd432db99174c8f10c33edb22226cca2c084 | |
| parent | 972bbcb308d360c5468cd629dc5cdf356d556a2e (diff) | |
| download | chouette-core-020cf3b06409acae569c23636ee91085fbeb5699.tar.bz2 | |
add offer workbench model #827
| -rw-r--r-- | app/assets/javascripts/offer_workbenches.js.coffee | 3 | ||||
| -rw-r--r-- | app/assets/stylesheets/main/offer_workbenches.scss | 3 | ||||
| -rw-r--r-- | app/controllers/offer_workbenches_controller.rb | 12 | ||||
| -rw-r--r-- | app/helpers/offer_workbenches_helper.rb | 2 | ||||
| -rw-r--r-- | app/models/offer_workbench.rb | 7 | ||||
| -rw-r--r-- | app/models/organisation.rb | 2 | ||||
| -rw-r--r-- | app/views/offer_workbenches/show.html.erb | 1 | ||||
| -rw-r--r-- | app/views/referentials/index.html.erb | 6 | ||||
| -rw-r--r-- | config/routes.rb | 2 | ||||
| -rw-r--r-- | db/migrate/20160512105643_create_offer_workbenches.rb | 10 | ||||
| -rw-r--r-- | db/schema.rb | 80 | ||||
| -rw-r--r-- | spec/controllers/offer_workbenches_controller_spec.rb | 13 | ||||
| -rw-r--r-- | spec/factories/offer_workbenches.rb | 7 | ||||
| -rw-r--r-- | spec/helpers/offer_workbenches_helper_spec.rb | 15 | ||||
| -rw-r--r-- | spec/models/offer_workbench_spec.rb | 13 | ||||
| -rw-r--r-- | spec/models/organisation_spec.rb | 8 | ||||
| -rw-r--r-- | spec/rails_helper.rb | 50 | ||||
| -rw-r--r-- | spec/views/offer_workbenches/show.html.erb_spec.rb | 5 | 
18 files changed, 211 insertions, 28 deletions
| diff --git a/app/assets/javascripts/offer_workbenches.js.coffee b/app/assets/javascripts/offer_workbenches.js.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/app/assets/javascripts/offer_workbenches.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://coffeescript.org/ diff --git a/app/assets/stylesheets/main/offer_workbenches.scss b/app/assets/stylesheets/main/offer_workbenches.scss new file mode 100644 index 000000000..2859c635d --- /dev/null +++ b/app/assets/stylesheets/main/offer_workbenches.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the offer_workbenches controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/offer_workbenches_controller.rb b/app/controllers/offer_workbenches_controller.rb new file mode 100644 index 000000000..b9663184b --- /dev/null +++ b/app/controllers/offer_workbenches_controller.rb @@ -0,0 +1,12 @@ +class OfferWorkbenchesController < BreadcrumbController + +  defaults :resource_class => OfferWorkbench +  respond_to :html, :only => [:show] + +  def show +    show! do +      build_breadcrumb :show +    end +  end + +end diff --git a/app/helpers/offer_workbenches_helper.rb b/app/helpers/offer_workbenches_helper.rb new file mode 100644 index 000000000..1590ec132 --- /dev/null +++ b/app/helpers/offer_workbenches_helper.rb @@ -0,0 +1,2 @@ +module OfferWorkbenchesHelper +end diff --git a/app/models/offer_workbench.rb b/app/models/offer_workbench.rb new file mode 100644 index 000000000..2288d5bbb --- /dev/null +++ b/app/models/offer_workbench.rb @@ -0,0 +1,7 @@ +class OfferWorkbench < ActiveRecord::Base +  belongs_to :organisation + +  validates :name, presence: true, uniqueness: true +  validates :organisation, presence: true + +end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 4d098dbd3..9d6e92825 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -12,6 +12,8 @@ class Organisation < ActiveRecord::Base    has_many :line_referential_memberships    has_many :line_referentials, through: :line_referential_memberships +  has_many :offer_workbenches +    validates :name, :presence => true, :uniqueness => true    after_create :add_rule_parameter_set diff --git a/app/views/offer_workbenches/show.html.erb b/app/views/offer_workbenches/show.html.erb new file mode 100644 index 000000000..c7c2ea896 --- /dev/null +++ b/app/views/offer_workbenches/show.html.erb @@ -0,0 +1 @@ +<%= title_tag @offer_workbench.name %>
\ No newline at end of file diff --git a/app/views/referentials/index.html.erb b/app/views/referentials/index.html.erb index cb84f39cc..c3ea18898 100644 --- a/app/views/referentials/index.html.erb +++ b/app/views/referentials/index.html.erb @@ -1,3 +1,9 @@ +<!-- FIXME #827 --> +<ul> +  <% current_organisation.offer_workbenches.try(:each) do |offer| %> +    <li><h2><%= link_to offer.name, offer %></h2></li> +  <% end %> +</ul>  <!-- FIXME #823 -->  <% if false %> diff --git a/config/routes.rb b/config/routes.rb index 19cb60538..dfa9f4655 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,7 @@  ChouetteIhm::Application.routes.draw do +  resources :offer_workbenches, :only => [:show] +    devise_for :users, :controllers => {      :registrations => 'users/registrations', :invitations => 'users/invitations'    } diff --git a/db/migrate/20160512105643_create_offer_workbenches.rb b/db/migrate/20160512105643_create_offer_workbenches.rb new file mode 100644 index 000000000..cc2b82152 --- /dev/null +++ b/db/migrate/20160512105643_create_offer_workbenches.rb @@ -0,0 +1,10 @@ +class CreateOfferWorkbenches < ActiveRecord::Migration +  def change +    create_table :offer_workbenches do |t| +      t.string :name +      t.references :organisation, index: true + +      t.timestamps +    end +  end +end diff --git a/db/schema.rb b/db/schema.rb index 6b7441190..0f7a5d74b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@  #  # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160510125443) do +ActiveRecord::Schema.define(version: 20160512105643) do    # These are extensions that must be enabled in order to support this database    enable_extension "plpgsql" @@ -209,18 +209,6 @@ ActiveRecord::Schema.define(version: 20160510125443) do      t.integer "line_id",          limit: 8    end -  create_table "jobs", force: true do |t| -    t.string   "action" -    t.datetime "created" -    t.string   "filename" -    t.text     "parameters" -    t.string   "referential" -    t.datetime "started" -    t.string   "status" -    t.string   "type" -    t.datetime "updated" -  end -    create_table "journey_frequencies", force: true do |t|      t.integer  "vehicle_journey_id",         limit: 8      t.time     "scheduled_headway_interval",                           null: false @@ -249,7 +237,7 @@ ActiveRecord::Schema.define(version: 20160510125443) do    create_table "journey_patterns", force: true do |t|      t.integer  "route_id",                limit: 8 -    t.string   "objectid",                                       null: false +    t.string   "objectid",                                      null: false      t.integer  "object_version"      t.datetime "creation_time"      t.string   "creator_id" @@ -259,12 +247,10 @@ ActiveRecord::Schema.define(version: 20160510125443) do      t.string   "published_name"      t.integer  "departure_stop_point_id", limit: 8      t.integer  "arrival_stop_point_id",   limit: 8 -    t.integer  "route_section_ids",                 default: [],              array: true -    t.integer  "section_status",                    default: 0,  null: false +    t.integer  "section_status",                    default: 0, null: false    end    add_index "journey_patterns", ["objectid"], :name => "journey_patterns_objectid_key", :unique => true -  add_index "journey_patterns", ["route_section_ids"], :name => "index_journey_patterns_on_route_section_ids"    create_table "journey_patterns_stop_points", id: false, force: true do |t|      t.integer "journey_pattern_id", limit: 8 @@ -310,12 +296,6 @@ ActiveRecord::Schema.define(version: 20160510125443) do    add_index "lines", ["objectid"], :name => "lines_objectid_key", :unique => true    add_index "lines", ["registration_number"], :name => "lines_registration_number_key" -  create_table "links", id: false, force: true do |t| -    t.integer "job_id", limit: 8, null: false -    t.string  "rel" -    t.string  "type" -  end -    create_table "networks", force: true do |t|      t.string   "objectid",            null: false      t.integer  "object_version" @@ -334,6 +314,15 @@ ActiveRecord::Schema.define(version: 20160510125443) do    add_index "networks", ["objectid"], :name => "networks_objectid_key", :unique => true    add_index "networks", ["registration_number"], :name => "networks_registration_number_key" +  create_table "offer_workbenches", force: true do |t| +    t.string   "name" +    t.integer  "organisation_id" +    t.datetime "created_at" +    t.datetime "updated_at" +  end + +  add_index "offer_workbenches", ["organisation_id"], :name => "index_offer_workbenches_on_organisation_id" +    create_table "organisations", force: true do |t|      t.string   "name"      t.datetime "created_at" @@ -373,8 +362,8 @@ ActiveRecord::Schema.define(version: 20160510125443) do    end    create_table "route_sections", force: true do |t| -    t.integer  "departure_id" -    t.integer  "arrival_id" +    t.integer  "departure_id",       limit: 8 +    t.integer  "arrival_id",         limit: 8      t.string   "objectid",                                                       null: false      t.integer  "object_version"      t.datetime "creation_time" @@ -625,12 +614,51 @@ ActiveRecord::Schema.define(version: 20160510125443) do    add_index "vehicle_journeys", ["route_id"], :name => "index_vehicle_journeys_on_route_id"    Foreigner.load +  add_foreign_key "access_links", "access_points", name: "aclk_acpt_fkey", dependent: :delete + +  add_foreign_key "group_of_lines_lines", "group_of_lines", name: "groupofline_group_fkey", dependent: :delete +  add_foreign_key "group_of_lines_lines", "lines", name: "groupofline_line_fkey", dependent: :delete +    add_foreign_key "journey_frequencies", "timebands", name: "journey_frequencies_timeband_id_fk", dependent: :nullify    add_foreign_key "journey_frequencies", "vehicle_journeys", name: "journey_frequencies_vehicle_journey_id_fk", dependent: :nullify    add_foreign_key "journey_pattern_sections", "journey_patterns", name: "journey_pattern_sections_journey_pattern_id_fk", dependent: :delete    add_foreign_key "journey_pattern_sections", "route_sections", name: "journey_pattern_sections_route_section_id_fk", dependent: :delete -  add_foreign_key "links", "jobs", name: "fk_n5ypxycc1stckgkm6ust2l6on" +  add_foreign_key "journey_patterns", "routes", name: "jp_route_fkey", dependent: :delete +  add_foreign_key "journey_patterns", "stop_points", name: "arrival_point_fkey", column: "arrival_stop_point_id", dependent: :nullify +  add_foreign_key "journey_patterns", "stop_points", name: "departure_point_fkey", column: "departure_stop_point_id", dependent: :nullify + +  add_foreign_key "journey_patterns_stop_points", "journey_patterns", name: "jpsp_jp_fkey", dependent: :delete +  add_foreign_key "journey_patterns_stop_points", "stop_points", name: "jpsp_stoppoint_fkey", dependent: :delete + +  add_foreign_key "lines", "companies", name: "line_company_fkey", dependent: :nullify +  add_foreign_key "lines", "networks", name: "line_ptnetwork_fkey", dependent: :nullify + +  add_foreign_key "routes", "lines", name: "route_line_fkey", dependent: :delete +  add_foreign_key "routes", "routes", name: "route_opposite_route_fkey", column: "opposite_route_id", dependent: :nullify + +  add_foreign_key "routing_constraints_lines", "lines", name: "routingconstraint_line_fkey", dependent: :delete + +  add_foreign_key "stop_areas", "stop_areas", name: "area_parent_fkey", column: "parent_id", dependent: :nullify + +  add_foreign_key "stop_areas_stop_areas", "stop_areas", name: "stoparea_child_fkey", column: "child_id", dependent: :delete +  add_foreign_key "stop_areas_stop_areas", "stop_areas", name: "stoparea_parent_fkey", column: "parent_id", dependent: :delete + +  add_foreign_key "stop_points", "routes", name: "stoppoint_route_fkey", dependent: :delete + +  add_foreign_key "time_table_dates", "time_tables", name: "tm_date_fkey", dependent: :delete + +  add_foreign_key "time_table_periods", "time_tables", name: "tm_period_fkey", dependent: :delete + +  add_foreign_key "time_tables_vehicle_journeys", "time_tables", name: "vjtm_tm_fkey", dependent: :delete +  add_foreign_key "time_tables_vehicle_journeys", "vehicle_journeys", name: "vjtm_vj_fkey", dependent: :delete + +  add_foreign_key "vehicle_journey_at_stops", "stop_points", name: "vjas_sp_fkey", dependent: :delete +  add_foreign_key "vehicle_journey_at_stops", "vehicle_journeys", name: "vjas_vj_fkey", dependent: :delete + +  add_foreign_key "vehicle_journeys", "companies", name: "vj_company_fkey", dependent: :nullify +  add_foreign_key "vehicle_journeys", "journey_patterns", name: "vj_jp_fkey", dependent: :delete +  add_foreign_key "vehicle_journeys", "routes", name: "vj_route_fkey", dependent: :delete  end diff --git a/spec/controllers/offer_workbenches_controller_spec.rb b/spec/controllers/offer_workbenches_controller_spec.rb new file mode 100644 index 000000000..f815b8492 --- /dev/null +++ b/spec/controllers/offer_workbenches_controller_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +RSpec.describe OfferWorkbenchesController, :type => :controller do +  let(:offerworkbench) { create :offer_workbench } + +  describe "GET show" do +    it "returns http success" do +      get :show, id: offerworkbench.id +      expect(response).to have_http_status(302) +    end +  end + +end diff --git a/spec/factories/offer_workbenches.rb b/spec/factories/offer_workbenches.rb new file mode 100644 index 000000000..e9e5b2cd9 --- /dev/null +++ b/spec/factories/offer_workbenches.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do +  factory :offer_workbench do +    sequence(:name) { |n| "Offer workbench #{n}" } +     +    association :organisation, :factory => :organisation +  end +end diff --git a/spec/helpers/offer_workbenches_helper_spec.rb b/spec/helpers/offer_workbenches_helper_spec.rb new file mode 100644 index 000000000..d9fa86242 --- /dev/null +++ b/spec/helpers/offer_workbenches_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the OfferWorkbenchesHelper. For example: +# +# describe OfferWorkbenchesHelper do +#   describe "string concat" do +#     it "concats two strings with spaces" do +#       expect(helper.concat_strings("this","that")).to eq("this that") +#     end +#   end +# end +RSpec.describe OfferWorkbenchesHelper, :type => :helper do +  pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/offer_workbench_spec.rb b/spec/models/offer_workbench_spec.rb new file mode 100644 index 000000000..6b29d3d82 --- /dev/null +++ b/spec/models/offer_workbench_spec.rb @@ -0,0 +1,13 @@ +require 'rails_helper' + +RSpec.describe OfferWorkbench, :type => :model do + +  it 'should have a valid factory' do +    expect(FactoryGirl.build(:offer_workbench)).to be_valid +  end + +  it { should validate_presence_of(:name) } +  it { should validate_uniqueness_of(:name) } +  it { should validate_presence_of(:organisation) } + +end diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 66b1e8534..fb9d3629b 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -2,8 +2,12 @@ require 'spec_helper'  describe Organisation do -  #it { should validate_presence_of(:name) } -  #it { should validate_uniqueness_of(:name) } +  it { should validate_presence_of(:name) } +  it { should validate_uniqueness_of(:name) } + +  it 'should have a valid factory' do +    expect(FactoryGirl.build(:organisation)).to be_valid +  end    it "create a rule_parameter_set" do      organisation = create(:organisation) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 000000000..e6c0b688f --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,50 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV["RAILS_ENV"] ||= 'test' +require 'spec_helper' +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } + +# Checks for pending migrations before tests are run. +# If you are not using ActiveRecord, you can remove this line. +ActiveRecord::Migration.maintain_test_schema! + +RSpec.configure do |config| +  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures +  config.fixture_path = "#{::Rails.root}/spec/fixtures" + +  # If you're not using ActiveRecord, or you'd prefer not to run each of your +  # examples within a transaction, remove the following line or assign false +  # instead of true. +  config.use_transactional_fixtures = true + +  # RSpec Rails can automatically mix in different behaviours to your tests +  # based on their file location, for example enabling you to call `get` and +  # `post` in specs under `spec/controllers`. +  # +  # You can disable this behaviour by removing the line below, and instead +  # explicitly tag your specs with their type, e.g.: +  # +  #     RSpec.describe UsersController, :type => :controller do +  #       # ... +  #     end +  # +  # The different available types are documented in the features, such as in +  # https://relishapp.com/rspec/rspec-rails/docs +  config.infer_spec_type_from_file_location! +end diff --git a/spec/views/offer_workbenches/show.html.erb_spec.rb b/spec/views/offer_workbenches/show.html.erb_spec.rb new file mode 100644 index 000000000..884cf588c --- /dev/null +++ b/spec/views/offer_workbenches/show.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe "offer_workbenches/show.html.erb", :type => :view do +   +end | 
