Skip to content

Instantly share code, notes, and snippets.

View BenEddy's full-sized avatar
💭
🍂

Ben Eddy BenEddy

💭
🍂
  • Seattle
View GitHub Profile
@BenEddy
BenEddy / angular-bootstrap-nav.html
Created February 18, 2016 01:06 — forked from fpv83/angular-bootstrap-nav.html
angular navbar directive for twitter bootstrap with the aid of bootstrap.ui
<!DOCTYPE html>
<html data-ng-app="webapp">
<head>
<title>angular nav</title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<style>
body{
padding-top: 70px;
}
Dir[File.dirname(__FILE__) + '/support/*.rb'].each {|file| require file }
describe UserSearch do
describe "#results" do
before { User.stub(scoped: MockActiveRelation.new) }
def results(options={})
described_class.new(options).results
end
it "does not scope results by default" do
expect(results).to_not be_scoped
class MockActiveRelation < Hash
def scoped?
any?
end
def name_matching(name)
new(name_scope: name)
end
def scoped_by_name?(name)
describe UserSearch do
describe "#results" do
let(:relation) { MockActiveRelation.new(:name_matching, :email_matching) }
def results(options = {})
described_class.new(options).results
end
before { User.stub(scoped: relation) }
class MockActiveRelation < Hash
attr_reader :mocked_scopes
def initialize(*mocked_scopes)
@mocked_scopes = mocked_scopes
super()
end
def scoped?
any?
describe UserSearch do
describe "#results" do
let(:user_scope) { double }
before do
User.stub(scoped: user_scope)
end
def results(options = {})
described_class.new(options).results
class UserSearch
attr_reader :name, :email
def initialize(options = {})
@name = options[:name]
@email = options[:email]
end
def results
scope = User.scoped
describe User do
describe ".name_matching" do
let!(:user) { User.create!(first_name: "Gaius", last_name: "Baltar") }
it "scopes to Users with matching first names" do
expect(User.name_matching("Gaius")).to eq([user])
end
it "scopes to Users with matching last names" do
expect(User.name_matching("Baltar")).to eq([user])
class User < ActiveRecord::Base
attr_accessible :email, :first_name, :last_name
def self.name_matching(name)
where("lower(first_name) LIKE lower(:name)
OR lower(last_name) LIKE lower(:name)", name: name + "%")
end
def self.email_matching(email)
where("lower(email) LIKE lower(?)", email + "%")