Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Fix spec for policy
Browse files Browse the repository at this point in the history
  • Loading branch information
brunto committed Jan 24, 2017
1 parent fd58caf commit 620a55f
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 7 deletions.
2 changes: 2 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@
config.demo_data = "tmp/demo.zip"

config.i18n.available_locales = [:fr, :en]

config.active_record.raise_in_transactional_callbacks = true
end
1 change: 1 addition & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@

config.i18n.available_locales = [:fr, :en]

config.active_record.raise_in_transactional_callbacks = true
end
4 changes: 3 additions & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
config.eager_load = false

# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_assets = true
config.serve_static_files = true
config.static_cache_control = 'public, max-age=3600'

# Show full error reports and disable caching.
Expand All @@ -40,6 +40,8 @@
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

config.active_record.raise_in_transactional_callbacks = true

# Specific theme for each company
# AFIMB
config.company_name = "afimb"
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

# Add additional requires below this line. Rails is not loaded until this point!
# Add this to load Capybara integration:
include Warden::Test::Helpers
include Pundit
require 'capybara/rspec'
require 'capybara/rails'
require 'capybara/poltergeist'
Expand Down Expand Up @@ -72,5 +74,4 @@
# 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
13 changes: 11 additions & 2 deletions spec/support/referential.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ def first_referential
Referential.where(:slug => "ch_1").take!
end

def first_user
User.first
end

def self.included(base)
base.class_eval do
extend ClassMethods
alias_method :referential, :first_referential
alias_method :user, :first_user
end
end

Expand All @@ -23,8 +28,12 @@ def assign_organisation
assign :organisation, referential.organisation
end
end


def assign_user
before(:each) do
user = FactoryGirl.create(:user)
assign :user, user
end
end
end

end
Expand Down
6 changes: 6 additions & 0 deletions spec/views/companies/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

describe "/companies/index", :type => :view do

assign_user
assign_referential
let!(:companies) { assign :companies, Kaminari.paginate_array(Array.new(2) { create(:company) }).page(1) }
let!(:search) { assign :q, Ransack::Search.new(Chouette::Company) }

before :each do
allow(@request.env['warden']).to receive(:authenticate!).and_return(user)
allow(controller).to receive(:current_user).and_return(user)
end

it "should render a show link for each group" do
render
companies.each do |company|
Expand Down
6 changes: 6 additions & 0 deletions spec/views/connection_links/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

describe "/connection_links/index", :type => :view do

assign_user
assign_referential
let!(:connection_links) { assign :connection_links, Kaminari.paginate_array(Array.new(2) { create(:connection_link) }).page(1) }
let!(:search) { assign :q, Ransack::Search.new(Chouette::ConnectionLink) }

before :each do
allow(@request.env['warden']).to receive(:authenticate!).and_return(user)
allow(controller).to receive(:current_user).and_return(user)
end

it "should render a show link for each group" do
render
connection_links.each do |connection_link|
Expand Down
3 changes: 3 additions & 0 deletions spec/views/lines/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

describe "/lines/index", :type => :view do

assign_user
assign_referential
let!(:network) { create :network }
let!(:company) { create :company }
let!(:lines) { assign :lines, Kaminari.paginate_array(Array.new(2) { create(:line, :network => network, :company => company) }).page(1) }
let!(:q) { assign :q, Ransack::Search.new(Chouette::Line) }

before :each do
allow(@request.env['warden']).to receive(:authenticate!).and_return(user)
allow(controller).to receive(:current_user).and_return(user)
allow(view).to receive(:link_with_search).and_return("#")
end

Expand Down
6 changes: 6 additions & 0 deletions spec/views/lines/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

describe "/lines/show", :type => :view do

assign_user
assign_referential
let!(:line) { assign :line, create(:line) }
let!(:routes) { assign :routes, Kaminari.paginate_array(Array.new(2) { create(:route, :line => line) }) }
let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) }

before :each do
allow(@request.env['warden']).to receive(:authenticate!).and_return(user)
allow(controller).to receive(:current_user).and_return(user)
end

it "should render h2 with the line name" do
render
expect(rendered).to have_selector("h2", :text => Regexp.new(line.name))
Expand Down
6 changes: 6 additions & 0 deletions spec/views/networks/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

describe "/networks/index", :type => :view do

assign_user
assign_referential
let!(:networks) { assign :networks, Kaminari.paginate_array(Array.new(2){ create(:network) }).page(1) }
let!(:search) { assign :q, Ransack::Search.new(Chouette::Network) }

before :each do
allow(@request.env['warden']).to receive(:authenticate!).and_return(user)
allow(controller).to receive(:current_user).and_return(user)
end

it "should render a show link for each group" do
render
networks.each do |network|
Expand Down
10 changes: 8 additions & 2 deletions spec/views/rule_parameter_sets/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
require 'spec_helper'

describe "/organisations/show" do


assign_user
assign_organisation

let!(:organisation) { create(:organisation) }
let!(:rule_parameter_sets) { assign :rule_parameter_sets, [ create(:rule_parameter_set, :organisation => organisation),
create(:rule_parameter_set, :organisation => organisation)] }
create(:rule_parameter_set, :organisation => organisation)] }
before :each do
allow(@request.env['warden']).to receive(:authenticate!).and_return(user)
allow(controller).to receive(:current_user).and_return(user)
end

it "should render a show link for each rule_parameter_set" do
render
rule_parameter_sets.each do |rule_parameter_set|
Expand Down
3 changes: 3 additions & 0 deletions spec/views/stop_areas/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

describe "/stop_areas/index", :type => :view do

assign_user
assign_referential
let!(:stop_areas) { assign :stop_areas, Kaminari.paginate_array(Array.new(2) { create(:stop_area) }).page(1) }
let!(:q) { assign :q, Ransack::Search.new(Chouette::StopArea) }

before :each do
allow(@request.env['warden']).to receive(:authenticate!).and_return(user)
allow(controller).to receive(:current_user).and_return(user)
allow(view).to receive(:link_with_search).and_return("#")
end

Expand Down
6 changes: 6 additions & 0 deletions spec/views/time_tables/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

describe "/time_tables/index", :type => :view do

assign_user
assign_referential
let!(:time_tables) { assign :time_tables, Kaminari.paginate_array(Array.new(2){ create(:time_table) }).page(1) }
let!(:search) { assign :q, Ransack::Search.new(Chouette::TimeTable) }

before :each do
allow(@request.env['warden']).to receive(:authenticate!).and_return(user)
allow(controller).to receive(:current_user).and_return(user)
end

it "should render a show link for each group" do
render
time_tables.each do |time_table|
Expand Down
8 changes: 7 additions & 1 deletion spec/views/time_tables/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
require 'spec_helper'

describe "/time_tables/show", :type => :view do


assign_user
assign_referential
let!(:time_table) { assign(:time_table, create(:time_table)) }
let!(:year) { assign(:year, Date.today.cwyear) }
let!(:time_table_combination) {assign(:time_table_combination, TimeTableCombination.new)}

before :each do
allow(@request.env['warden']).to receive(:authenticate!).and_return(user)
allow(controller).to receive(:current_user).and_return(user)
end

it "should render h2 with the time_table comment" do
render
expect(rendered).to have_selector("h2", :text => Regexp.new(time_table.comment))
Expand Down
6 changes: 6 additions & 0 deletions spec/views/timebands/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

describe "/timebands/index", :type => :view do

assign_user
assign_referential
let!(:timebands) { assign :timebands, Kaminari.paginate_array(Array.new(2){ create(:timeband) }).page(1) }

before :each do
allow(@request.env['warden']).to receive(:authenticate!).and_return(user)
allow(controller).to receive(:current_user).and_return(user)
end

it "should render a show link for each timeband" do
render
timebands.each do |timeband|
Expand Down

0 comments on commit 620a55f

Please sign in to comment.