This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var val = 1.995, | |
dp = 2, | |
scale = Math.pow(10, dp), | |
rounded = Math.round(val * scale) / scale; | |
console.log(val + ' ==> ' + rounded); // "1.995 ==> 2" |
This file has been truncated, but you can view the full file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"id":"f2eb8a62-ce3c-4104-8d9c-749059fd79ce","source_id":null,"variant_source_id":null,"handle":"adunn","type":"quam","variant_parent_id":null,"active":true,"name":"viverra pede ac diam cras pellentesque volutpat","description":"Pellentesque viverra pede ac diam. Cras pellentesque volutpat dui. Maecenas tristique, est et tempus semper, est quam pharetra magna, ac consequat metus sapien ut nunc.","sku":"llopez","price":3398.40672,"tax":2736.7653,"tax_id":"e22bed8e-c87b-403a-860b-6c7255770e37","tax_name":"id nisl","updated_at":"2013-11-08 00:07:41","created_at":"2014-07-12 18:25:13","deleted_at":null}, | |
{"id":"212b82f6-d762-4ce2-9bfb-190d17f0b69d","source_id":null,"variant_source_id":null,"handle":"rortiz","type":"quam","variant_parent_id":null,"active":true,"name":"risus semper porta volutpat quam pede lobortis ligula sit amet eleifend pede","description":"Aliquam sit amet diam in magna bibendum imperdiet. Nullam orci pede, venenatis non, sodales sed, tincidunt eu, felis. Fusce posuere felis sed lacus. Morbi s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/spec_helper.rb | |
require 'elasticsearch/extensions/test/cluster' | |
RSpec.configure do |config| | |
# Start an in-memory cluster for Elasticsearch as needed | |
config.before :all, elasticsearch: true do | |
Elasticsearch::Extensions::Test::Cluster.start(port: 9250, nodes: 1, timeout: 120) unless Elasticsearch::Extensions::Test::Cluster.running?(on: 9250) | |
end | |
# Stop elasticsearch cluster after test run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gemfile | |
group :test do | |
gem 'elasticsearch-extensions' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/spec_helper.rb | |
RSpec.configure do |config| | |
# Create indexes for all elastic searchable models | |
config.before :each, elasticsearch: true do | |
ActiveRecord::Base.descendants.each do |model| | |
if model.respond_to?(:__elasticsearch__) | |
begin | |
model.__elasticsearch__.create_index! | |
model.__elasticsearch__.refresh_index! | |
rescue Elasticsearch::Transport::Transport::Errors::NotFound => e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/model/fruit_spec.rb | |
RSpec.describe Fruit, elasticsearch: true, :type => :model do | |
it 'should be indexed' do | |
# create an instance of your model | |
Fruit.create(name: 'apple') | |
# refresh the index | |
Fruit.__elasticsearch__.refresh_index! | |
# verify your model was indexed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gemfile | |
group :test do | |
gem 'test_after_commit' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .travis.yml | |
services: | |
- elasticsearch | |
before_script: | |
- sleep 5 # To make sure Elasticsearch instance is ready |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gemfile | |
group :test do | |
gem 'database_cleaner' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/rails_helper.rb | |
config.before(:suite) do | |
DatabaseCleaner.strategy = :transaction | |
DatabaseCleaner.clean_with(:truncation) | |
end | |
config.around(:each) do |example| | |
DatabaseCleaner.cleaning do | |
example.run | |
end |
OlderNewer