aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support
diff options
context:
space:
mode:
authorLuc Donnet2015-01-05 14:56:12 +0100
committerLuc Donnet2015-01-05 14:56:12 +0100
commit3bc6d313bebdc1f03e4021aabbc774a0cd97d938 (patch)
treeac5b8c6d8309012136606d9fd9b9a00290f486a8 /spec/support
parente632a4634b1762f4c73d11f1e5b127de9832a1ff (diff)
downloadchouette-core-3bc6d313bebdc1f03e4021aabbc774a0cd97d938.tar.bz2
Initialize rails 4 migration
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/api_key.rb2
-rw-r--r--spec/support/api_key_protected.rb12
-rw-r--r--spec/support/devise.rb5
-rw-r--r--spec/support/referential.rb24
-rw-r--r--spec/support/type_ids_modelable_spec.rb36
5 files changed, 47 insertions, 32 deletions
diff --git a/spec/support/api_key.rb b/spec/support/api_key.rb
index dc7111214..9353fac15 100644
--- a/spec/support/api_key.rb
+++ b/spec/support/api_key.rb
@@ -1,7 +1,7 @@
module ApiKeyHelper
def get_api_key
- Api::V1::ApiKey.find_or_create_by_referential_id_and_name( referential.id, "test")
+ Api::V1::ApiKey.first_or_create( :referential_id => referential.id, :name => "test")
end
def config_formatted_request_with_authorization( format)
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials( get_api_key.token)
diff --git a/spec/support/api_key_protected.rb b/spec/support/api_key_protected.rb
index 43256716d..c1ed3b5b5 100644
--- a/spec/support/api_key_protected.rb
+++ b/spec/support/api_key_protected.rb
@@ -12,7 +12,7 @@ shared_examples "api key protected controller" do
h[http_verb].call
end
it "should return HTTP 401" do
- response.response_code.should == 401
+ expect(response.response_code).to eq(401)
end
end
context "when no authorization is provided" do
@@ -21,7 +21,7 @@ shared_examples "api key protected controller" do
h[http_verb].call
end
it "should return HTTP 401" do
- response.response_code.should == 401
+ expect(response.response_code).to eq(401)
end
end
context "when authorization provided and request.accept is #{format}," do
@@ -31,17 +31,17 @@ shared_examples "api key protected controller" do
end
it "should assign expected api_key" do
- assigns[:api_key].should eql(api_key) if json_xml_format?
+ expect(assigns[:api_key]).to eql(api_key) if json_xml_format?
end
it "should assign expected referential" do
- assigns[:referential].should == api_key.referential if json_xml_format?
+ expect(assigns[:referential]).to eq(api_key.referential) if json_xml_format?
end
it "should return #{(format == "application/json" || format == "application/xml") ? "success" : "failure"} response" do
if json_xml_format?
- response.should be_success
+ expect(response).to be_success
else
- response.should_not be_success
+ expect(response).not_to be_success
end
end
end
diff --git a/spec/support/devise.rb b/spec/support/devise.rb
index 8713e96fa..cd5782f36 100644
--- a/spec/support/devise.rb
+++ b/spec/support/devise.rb
@@ -2,7 +2,7 @@ module DeviseRequestHelper
include Warden::Test::Helpers
def login_user
- organisation = Organisation.find_by_name("first") || create(:organisation, :name => "first")
+ organisation = Organisation.where(:name => "first").first_or_create(attributes_for(:organisation))
@user ||= create(:user, :organisation => organisation)
@user.confirm!
login_as @user, :scope => :user
@@ -34,7 +34,7 @@ module DeviseControllerHelper
def login_user
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
- organisation = Organisation.find_by_name("first") || create(:organisation, :name => "first")
+ organisation = Organisation.where(:name => "first").first_or_create(attributes_for(:organisation))
user = create(:user, :organisation => organisation)
user.confirm!
sign_in user
@@ -47,4 +47,5 @@ RSpec.configure do |config|
config.extend DeviseControllerHelper, :type => :controller
config.include DeviseRequestHelper, :type => :request
+ config.include DeviseRequestHelper, :type => :feature
end
diff --git a/spec/support/referential.rb b/spec/support/referential.rb
index 28f3799ec..d20b68ee6 100644
--- a/spec/support/referential.rb
+++ b/spec/support/referential.rb
@@ -27,15 +27,29 @@ RSpec.configure do |config|
config.include ReferentialHelper
config.before(:suite) do
- organisation = Organisation.find_or_create_by_name :name => "first"
- organisation.referentials.find_by_slug("first" ) ||
- Referential.create(:prefix => "first", :name => "first", :slug => "first", :organisation => organisation)
- # FIXME in Rails 3.2 :
- # Referential.where(:slug => 'first').first_or_create(FactoryGirl.attributes_for(:referential))
+ # Clean all tables to start
+ DatabaseCleaner.clean_with :truncation
+ # Use transactions for tests
+ DatabaseCleaner.strategy = :transaction
+ # Truncating doesn't drop schemas, ensure we're clean here, first *may not* exist
+ Apartment::Tenant.drop('first') rescue nil
+ # Create the default tenant for our tests
+ organisation = Organisation.where(:name => "first").first_or_create
+ Referential.where(:prefix => "first", :name => "first", :slug => "first", :organisation => organisation).first_or_create
end
config.before(:each) do
+ # Start transaction for this test
+ #DatabaseCleaner.start
+ # Switch into the default tenant
first_referential.switch
end
+ config.after(:each) do
+ # Reset tenant back to `public`
+ Apartment::Tenant.reset
+ # Rollback transaction
+ DatabaseCleaner.clean
+ end
+
end
diff --git a/spec/support/type_ids_modelable_spec.rb b/spec/support/type_ids_modelable_spec.rb
index d5a3f7042..8174fb130 100644
--- a/spec/support/type_ids_modelable_spec.rb
+++ b/spec/support/type_ids_modelable_spec.rb
@@ -3,11 +3,11 @@ require 'spec_helper'
shared_examples_for TypeIdsModelable do
context 'class methods' do
it 'should be a TypeIdsModelable class' do
- described_class.type_ids_modelable_class?.should be_true
+ expect(described_class.type_ids_modelable_class?).to be_truthy
end
describe ".references_relation" do
it "shoud demodulize, underscore and puralize" do
- described_class.references_relation( Chouette::StopArea).should == "stop_areas"
+ expect(described_class.references_relation( Chouette::StopArea)).to eq("stop_areas")
end
end
end
@@ -16,11 +16,11 @@ shared_examples_for TypeIdsModelable do
describe "#references" do
it "should be empty if references_type is nil" do
type_ids_model.references_type = nil
- type_ids_model.references.should be_empty
+ expect(type_ids_model.references).to be_empty
end
it "should be empty if reference_ids is blank" do
type_ids_model.reference_ids = ""
- type_ids_model.references.should be_empty
+ expect(type_ids_model.references).to be_empty
end
end
describe "#references=" do
@@ -31,10 +31,10 @@ shared_examples_for TypeIdsModelable do
type_ids_model.references = lines
end
it "should set reference_ids to [data_a.id]" do
- type_ids_model.reference_ids.should == lines.map(&:id)
+ expect(type_ids_model.reference_ids).to eq(lines.map(&:id))
end
it "should set references_type to EffectiveDataTypeA" do
- type_ids_model.references_type.should == 'Chouette::Line'
+ expect(type_ids_model.references_type).to eq('Chouette::Line')
end
end
context "when references blank" do
@@ -42,10 +42,10 @@ shared_examples_for TypeIdsModelable do
type_ids_model.references = ""
end
it "should set reference_ids to []" do
- type_ids_model.reference_ids.should == []
+ expect(type_ids_model.reference_ids).to eq([])
end
it "should set references_type to nil" do
- type_ids_model.references_type.should be_nil
+ expect(type_ids_model.references_type).to be_nil
end
end
end
@@ -53,45 +53,45 @@ shared_examples_for TypeIdsModelable do
describe "#references_relation" do
it "should be 'lines' when relation_type is 'Chouette::Line'" do
type_ids_model.references_type = "Chouette::Line"
- type_ids_model.references_relation.should == "lines"
+ expect(type_ids_model.references_relation).to eq("lines")
end
it "should be 'networks' when relation_type is 'Chouette::Network'" do
type_ids_model.references_type = "Chouette::Network"
- type_ids_model.references_relation.should == "networks"
+ expect(type_ids_model.references_relation).to eq("networks")
end
it "should be nil when relation_type is blank" do
type_ids_model.references_type = ""
- type_ids_model.references_relation.should be_nil
+ expect(type_ids_model.references_relation).to be_nil
end
it "should be nil when relation_type is 'dummy'" do
type_ids_model.references_type = "dummy"
- type_ids_model.references_relation.should be_nil
+ expect(type_ids_model.references_relation).to be_nil
end
end
describe "#reference_ids" do
it "should parse raw_reference_ids and returns ids" do
- type_ids_model.stub :raw_reference_ids => "1,2,3"
- type_ids_model.reference_ids.should == [1,2,3]
+ allow(type_ids_model).to receive_messages :raw_reference_ids => "1,2,3"
+ expect(type_ids_model.reference_ids).to eq([1,2,3])
end
it "should be empty if raw_reference_ids is blank" do
- type_ids_model.stub :raw_reference_ids => ""
- type_ids_model.reference_ids.should be_empty
+ allow(type_ids_model).to receive_messages :raw_reference_ids => ""
+ expect(type_ids_model.reference_ids).to be_empty
end
end
describe "#reference_ids=" do
it "should join ids with comma" do
type_ids_model.reference_ids = [1,2,3]
- type_ids_model.raw_reference_ids.should == "1,2,3"
+ expect(type_ids_model.raw_reference_ids).to eq("1,2,3")
end
it "should be nil if records is blank" do
type_ids_model.reference_ids = []
- type_ids_model.raw_reference_ids.should be_nil
+ expect(type_ids_model.raw_reference_ids).to be_nil
end
end
end