Sha256: 650dc384a67d0020b6f918bd227be985f82139261054c04f11d25eacd3eec703

Contents?: true

Size: 1.98 KB

Versions: 3

Compression:

Stored size: 1.98 KB

Contents

require 'spec_helper'

describe Cabalist::Frontend do
  
  with_model :Cat do
    
    table do |t|
      t.string    :color
      t.boolean   :evil
      t.timestamp :autoclassified_at
    end

    model do
      extend Cabalist::ModelAdditions

      def self.test_cats
        result = []
        100.times { result << Cat::create(:color => 'white', :evil => false) }
        100.times { result << Cat::create(:color => 'black', :evil => true) }
        return result
      end
    
      acts_as_cabalist :class_variable => :evil,
                       :features       => [:color],
                       :collection     => :test_cats
    end

  end
  
  before(:each) do
    Cat::test_cats
    Cabalist::Configuration.instance.frontend_classes = [Cat]
  end
  
  it "should respond to GET at /" do
    get '/'
    last_response.should be_ok
    last_response.body.should match /Cats/
  end
  
  it "should list all records for Cat" do
    get "/cat/all/1"
    last_response.should be_ok
  end
  
  it "should list non-classified records for Cat" do
    get "/cat/none/1"
    last_response.should be_ok
  end
  
  it "should list manually classified records for Cat" do
    get "/cat/manual/1"
    last_response.should be_ok
  end
  
  it "should list automatically classified records for Cat" do
    get "/cat/auto/1"
    last_response.should be_ok
  end
  
  it "should set the value of class variable for a Cat with a given ID" do
    cat = Cat.first
    post "/cat/teach/#{cat.id}", { :classification => true, :classification_freeform => '' },
                                 { :referer => '/cat/all/1' }
    last_response.should be_redirect
  end
  
  it "should automatically classify the Cat with a given ID" do
    cat = Cat.first
    post "/cat/autoclassify/#{cat.id}", {}, { :referer => '/cat/manual/1' }
    last_response.should be_redirect
  end
  
  it "should retrain the Cat classification model" do
    post "/cat/retrain", {}, { :referer => '/cat/manual/1' }
    last_response.should be_redirect
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cabalist-0.0.4 spec/cabalist/frontend_spec.rb
cabalist-0.0.3 spec/cabalist/frontend_spec.rb
cabalist-0.0.2 spec/cabalist/frontend_spec.rb