Skip to content

Commit bf5990a

Browse files
committed
Do not include invisible market in Market.all
1 parent 439d94c commit bf5990a

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

app/models/market.rb

+7
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@
1111
class Market < ActiveYamlBase
1212
include Enumerizeable
1313

14+
field :visible, default: true
15+
1416
attr :name, :target_unit, :price_unit
1517

18+
self.singleton_class.send :alias_method, :orig_all, :all
19+
def self.all
20+
orig_all.select &:visible
21+
end
22+
1623
# TODO: our market id is the opposite of conventional market name.
1724
# e.g. our 'btccny' market should use 'btccny' as id, and its name should
1825
# be 'BTC/CNY'

config/markets.yml.example

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
code: 3
33
bid: {fee: 0, currency: cny, fixed: 2}
44
ask: {fee: 0, currency: btc, fixed: 4}
5+
#visible: false # default to true

spec/fixtures/currencies.yml

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
rpc: http://bitcoinrpc:[email protected]:18332
1010
blockchain: http://testnet.btclook.com/txn/#{txid}
1111
address_url: https://blockchain.info/address/#{address}
12+
- id: 4
13+
key: protoshare
14+
code: pts
15+
coin: true

spec/fixtures/markets.yml

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
code: 3
33
bid: {fee: 0, currency: cny, fixed: 2}
44
ask: {fee: 0, currency: btc, fixed: 4}
5+
- id: ptsbtc
6+
code: 6
7+
bid: {fee: 0, currency: btc, fixed: 4}
8+
ask: {fee: 0, currency: pts, fixed: 4}
9+
visible: false

spec/models/market_spec.rb

+14-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22

33
describe Market do
44

5-
subject { Market.find('btccny') }
6-
7-
its(:id) { should == 'btccny' }
8-
its(:name) { should == 'BTC/CNY' }
9-
its(:target_unit) { should == 'btc' }
10-
its(:price_unit) { should == 'cny' }
11-
125
it "should raise argument error on invalid market id" do
136
expect { Market.new(id: 'dogecny') }.to raise_error(ArgumentError)
147
expect { Market.new(id: 'dogcny') }.not_to raise_error
158
end
169

10+
context 'visible market' do
11+
it { expect(Market.orig_all.count).to eq(2) }
12+
it { expect(Market.all.count).to eq(1) }
13+
end
14+
15+
context 'market attributes' do
16+
subject { Market.find('btccny') }
17+
18+
its(:id) { should == 'btccny' }
19+
its(:name) { should == 'BTC/CNY' }
20+
its(:target_unit) { should == 'btc' }
21+
its(:price_unit) { should == 'cny' }
22+
its(:visible) { should be_true }
23+
end
1724
end

0 commit comments

Comments
 (0)