require 'spec_helper'

describe Traxii::OnApp::ClassMethods do
  before(:each) do
    @klass = Class.new
    @klass.instance_eval { extend Traxii::OnApp::ClassMethods }
  end

  context ".resource_uri" do
    it "set value" do
      @klass.resource_uri '/test'
      expect(@klass.instance_variable_get('@resource_uri')).to be_eql('/test')
    end
  end

  context ".resource_name" do
    it "set value" do
      @klass.resource_name 'test'
      expect(@klass.instance_variable_get('@resource_name')).to be_eql('test')
    end
  end

  context ".make_uri" do
    before(:each) do
      @klass.resource_uri '/test'
    end

    it "add json has default format" do
      expect(@klass.make_uri(:index)).to be_eql('/test.json')
    end

    it "set any other format" do
      expect(@klass.make_uri(:index, nil, :xml)).to be_eql('/test.xml')
    end

    it "uri for index" do
      expect(@klass.make_uri(:index)).to be_eql('/test.json')
    end

    it "uri for show" do
      expect(@klass.make_uri(:show, { id: 1 })).to be_eql('/test/1.json')
    end

    it "uri for edit" do
      expect(@klass.make_uri(:edit, { id: 1 })).to be_eql('/test/1.json')
    end

    it "uri for delete" do
      expect(@klass.make_uri(:delete, { id: 1 } )).to be_eql('/test/1.json')
    end

    it "uri a member action" do
      expect(@klass.make_uri(:member, { id: 1, action: 'foo' })).to be_eql('/test/1/foo.json')
    end

    it "uri for a collection action" do
      expect(@klass.make_uri(:collection, { action: 'foo' })).to be_eql('/test/foo.json')
    end
  end
end
