spec/expressive_spec.rb in expressive-0.0.29 vs spec/expressive_spec.rb in expressive-0.0.30
- old
+ new
@@ -4,11 +4,11 @@
before(:each) do
@scope = Expressive::TopLevel.new
end
describe "all_symbols" do
- it { Expressive.all_symbols.should =~ %w(+ - * / = set sum $sub get put post >= > < <= and or if date datetime lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail $hash $concat $split $sms $hval) }
+ it { Expressive.all_symbols.should =~ %w(+ - * / = set sum $sub get put post >= > < <= and or if date datetime lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail $hash $concat $split $sms $hval $index) }
end
describe "understands booleans" do
it { Expressive.run("true").should eql true }
it { Expressive.run("false").should eql false }
@@ -89,10 +89,11 @@
describe "understands compound statements" do
it { Expressive.run("(= (+ 4 2) 6)").should eql true }
it { Expressive.run("(if (and (< 3 9) (> 2 1)), true, false)").should eql true }
it { Expressive.run("(if (and (< 10 9) (> 2 1)), true, false)").should eql false }
+
end
describe "understands conditional statements" do
it { Expressive.run('(if (> 5 4) "greater" "not so greater")').should eql "greater" }
it { Expressive.run('(if (= 5.2473 5.3473) true false)').should eql false }
@@ -259,11 +260,11 @@
end
end
describe "understands the modification of scope" do
- it "works" do
+ it "sets scope based off rounded equality calculation" do
@scope['total_payment_amount'] = 2.32
@scope['refund_amount'] = 2.32
@scope['payment_reconciled'] = "asdf"
Expressive.run('(if (= ($round total_payment_amount 2) ($round refund_amount 2)) true false)', @scope).should eql true
Expressive.run('(if (= ($round total_payment_amount 2) ($round refund_amount 2)) true, false)', @scope).should eql true
@@ -357,10 +358,53 @@
@scope["owned_by_type"].should eql "RSpec::Mocks::Mock"
end
end
+ describe "$index" do
+ it "generates an array" do
+ Expressive.run('(2 3)').should eql [2,3]
+ end
+ it "picks out correct field" do
+ Expressive.run('($index (2 3) 1)').should eql 3
+ end
+
+ it "picks correct result from calculations" do
+ @scope["total_payment_amount"] = 56
+ @scope.add_lookup_function("related_payments_count") do |options, additional_query_specs = []|
+ 2
+ end
+
+ @scope.add_lookup_function("related_payments_summed") do |options, select_field, additional_query_specs = []|
+ 200.50
+ end
+
+ result = Expressive.run('($index ((set total_payment_amount ($round (lookup related_payments_summed \"total_amount\") 2)) (lookup related_payments_count)) 1)', @scope)
+
+ @scope["total_payment_amount"].should == 200.50
+ result.should == 2
+
+ end
+ end
+
+
+ it "sets value and then looksup another" do
+ @scope["total_payment_amount"] = 56
+ @scope.add_lookup_function("related_payments_count") do |options, additional_query_specs = []|
+ 2
+ end
+
+ @scope.add_lookup_function("related_payments_summed") do |options, select_field, additional_query_specs = []|
+ 200.50
+ end
+
+ result = Expressive.run('(set total_payment_amount ($round (lookup related_payments_summed \"total_amount\") 2)) (lookup related_payments_count)', @scope)
+
+ @scope["total_payment_amount"].should == 200.50
+ result.should == 2
+ end
+
describe "understands adding values to lists" do
it "add a single value to a list of values" do
Expressive.run('($append participating_teams 1)', @scope)
@scope['participating_teams'].should == [1]
end
@@ -392,9 +436,22 @@
it { Expressive.run("($days_ago 28)").should eql (@now - 28 * 86400) }
it { Expressive.run("($hours_ago 7)").should eql (@now - 7 * 3600) }
it { Expressive.run("($minutes_ago 12)").should eql (@now - 12 * 60) }
end
+ describe "concat" do
+ it "string and number values" do
+ Expressive.run('($concat "ref-" 3)').should eql "ref-3"
+ end
+
+ it "concats from lookups" do
+ @scope.add_lookup_function("related_matter", case_type: "matter_case_type") do |options, select_field, additional_query_specs = []|
+ "value1"
+ end
+ Expressive.run('($concat "matter-" (lookup related_matter "field1"))', @scope).should eql "matter-value1"
+ end
+
+ end
describe "understands using lookup functions" do
it "should perform the lookup function (add account and reverse login)" do
@scope.add_lookup_function("account_reverse_login", account: "ea") do |options, login|
"#{options[:account]}-#{login.reverse}"