Skip to content

Instantly share code, notes, and snippets.

@jittuu
jittuu / gist:792715
Created January 24, 2011 02:19
Test Omniauth Facebook Callback Controllers in Devise with rspec
require 'spec_helper'
describe Users::OauthCallbacksController, "handle facebook authentication callback" do
describe "#annonymous user" do
context "when facebook email doesn't exist in the system" do
before(:each) do
stub_env_for_omniauth
get :facebook
[TestMethod]
public void ToSlugShouldReturnJustSlug()
{
var value = "^&*#$Slug testing ?? @3 with--- some-tokens!.";
var expected = "slug-testing-3-with-some-tokens";
var actual = value.ToSlug();
Assert.AreEqual(expected, actual);
}
public static string ToSlug(this string target)
{
var pattern = @"[^0-9a-zA-Z]+";
return Regex.Replace(target, pattern, "-")
.Trim('-')
.ToLowerInvariant();
}
if (user.PostedPostCount > 1000
&& user.LastActivityDate >= DateTime.Today.AddMonths(-3))
{
// do something
}
// Is it Gold Partner?
if (user.PostedPostCount > 1000 
&& user.LastActivityDate >= DateTime.Today.AddMonths(-3)) 
{
// do something
}
if (user.IsGoldPartner()) 
{
// do something
}
public class User
{
public int PostedPostCount { get; set; }
public DateTime LastActivityDate { get; set; }
public bool IsGoldPartner()
public static class DateTimeExtensions
{
public static bool IsAfter(this DateTime current, DateTime value)
{
return current > value;
}
public static bool IsBefore(this DateTime current, DateTime value)
{
return current < value;
[TestClass]
public class DateTimeExtensionTest
{
[TestMethod]
public void FiveMinAgoShouldBeBeforeCurrent()
{
var current = DateTime.Now;
var fiveMinAgo = current.AddMinutes(-5);
Assert.IsTrue(fiveMinAgo.IsBefore(current));
public class FormulaSample : ObservableBase
{
private decimal a;
public decimal A
{
get { return a; }
set
{
this.a = value;
RaisePropertyChanged("A");
public class Formula<T> : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = delegate { };
private readonly Func<T> formula;
private readonly INotifyPropertyChanged source;
public Formula(INotifyPropertyChanged source, Func<T> formula, params string[] dependencyProperties)
{
this.source = source;