check if username is available in registration form

This commit is contained in:
Julian Herrero
2016-01-10 19:17:20 +01:00
parent c8ad7a8fb2
commit 7bbfcd74e2
9 changed files with 106 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
require 'rails_helper'
describe Users::RegistrationsController do
describe "POST check_username" do
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
end
context "when username is available" do
it "should return true with no error message" do
post :check_username, username: "available username"
data = JSON.parse response.body, symbolize_names: true
expect(data[:available]).to be true
expect(data[:message]).to eq I18n.t("devise_views.users.registrations.new.username_is_available")
end
end
context "when username is not available" do
it "should return true with no error message" do
user = create(:user)
post :check_username, username: user.username
data = JSON.parse response.body, symbolize_names: true
expect(data[:available]).to be false
expect(data[:message]).to eq I18n.t("devise_views.users.registrations.new.username_is_not_available")
end
end
end
end