summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/sessions_controller_spec.rb38
-rw-r--r--spec/support/database_cleaner.rb2
-rw-r--r--spec/support/factory_girl.rb2
3 files changed, 40 insertions, 2 deletions
diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb
new file mode 100644
index 0000000..be81527
--- /dev/null
+++ b/spec/controllers/sessions_controller_spec.rb
@@ -0,0 +1,38 @@
+require 'rails_helper'
+
+RSpec.describe SessionsController, type: :controller do
+ describe "GET #new" do
+ it "returns http success" do
+ get :new
+ expect(response).to have_http_status(:success)
+ end
+
+ it "loads a new user" do
+ get :new
+ expect(assigns(:user)).to be_new_record
+ end
+ end
+
+ describe "GET #create" do
+ context "when credentials are valid" do
+ let(:user) { create(:user) }
+
+ before { get :create, username: user.username, password: 'password' }
+
+ it "creates a new session for the user" do
+ expect(session[:x]).to eql(user.id)
+ end
+
+ it "redirects the user to the dashboard" do
+ expect(response).to redirect_to(agents_path)
+ end
+ end
+ end
+
+ describe "GET #destroy" do
+ it "returns http success" do
+ get :destroy
+ expect(response).to have_http_status(:success)
+ end
+ end
+end
diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb
index 5083a47..e0dbc9a 100644
--- a/spec/support/database_cleaner.rb
+++ b/spec/support/database_cleaner.rb
@@ -1,4 +1,4 @@
-Rspec.configure do |config|
+RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
diff --git a/spec/support/factory_girl.rb b/spec/support/factory_girl.rb
index 6fd137f..eec437f 100644
--- a/spec/support/factory_girl.rb
+++ b/spec/support/factory_girl.rb
@@ -1,3 +1,3 @@
-Rspec.configure do |config|
+RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end