question_chain 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +18 -0
- data/Licence.txt +20 -0
- data/README.rdoc +34 -0
- data/Rakefile +2 -0
- data/config/initializers/mustache.rb +2 -0
- data/lib/question_chain/answerable.rb +142 -0
- data/lib/question_chain/answers.rb +290 -0
- data/lib/question_chain/models/answers/question_view.rb +21 -0
- data/lib/question_chain/models/answers/ui_object_view.rb +67 -0
- data/lib/question_chain/models/answers/ui_objects_check_box_view.rb +17 -0
- data/lib/question_chain/models/answers/ui_objects_drop_down_view.rb +16 -0
- data/lib/question_chain/models/answers/ui_objects_hidden_field_view.rb +8 -0
- data/lib/question_chain/models/answers/ui_objects_object_reference_drop_down_view.rb +18 -0
- data/lib/question_chain/models/answers/ui_objects_object_search_view.rb +22 -0
- data/lib/question_chain/models/answers/ui_objects_relatable_category_drop_down_view.rb +18 -0
- data/lib/question_chain/models/answers/ui_objects_text_field_view.rb +8 -0
- data/lib/question_chain/models/chain_template.rb +43 -0
- data/lib/question_chain/models/question.rb +37 -0
- data/lib/question_chain/models/relatable_category_filter.rb +15 -0
- data/lib/question_chain/models/rule.rb +27 -0
- data/lib/question_chain/models/rules/attribute_change.rb +28 -0
- data/lib/question_chain/models/rules/choice_genenerator.rb +5 -0
- data/lib/question_chain/models/rules/populate_drop_down.rb +30 -0
- data/lib/question_chain/models/rules/search.rb +19 -0
- data/lib/question_chain/models/rules/value_change.rb +22 -0
- data/lib/question_chain/models/ui_group.rb +71 -0
- data/lib/question_chain/models/ui_object.rb +92 -0
- data/lib/question_chain/models/ui_object_answer.rb +17 -0
- data/lib/question_chain/models/ui_objects/check_box.rb +8 -0
- data/lib/question_chain/models/ui_objects/drop_down.rb +17 -0
- data/lib/question_chain/models/ui_objects/hidden_field.rb +5 -0
- data/lib/question_chain/models/ui_objects/object_reference_drop_down.rb +67 -0
- data/lib/question_chain/models/ui_objects/object_search.rb +44 -0
- data/lib/question_chain/models/ui_objects/radio_button.rb +5 -0
- data/lib/question_chain/models/ui_objects/radio_button_group.rb +5 -0
- data/lib/question_chain/models/ui_objects/relatable_category_drop_down.rb +70 -0
- data/lib/question_chain/models/ui_objects/text_field.rb +11 -0
- data/lib/question_chain/mongo_serialization.rb +62 -0
- data/lib/question_chain/mustache_handler.rb +16 -0
- data/lib/question_chain/mustache_rails.rb +50 -0
- data/lib/question_chain/state_machine.rb +29 -0
- data/lib/question_chain/stored_template.rb +30 -0
- data/lib/question_chain/version.rb +3 -0
- data/lib/question_chain/views/answers/_edit.html.haml +62 -0
- data/lib/question_chain/views/answers/_new.html.haml +62 -0
- data/lib/question_chain/views/answers/_question.html.mustache +11 -0
- data/lib/question_chain/views/answers/_ui_objects_check_box.html.mustache +19 -0
- data/lib/question_chain/views/answers/_ui_objects_drop_down.html.mustache +26 -0
- data/lib/question_chain/views/answers/_ui_objects_hidden_field.html.mustache +3 -0
- data/lib/question_chain/views/answers/_ui_objects_object_reference_drop_down.html.mustache +27 -0
- data/lib/question_chain/views/answers/_ui_objects_object_search.html.mustache +20 -0
- data/lib/question_chain/views/answers/_ui_objects_relatable_category_drop_down.html.mustache +26 -0
- data/lib/question_chain/views/answers/_ui_objects_text_field.html.mustache +19 -0
- data/lib/question_chain/views/layouts/application.html.haml +10 -0
- data/lib/question_chain.rb +35 -0
- data/question_chain.gemspec +31 -0
- data/test_app/.gitignore +4 -0
- data/test_app/Gemfile +29 -0
- data/test_app/Rakefile +16 -0
- data/test_app/app/controllers/answers_controller.rb +13 -0
- data/test_app/app/controllers/application_controller.rb +4 -0
- data/test_app/app/models/container.rb +10 -0
- data/test_app/app/models/flight.rb +20 -0
- data/test_app/app/views/answers/edit.html.haml +1 -0
- data/test_app/app/views/answers/new.html.haml +1 -0
- data/test_app/config/application.rb +18 -0
- data/test_app/config/boot.rb +13 -0
- data/test_app/config/database.yml +15 -0
- data/test_app/config/environment.rb +5 -0
- data/test_app/config/initializers/app.rb +5 -0
- data/test_app/config/initializers/cookie_verification_secret.rb +7 -0
- data/test_app/config/initializers/mongodb.rb +2 -0
- data/test_app/config/initializers/session_store.rb +3 -0
- data/test_app/config/routes.rb +30 -0
- data/test_app/config.ru +2 -0
- data/test_app/environments/development.rb +19 -0
- data/test_app/environments/test.rb +30 -0
- data/test_app/lib/tasks/rspec.rake +69 -0
- data/test_app/lib/tasks/yard.rake +4 -0
- data/test_app/public/.gitkeep +0 -0
- data/test_app/script/rails +10 -0
- data/test_app/spec/acceptance/new_spec +30 -0
- data/test_app/spec/factories.rb +81 -0
- data/test_app/spec/models/chain_template_spec.rb +53 -0
- data/test_app/spec/models/flight_spec.rb +101 -0
- data/test_app/spec/models/question_spec.rb +13 -0
- data/test_app/spec/models/rules/value_change_spec.rb +31 -0
- data/test_app/spec/models/ui_group_spec.rb +55 -0
- data/test_app/spec/models/ui_object_spec.rb +33 -0
- data/test_app/spec/models/ui_objects/drop_down_spec.rb +28 -0
- data/test_app/spec/models/ui_objects/relatable_category_drop_down_spec.rb +13 -0
- data/test_app/spec/spec_helper.rb +25 -0
- metadata +325 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class Flight
|
|
2
|
+
include MongoMapper::Document
|
|
3
|
+
include QuestionChain::Answerable
|
|
4
|
+
|
|
5
|
+
key :container_id, ObjectId
|
|
6
|
+
|
|
7
|
+
self._extra_keyword_methods = [:milk, :beans]
|
|
8
|
+
|
|
9
|
+
def object_reference_name
|
|
10
|
+
"flight"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def milk
|
|
14
|
+
"black rebel"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def beans
|
|
18
|
+
"motocycle"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
= render :partial => "edit"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
= render :partial => "new"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
|
2
|
+
|
|
3
|
+
require "active_support/railtie"
|
|
4
|
+
require "active_model/railtie"
|
|
5
|
+
require "action_controller/railtie"
|
|
6
|
+
require "action_view/railtie"
|
|
7
|
+
|
|
8
|
+
Bundler.require :default, Rails.env
|
|
9
|
+
|
|
10
|
+
module TestApp
|
|
11
|
+
class Application < Rails::Application
|
|
12
|
+
|
|
13
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
|
14
|
+
config.filter_parameters << :password
|
|
15
|
+
config.encoding = "utf-8"
|
|
16
|
+
config.cache_classes = true
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
|
|
3
|
+
# Set up gems listed in the Gemfile.
|
|
4
|
+
gemfile = File.expand_path('../../Gemfile', __FILE__)
|
|
5
|
+
begin
|
|
6
|
+
ENV['BUNDLE_GEMFILE'] = gemfile
|
|
7
|
+
require 'bundler'
|
|
8
|
+
Bundler.setup
|
|
9
|
+
rescue Bundler::GemNotFound => e
|
|
10
|
+
STDERR.puts e.message
|
|
11
|
+
STDERR.puts "Try running `bundle install`."
|
|
12
|
+
exit!
|
|
13
|
+
end if File.exist?(gemfile)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
development:
|
|
2
|
+
adapter: mongodb
|
|
3
|
+
database: carbon_calculated_test_app_development
|
|
4
|
+
host: localhost
|
|
5
|
+
username:
|
|
6
|
+
password:
|
|
7
|
+
port: 27017
|
|
8
|
+
|
|
9
|
+
test: &TEST
|
|
10
|
+
database: carbon_calculated_test_app_test
|
|
11
|
+
host: localhost
|
|
12
|
+
port: 27017
|
|
13
|
+
|
|
14
|
+
cucumber:
|
|
15
|
+
<<: *TEST
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
|
|
3
|
+
# Your secret key for verifying the integrity of signed cookies.
|
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
|
7
|
+
Rails.application.config.secret_token = '8a4af655c7d9d5ae1ea97f9bb91sdffb64c578ad16fbaaf88a5e26e7e9aa6f49a25de137f10ca99f74b3e891ede88c0818de9c47e4afaa2a3d8f0073'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
TestApp::Application.routes.draw do
|
|
2
|
+
|
|
3
|
+
match '/answers/fire_object_search' => 'answers#fire_object_search'
|
|
4
|
+
match '/answers/fire_populate_drop_down' => 'answers#fire_populate_drop_down'
|
|
5
|
+
|
|
6
|
+
chain_template_routes = lambda do
|
|
7
|
+
scope "/:context(/:question_id)" do
|
|
8
|
+
resources :answers, :only => [:new, :create, :index] do
|
|
9
|
+
collection do
|
|
10
|
+
post :fire_populate_drop_down
|
|
11
|
+
post :fire_object_search
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
scope "/:context" do
|
|
16
|
+
resources :answers, :only => [:edit, :update, :show] do
|
|
17
|
+
collection do
|
|
18
|
+
post :fire_populate_drop_down
|
|
19
|
+
post :fire_object_search
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
resources :containers do
|
|
26
|
+
chain_template_routes.call
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
root :to => "home#index"
|
|
30
|
+
end
|
data/test_app/config.ru
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
TestApp::Application.configure do
|
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
|
3
|
+
|
|
4
|
+
# In the development environment your application's code is reloaded on
|
|
5
|
+
# every request. This slows down response time but is perfect for development
|
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
|
7
|
+
config.cache_classes = false
|
|
8
|
+
|
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
|
10
|
+
config.whiny_nils = true
|
|
11
|
+
|
|
12
|
+
# Show full error reports and disable caching
|
|
13
|
+
config.consider_all_requests_local = true
|
|
14
|
+
config.action_view.debug_rjs = true
|
|
15
|
+
config.action_controller.perform_caching = false
|
|
16
|
+
|
|
17
|
+
# Don't care if the mailer can't send
|
|
18
|
+
config.action_mailer.raise_delivery_errors = false
|
|
19
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
TestApp::Application.configure do
|
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
|
3
|
+
|
|
4
|
+
# The test environment is used exclusively to run your application's
|
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
|
8
|
+
config.cache_classes = true
|
|
9
|
+
|
|
10
|
+
# Log error messages when you accidentally call methods on nil.
|
|
11
|
+
config.whiny_nils = true
|
|
12
|
+
|
|
13
|
+
# Show full error reports and disable caching
|
|
14
|
+
config.consider_all_requests_local = true
|
|
15
|
+
config.action_controller.perform_caching = false
|
|
16
|
+
|
|
17
|
+
# Raise exceptions instead of rendering exception templates
|
|
18
|
+
config.action_dispatch.show_exceptions = false
|
|
19
|
+
|
|
20
|
+
# Disable request forgery protection in test environment
|
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
|
22
|
+
|
|
23
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
|
24
|
+
# The :test delivery method accumulates sent emails in the
|
|
25
|
+
# ActionMailer::Base.deliveries array.
|
|
26
|
+
config.action_mailer.delivery_method = :test
|
|
27
|
+
|
|
28
|
+
# Print deprecation notices to the stderr
|
|
29
|
+
config.active_support.deprecation to :stderr
|
|
30
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'rspec/core'
|
|
3
|
+
require 'rspec/core/rake_task'
|
|
4
|
+
rescue MissingSourceFile
|
|
5
|
+
module Rspec
|
|
6
|
+
module Core
|
|
7
|
+
class RakeTask
|
|
8
|
+
def initialize(name)
|
|
9
|
+
task name do
|
|
10
|
+
# if rspec-rails is a configured gem, this will output helpful material and exit ...
|
|
11
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
|
|
12
|
+
|
|
13
|
+
# ... otherwise, do this:
|
|
14
|
+
raise <<-MSG
|
|
15
|
+
|
|
16
|
+
#{"*" * 80}
|
|
17
|
+
* You are trying to run an rspec rake task defined in
|
|
18
|
+
* #{__FILE__},
|
|
19
|
+
* but rspec can not be found in vendor/gems, vendor/plugins or system gems.
|
|
20
|
+
#{"*" * 80}
|
|
21
|
+
MSG
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
Rake.application.instance_variable_get('@tasks').delete('default')
|
|
30
|
+
|
|
31
|
+
spec_prereq = File.exist?(File.join(Rails.root, 'config', 'database.yml')) ? :noop : :noop
|
|
32
|
+
task :noop do
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
task :default => :spec
|
|
36
|
+
task :stats => "spec:statsetup"
|
|
37
|
+
|
|
38
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
|
39
|
+
Rspec::Core::RakeTask.new(:spec => spec_prereq)
|
|
40
|
+
|
|
41
|
+
namespace :spec do
|
|
42
|
+
[:requests, :models, :controllers, :views, :helpers, :mailers, :lib].each do |sub|
|
|
43
|
+
desc "Run the code examples in spec/#{sub}"
|
|
44
|
+
Rspec::Core::RakeTask.new(sub => spec_prereq) do |t|
|
|
45
|
+
t.pattern = "./spec/#{sub}/**/*_spec.rb"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
task :statsetup do
|
|
50
|
+
require 'rails/code_statistics'
|
|
51
|
+
::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
|
|
52
|
+
::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
|
|
53
|
+
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
|
|
54
|
+
::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
|
|
55
|
+
::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
|
|
56
|
+
::STATS_DIRECTORIES << %w(Mailer\ specs spec/mailers) if File.exist?('spec/mailers')
|
|
57
|
+
::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
|
|
58
|
+
::STATS_DIRECTORIES << %w(Request\ specs spec/requests) if File.exist?('spec/requests')
|
|
59
|
+
::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
|
|
60
|
+
::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
|
|
61
|
+
::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
|
|
62
|
+
::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
|
|
63
|
+
::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
|
|
64
|
+
::CodeStatistics::TEST_TYPES << "Mailer specs" if File.exist?('spec/mailer')
|
|
65
|
+
::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
|
|
66
|
+
::CodeStatistics::TEST_TYPES << "Request specs" if File.exist?('spec/requests')
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
3
|
+
|
|
4
|
+
ENV_PATH = File.expand_path('../../config/environment', __FILE__)
|
|
5
|
+
BOOT_PATH = File.expand_path('../../config/boot', __FILE__)
|
|
6
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
|
7
|
+
ROOT_PATH = File.expand_path('../..', __FILE__)
|
|
8
|
+
|
|
9
|
+
require BOOT_PATH
|
|
10
|
+
require 'rails/commands'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Todo For Acceptance Specs
|
|
2
|
+
|
|
3
|
+
# Feature: New Answer (for a Flight)
|
|
4
|
+
# In order add a new answer for a resource that can have a co2 computation
|
|
5
|
+
# As an application user
|
|
6
|
+
# I want to be able create a new answer
|
|
7
|
+
#
|
|
8
|
+
# Scenario: New Answer for a flight resource (Question wants a distance and a flight)
|
|
9
|
+
# Given a flight context exists with a valid question
|
|
10
|
+
# When go to the new flight answers page
|
|
11
|
+
#
|
|
12
|
+
# Then show me the page
|
|
13
|
+
# And I should see "Flight Calculator" within "#question"
|
|
14
|
+
# And I should see "Please enter flight details" within "#question"
|
|
15
|
+
# And I should see "Distance" within "#ui_objects"
|
|
16
|
+
# And I should see "Flight" within "#ui_objects"
|
|
17
|
+
# And I should see "flight1" within ".ui-objects-object_reference-drop-down-template"
|
|
18
|
+
# And I should see "flight2" within ".ui-objects-object_reference-drop-down-template"
|
|
19
|
+
#
|
|
20
|
+
# Feature: Edit Answer (for a Flight)
|
|
21
|
+
# In order to change the the details of the resource for a carbon calculation so calculations are correct
|
|
22
|
+
# As an application user
|
|
23
|
+
# I want to be able create a edit a carbon calculated resource (Flight)
|
|
24
|
+
#
|
|
25
|
+
# Scenario: View the edit page for the flight resource
|
|
26
|
+
# Given a flight context exists with a valid question
|
|
27
|
+
# And a flight exists with the id: "3458234509854309534", distance: "12", :flight => "23432234234"
|
|
28
|
+
# When go to the edit flight answer page
|
|
29
|
+
#
|
|
30
|
+
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Read about factories at http://github.com/thoughtbot/factory_girl
|
|
2
|
+
Factory.sequence :name do |n|
|
|
3
|
+
"name_#{n}"
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
Factory.sequence :object_name do |n|
|
|
7
|
+
"object_name_#{n}"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
Factory.sequence :label do |n|
|
|
11
|
+
"label_#{n}"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
Factory.sequence :related_attribute do |n|
|
|
15
|
+
"related_attribute_#{n}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
Factory.define :flight do |f|
|
|
19
|
+
f.question_id {BSON::ObjectId.new}
|
|
20
|
+
f.result{ {"co2"=> "45.5", "object_references" => {"123" => {"identifier" => "beans"}}}}
|
|
21
|
+
f.answer_params {{"flight" => "123"}}
|
|
22
|
+
f.reference {Factory.next(:name)}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
Factory.define :chain_template do |f|
|
|
26
|
+
f.for_resource "container"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
Factory.define :question do |f|
|
|
30
|
+
f.name {Factory.next(:name)}
|
|
31
|
+
f.label {Factory.next(:label)}
|
|
32
|
+
f.description "this is a question it can be about anything that is carbon"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
Factory.define :ui_group do |f|
|
|
36
|
+
f.name {Factory.next(:name)}
|
|
37
|
+
f.label {Factory.next(:label)}
|
|
38
|
+
f.description "this is a question it can be about anything that is carbon"
|
|
39
|
+
f.association :question
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
Factory.define :ui_object do |f|
|
|
43
|
+
f.label {Factory.next(:label)}
|
|
44
|
+
f.association :ui_group
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
Factory.define :drop_down, :class => UiObjects::DropDown do |f|
|
|
48
|
+
f.label {Factory.next(:label)}
|
|
49
|
+
f.association :ui_group
|
|
50
|
+
f.options {%w(what ever the egg says is true)}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
Factory.define :check_box, :class => UiObjects::CheckBox do |f|
|
|
54
|
+
f.label {Factory.next(:label)}
|
|
55
|
+
f.association :ui_group
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
Factory.define :hidden_field, :class => UiObjects::HiddenField do |f|
|
|
59
|
+
f.label {Factory.next(:label)}
|
|
60
|
+
f.association :ui_group
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
Factory.define :object_reference_drop_down, :class => UiObjects::ObjectReferenceDropDown do |f|
|
|
64
|
+
f.label {Factory.next(:label)}
|
|
65
|
+
f.association :ui_group
|
|
66
|
+
f.object_name {Factory.next(:object_name)}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
Factory.define :relatable_category_drop_down, :class => UiObjects::RelatableCategoryDropDown do |f|
|
|
70
|
+
f.association :ui_group
|
|
71
|
+
f.label {Factory.next(:label)}
|
|
72
|
+
f.related_attribute {Factory.next(:related_attribute)}
|
|
73
|
+
f.object_name {Factory.next(:object_name)}
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
Factory.define :text_field, :class => UiObjects::TextField do |f|
|
|
77
|
+
f.association :ui_group
|
|
78
|
+
f.label {Factory.next(:label)}
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "ChainTemplate" do
|
|
4
|
+
describe "when validating" do
|
|
5
|
+
before(:each) do
|
|
6
|
+
@chain_template = Factory.build(:chain_template, :context => {"egg" => "123"})
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should be cool from the factory" do
|
|
10
|
+
@chain_template.should be_valid
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should not be cool without a for_resource" do
|
|
14
|
+
@chain_template.for_resource = nil
|
|
15
|
+
@chain_template.should_not be_valid
|
|
16
|
+
end
|
|
17
|
+
it "should not be cool if the context is empty" do
|
|
18
|
+
@chain_template.context = {}
|
|
19
|
+
@chain_template.should_not be_valid
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "when activating" do
|
|
24
|
+
before(:each) do
|
|
25
|
+
@chain_template = Factory.build(:chain_template, :context => {"egg" => "123"})
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should be in a pending state to start off with" do
|
|
29
|
+
@chain_template.should be_pending
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should be in an active state one we have activated it" do
|
|
33
|
+
@chain_template.activate!
|
|
34
|
+
@chain_template.should be_active
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "when there is an account_id" do
|
|
39
|
+
before(:each) do
|
|
40
|
+
@account_id = BSON::ObjectId.new.to_s
|
|
41
|
+
@chain_template = Factory(:chain_template, :account_id => @account_id, :context => {"egg" => "123"})
|
|
42
|
+
@chain_template2 = Factory(:chain_template, :context => {"egg" => "123"})
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should find the account when specifying an account" do
|
|
46
|
+
ChainTemplate.first(:for_resource => "container", :account_id => @account_id).should_not be_nil
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "should find the default if the account_id nil" do
|
|
50
|
+
ChainTemplate.first(:for_resource => "container", :account_id => nil).should_not be_nil
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Flight (Test Model)" do
|
|
4
|
+
describe "when it is CarbonCalculated::Answerable" do
|
|
5
|
+
describe "initializing" do
|
|
6
|
+
before(:each) do
|
|
7
|
+
@flight = Flight.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should have answerable keys" do
|
|
11
|
+
@flight.keys.should include(:question_id)
|
|
12
|
+
@flight.keys.should include(:result)
|
|
13
|
+
@flight.keys.should include(:answer_params)
|
|
14
|
+
@flight.keys.should include(:answer_json)
|
|
15
|
+
@flight.keys.should include(:user_id)
|
|
16
|
+
@flight.keys.should include(:reference)
|
|
17
|
+
@flight.keys.should include(:stored_identifier)
|
|
18
|
+
@flight.keys.should include(:_extra_keywords)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "Should have access to _extra_keyword class method" do
|
|
22
|
+
Flight.should respond_to(:_extra_keyword_methods)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "when validating" do
|
|
27
|
+
before(:each) do
|
|
28
|
+
@flight = Factory.build(:flight)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "should be cool from the factory" do
|
|
32
|
+
@flight.should be_valid
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should not be cool if there is no question_id" do
|
|
36
|
+
@flight.question_id = nil
|
|
37
|
+
@flight.should_not be_valid
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should not be cool without a result" do
|
|
41
|
+
@flight.result = nil
|
|
42
|
+
@flight.should_not be_valid
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should not be cool without a answer_params" do
|
|
46
|
+
@flight.answer_params = nil
|
|
47
|
+
@flight.should_not be_valid
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "when save", "given that the flight has object with an identifier of beans" do
|
|
52
|
+
before(:each) do
|
|
53
|
+
@flight = Factory.build(:flight)
|
|
54
|
+
@flight.save
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "should have a identifier of 'beans'" do
|
|
58
|
+
@flight.identifier.should == "beans"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "should be searchable from the saved idenifier" do
|
|
62
|
+
flights = Flight.search "beans"
|
|
63
|
+
flights.first.should == @flight
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "should not be found on a silly search like eggs" do
|
|
67
|
+
flights = Flight.search "eggs"
|
|
68
|
+
flights.should be_empty
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe "when save", "given that the flight has more then 1 object reference" do
|
|
73
|
+
before(:each) do
|
|
74
|
+
@flight = Factory.build(:flight)
|
|
75
|
+
@flight.result = {"co2" => 234.234, "object_references" => {"1" => {"identifier" => "what"}, "2" => {"identifier" => "me"}}}
|
|
76
|
+
@flight.save
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should have a identifier of 'beans'" do
|
|
80
|
+
@flight.identifier.should == "what me"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe "when save", "with extra keyword methods that result in 'black rebel motocycle' keywords being added" do
|
|
85
|
+
before(:each) do
|
|
86
|
+
@flight = Factory.build(:flight)
|
|
87
|
+
@flight.result = {"co2" => 234.234, "object_references" => {"1" => {"identifier" => "what"}, "2" => {"identifier" => "me"}}}
|
|
88
|
+
@flight.save
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "should find the flight from the search 'black' OR 'motocycle'" do
|
|
92
|
+
flights = Flight.search "black"
|
|
93
|
+
flights.first.should == @flight
|
|
94
|
+
|
|
95
|
+
flights = Flight.search "motocycle"
|
|
96
|
+
flights.first.should == @flight
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe "Question" do
|
|
4
|
+
describe "when validating" do
|
|
5
|
+
before(:each) do
|
|
6
|
+
@question = Factory.build(:flight)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should be cool straight from the factory" do
|
|
10
|
+
@question.should be_valid
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe "ValueChange", "Given UiObject is cool" do
|
|
4
|
+
describe "when validating" do
|
|
5
|
+
before(:each) do
|
|
6
|
+
@ui_object = Factory(:text_field)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should be cool from the factory" do
|
|
10
|
+
@ui_object.rules << Rules::ValueChange.new(
|
|
11
|
+
:affecting_ui_object_id => Factory(:hidden_field).id,
|
|
12
|
+
:change_value => "egg"
|
|
13
|
+
)
|
|
14
|
+
@ui_object.should be_valid
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should not be cool if the rule does not have an affecting_ui_object_id" do
|
|
18
|
+
@ui_object.rules << Rules::ValueChange.new(
|
|
19
|
+
:change_value => "egg"
|
|
20
|
+
)
|
|
21
|
+
@ui_object.should_not be_valid
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should not be cool if the rule does not have an change value" do
|
|
25
|
+
@ui_object.rules << Rules::ValueChange.new(
|
|
26
|
+
:affecting_ui_object_id => Factory(:hidden_field).id
|
|
27
|
+
)
|
|
28
|
+
@ui_object.should_not be_valid
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
|
+
|
|
3
|
+
describe "UiGroup" do
|
|
4
|
+
describe "when validating" do
|
|
5
|
+
before(:each) do
|
|
6
|
+
@ui_group = Factory.build(:ui_group)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should be cool from the blueprint" do
|
|
10
|
+
@ui_group.should be_valid
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should not be cool without a name" do
|
|
14
|
+
@ui_group.name = nil
|
|
15
|
+
@ui_group.should_not be_valid
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should not be cool without a label" do
|
|
20
|
+
@ui_group.label = nil
|
|
21
|
+
@ui_group.should_not be_valid
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should not be cool if it does not have a question" do
|
|
25
|
+
@ui_group.question = nil
|
|
26
|
+
@ui_group.should_not be_valid
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe "when assign some ui_objects", "1 text field, 1 relatable_category_drop_down, 1 object_reference_drop_down" do
|
|
31
|
+
before(:each) do
|
|
32
|
+
@ui_group = Factory.build(:ui_group)
|
|
33
|
+
@text_field = @ui_group.text_fields.create!(Factory.attributes_for(:text_field))
|
|
34
|
+
@relatable_category_drop_down = @ui_group.relatable_category_drop_downs.create!(Factory.attributes_for(:relatable_category_drop_down))
|
|
35
|
+
@object_referenece_drop_down = @ui_group.object_reference_drop_down.create!(Factory.attributes_for(:object_reference_drop_down))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should have 3 ui_objects" do
|
|
39
|
+
@ui_group.ui_objects.size.should == 3
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "should have 1 relatable_category drop down" do
|
|
43
|
+
@ui_group.relatable_category_drop_downs.size.should == 1
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should have 1 object_reference drop down" do
|
|
47
|
+
@ui_group.object_reference_drop_down.should_not be_nil
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should have 1 text field" do
|
|
51
|
+
@ui_group.text_fields.size.should == 1
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
end
|