Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split Detail Remote Model #26

Merged
merged 13 commits into from Apr 10, 2017
5 changes: 5 additions & 0 deletions app/controllers/tt/api/v1/split_details_controller.rb
@@ -0,0 +1,5 @@
class Tt::Api::V1::SplitDetailsController < Tt::Api::V1::ApplicationController
def show
@split_detail = TestTrack::FakeServer.split_details(params[:id])
end
end
25 changes: 25 additions & 0 deletions app/models/test_track/fake/split_detail.rb
@@ -0,0 +1,25 @@
class TestTrack::Fake::SplitDetail
attr_reader :name

def initialize(name)
@name = name
end

def details
@details ||= _details
end

private

def _details
{
name: name,
hypothesis: "user will interact more with blue banner",
location: "home screen",
platform: "mobile",
owner: "mobile team",
assignment_criteria: "user has mobile app",
description: "banner test to see if users will interact more"
}
end
end
4 changes: 4 additions & 0 deletions app/models/test_track/fake_server.rb
Expand Up @@ -4,6 +4,10 @@ def split_registry
TestTrack::Fake::SplitRegistry.instance.splits
end

def split_details(name)
TestTrack::Fake::SplitDetail.new(name).details
end

def visitor
TestTrack::Fake::Visitor.instance
end
Expand Down
28 changes: 28 additions & 0 deletions app/models/test_track/remote/split_detail.rb
@@ -0,0 +1,28 @@
class TestTrack::Remote::SplitDetail
include TestTrack::RemoteModel

collection_path '/api/v1/split_details'

attributes :name, :hypothesis, :assignment_criteria, :description, :owner, :location, :platform

def self.from_name(name)
# TODO: FakeableHer needs to make this faking a feature of `get`
if faked?
new(fake_instance_attributes(name))
else
get("/api/v1/split_details/#{name}")
end
end

def self.fake_instance_attributes(name)
{
name: name,
hypothesis: "fake hypothesis",
assignment_criteria: "fake criteria for everyone",
description: "fake but still good description",
owner: "fake owner",
location: "fake activity",
platform: "mobile"
}
end
end
1 change: 1 addition & 0 deletions app/views/tt/api/v1/split_details/show.json.jbuilder
@@ -0,0 +1 @@
json.(@split_detail, :name, :hypothesis, :assignment_criteria, :description, :owner, :location, :platform)
2 changes: 2 additions & 0 deletions config/routes.rb
Expand Up @@ -11,6 +11,8 @@

resources :visitors, only: :show

resource :split_detail, only: :show

resources :identifier_types, only: [], param: :name do
resources :identifiers, only: [], param: :value do
resource :visitor, only: :show, controller: 'identifier_visitors'
Expand Down
23 changes: 23 additions & 0 deletions spec/controllers/tt/api/v1/split_details_controller_spec.rb
@@ -0,0 +1,23 @@
require 'rails_helper'

RSpec.describe Tt::Api::V1::SplitDetailsController do
let(:response_json) { JSON.parse(response.body, symbolize_names: true) }

describe '#show' do
it 'returns fake split details' do
get :show, id: "great_split", format: :json

expected_response = {
name: "great_split",
hypothesis: "user will interact more with blue banner",
location: "home screen",
platform: "mobile",
owner: "mobile team",
assignment_criteria: "user has mobile app",
description: "banner test to see if users will interact more"
}

expect(response_json).to eq expected_response
end
end
end
18 changes: 18 additions & 0 deletions spec/models/test_track/fake/split_detail_spec.rb
@@ -0,0 +1,18 @@
require 'rails_helper'

RSpec.describe TestTrack::Fake::SplitDetail do
subject { Class.new(described_class).new("great_split").details }

context 'when splits exist' do
describe '#details' do
it 'returns a hash of split details for a split' do
expect(subject[:name]).to eq "great_split"
expect(subject[:owner]).to eq "mobile team"
expect(subject[:platform]).to eq "mobile"
expect(subject[:location]).to eq "home screen"
expect(subject[:assignment_criteria]).to eq "user has mobile app"
expect(subject[:hypothesis]).to eq "user will interact more with blue banner"
end
end
end
end
59 changes: 59 additions & 0 deletions spec/models/test_track/remote/split_detail_spec.rb
@@ -0,0 +1,59 @@
require 'rails_helper'

RSpec.describe TestTrack::Remote::SplitDetail do
before do
stub_request(:get, url)
.with(basic_auth: %w(dummy fakepassword))
.to_return(status: 200, body: {
name: "fake_split_name_from_server",
hypothesis: "hypothesis from a real server",
assignment_criteria: "criteria about real not fake users",
description: "description about a very real test",
owner: "best owner ever",
location: "the homepage above the fold",
platform: "mobile"
}.to_json)
end

describe ".find" do
let(:url) { "http://testtrack.dev/api/v1/split_details/fake_split_name_from_server" }
subject { described_class.find("fake_split_name_from_server") }

it "loads split details with fake instance attributes" do
expect(subject.name).to eq("fake_split_name_from_server")
expect(subject.hypothesis).to eq("fake hypothesis")
expect(subject.assignment_criteria).to eq("fake criteria for everyone")
expect(subject.description).to eq("fake but still good description")
expect(subject.owner).to eq("fake owner")
expect(subject.location).to eq("fake activity")
expect(subject.platform).to eq("mobile")
end

it "fetches attributes from the test track server when enabled" do
with_test_track_enabled do
expect(subject.name).to eq("fake_split_name_from_server")
expect(subject.hypothesis).to eq("hypothesis from a real server")
expect(subject.assignment_criteria).to eq("criteria about real not fake users")
expect(subject.description).to eq("description about a very real test")
expect(subject.owner).to eq("best owner ever")
expect(subject.location).to eq("the homepage above the fold")
expect(subject.platform).to eq("mobile")
end
end
end

describe ".from_name" do
subject { described_class.from_name("clown_id") }
let(:url) { "http://testtrack.dev/api/v1/split_details/clown_id" }

it "loads split details with instance attributes" do
expect(subject.name).to eq("clown_id")
end

it "fetches attributes from the test track server when enabled" do
with_test_track_enabled do
expect(subject.name).to eq("fake_split_name_from_server")
end
end
end
end