91 lines
3.1 KiB
Ruby
91 lines
3.1 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe User do
|
|
|
|
before(:each) do
|
|
User.delete_search_index
|
|
User.create_search_index
|
|
|
|
@user = FactoryGirl.create(:user, first_name: "Example", last_name: "User", email: "user@example.com",
|
|
password: "foobar", password_confirmation: "foobar", musician: true, email_confirmed: true,
|
|
city: "Apex", state: "NC", country: "USA")
|
|
# you have to poke elasticsearch because it will batch requests internally for a second
|
|
User.search_index.refresh
|
|
end
|
|
|
|
it "should allow search of one user" do
|
|
ws = User.search("Example User")
|
|
ws.results.length.should == 1
|
|
user_result = ws.results[0]
|
|
user_result._type.should == "jam_ruby/user"
|
|
user_result.first_name.should == @user.first_name
|
|
user_result.last_name.should == @user.last_name
|
|
user_result.id.should == @user.id
|
|
user_result.location.should == @user.location
|
|
user_result.musician.should == true
|
|
end
|
|
|
|
it "should delete user" do
|
|
ws = User.search("Example User")
|
|
ws.results.length.should == 1
|
|
user_result = ws.results[0]
|
|
user_result.id.should == @user.id
|
|
|
|
@user.destroy # delete doesn't work; you have to use destroy.
|
|
User.search_index.refresh
|
|
|
|
ws = User.search("Example User")
|
|
ws.results.length.should == 0
|
|
end
|
|
|
|
it "should update user" do
|
|
ws = User.search("Example User")
|
|
ws.results.length.should == 1
|
|
user_result = ws.results[0]
|
|
user_result.id.should == @user.id
|
|
|
|
@user.first_name = "bonus-junk"
|
|
@user.last_name = "more-junk"
|
|
@user.save
|
|
User.search_index.refresh
|
|
|
|
ws = User.search("Example User")
|
|
ws.results.length.should == 1
|
|
|
|
ws = User.search("Bonus")
|
|
ws.results.length.should == 1
|
|
user_result = ws.results[0]
|
|
user_result.id.should == @user.id
|
|
user_result.first_name.should == "bonus-junk"
|
|
end
|
|
|
|
it "should tokenize correctly" do
|
|
@user2 = FactoryGirl.create(:user, first_name: "peaches", last_name: "test", email: "peach@example.com",
|
|
password: "foobar", password_confirmation: "foobar", musician: true, email_confirmed: true,
|
|
city: "Apex", state: "NC", country: "USA")
|
|
User.search_index.refresh
|
|
ws = User.search("pea")
|
|
ws.results.length.should == 1
|
|
user_result = ws.results[0]
|
|
user_result.id.should == @user2.id
|
|
end
|
|
|
|
it "users who have signed up, but not confirmed should not show up in search index" do
|
|
@user3 = FactoryGirl.create(:user, first_name: "unconfirmed", last_name: "unconfirmed", email: "unconfirmed@example.com",
|
|
password: "foobar", password_confirmation: "foobar", musician: true, email_confirmed: false,
|
|
city: "Apex", state: "NC", country: "USA")
|
|
User.search_index.refresh
|
|
ws = User.search("unconfirmed")
|
|
ws.results.length.should == 0
|
|
|
|
# Ok, confirm the user, and see them show up
|
|
@user3.email_confirmed = true
|
|
@user3.save
|
|
User.search_index.refresh
|
|
|
|
ws = User.search("unconfirmed")
|
|
ws.results.length.should == 1
|
|
user_result = ws.results[0]
|
|
user_result.id.should == @user3.id
|
|
end
|
|
end |