aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorMarc Florisson2012-12-13 16:03:53 +0100
committerMarc Florisson2012-12-13 16:03:53 +0100
commit3a4ee94cd91de749521ac190656c65266861270f (patch)
tree33cbf422cd46bc5c7095d9a466f940f62f83e90b /spec
parent845a400042115db5c3f7c1b77a685c5ece177d83 (diff)
downloadchouette-core-3a4ee94cd91de749521ac190656c65266861270f.tar.bz2
make api_key persistent
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/v1/lines_controller_spec.rb1
-rw-r--r--spec/controllers/api/v1/networks_controller_spec.rb1
-rw-r--r--spec/models/api/v1/api_key_spec.rb13
-rw-r--r--spec/support/api_key.rb2
-rw-r--r--spec/support/api_key_protected.rb7
5 files changed, 21 insertions, 3 deletions
diff --git a/spec/controllers/api/v1/lines_controller_spec.rb b/spec/controllers/api/v1/lines_controller_spec.rb
index 5bd8cac57..2bf7515b9 100644
--- a/spec/controllers/api/v1/lines_controller_spec.rb
+++ b/spec/controllers/api/v1/lines_controller_spec.rb
@@ -5,6 +5,7 @@ describe Api::V1::LinesController do
it_behaves_like "api key protected controller" do
let(:data){line}
+ let(:provided_referential){referential}
end
describe "GET #index" do
it "test" do
diff --git a/spec/controllers/api/v1/networks_controller_spec.rb b/spec/controllers/api/v1/networks_controller_spec.rb
index 01e3ee35d..f3db35369 100644
--- a/spec/controllers/api/v1/networks_controller_spec.rb
+++ b/spec/controllers/api/v1/networks_controller_spec.rb
@@ -5,6 +5,7 @@ describe Api::V1::NetworksController do
it_behaves_like "api key protected controller" do
let(:data){network}
+ let(:referential){referential}
end
describe "GET #show" do
diff --git a/spec/models/api/v1/api_key_spec.rb b/spec/models/api/v1/api_key_spec.rb
new file mode 100644
index 000000000..02c68ea13
--- /dev/null
+++ b/spec/models/api/v1/api_key_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+describe Api::V1::ApiKey do
+ let!(:referential){Factory(:referential)}
+ subject { Api::V1::ApiKey.create( :name => "test", :referential => referential)}
+
+ it "test" do
+ subject.should be_valid
+ subject.referential.should == referential
+
+ end
+end
+
diff --git a/spec/support/api_key.rb b/spec/support/api_key.rb
index 8c025bbad..dc7111214 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.create( referential.organisation, referential)
+ Api::V1::ApiKey.find_or_create_by_referential_id_and_name( referential.id, "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..9f3544afb 100644
--- a/spec/support/api_key_protected.rb
+++ b/spec/support/api_key_protected.rb
@@ -1,13 +1,14 @@
shared_examples "api key protected controller" do
- let(:h) { { :index => (Proc.new { get :index }),
- :show => (Proc.new { get :show, :id => data.objectid })}}
+ let(:h) { { :index => (Proc.new { get :index, :referential_id => provided_referential.id }),
+ :show => (Proc.new { get :show, :referential_id => provided_referential.id, :id => data.objectid })}}
[:index, :show].each do |http_verb|
describe "GET ##{http_verb}" do
["application/json","application/xml","application/html"].each do |format|
context "when an invalid authorization is provided" do
before :each do
+ puts "when an invalid authorization is provided"
config_formatted_request_with_dummy_authorization( format)
h[http_verb].call
end
@@ -17,6 +18,7 @@ shared_examples "api key protected controller" do
end
context "when no authorization is provided" do
before :each do
+ puts "when no authorization is provided"
config_formatted_request_without_authorization( format)
h[http_verb].call
end
@@ -26,6 +28,7 @@ shared_examples "api key protected controller" do
end
context "when authorization provided and request.accept is #{format}," do
before :each do
+ puts "when authorization provided and request.accept is #{format},"
config_formatted_request_with_authorization( format)
h[http_verb].call
end