smart_sms 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/.rdoc_options +21 -0
- data/Gemfile.lock +25 -11
- data/README.md +10 -11
- data/lib/generators/smart_sms/install_generator.rb +3 -1
- data/lib/generators/smart_sms/templates/add_uid_to_smart_sms_messages.rb +6 -0
- data/lib/smart_sms/account.rb +6 -3
- data/lib/smart_sms/config.rb +20 -20
- data/lib/smart_sms/has_sms_verification.rb +8 -5
- data/lib/smart_sms/helpers/fake_sms.rb +9 -1
- data/lib/smart_sms/helpers/verification_code.rb +6 -4
- data/lib/smart_sms/message_service.rb +20 -9
- data/lib/smart_sms/model/message.rb +1 -1
- data/lib/smart_sms/request.rb +7 -0
- data/lib/smart_sms/template.rb +4 -2
- data/lib/smart_sms/version.rb +1 -1
- data/smart_sms.gemspec +3 -1
- data/spec/fake_app/active_record/models.rb +2 -0
- data/spec/has_sms_verificaton_spec.rb +18 -18
- data/spec/smart_sms_spec.rb +2 -1
- data/spec/spec_helper.rb +1 -0
- metadata +35 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3569350a7e3da1867a4cb90fd0c1dd1cf120adb6
|
4
|
+
data.tar.gz: 5c712a0e4a500ec1b8568d41b1bdfba2d4e34c60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46a33be40d5698125a8112051cfdbfdcf9f0d9a56fb25f3222f09c7515f02fb45501086d451c0be602e3ac20bf7e854934e728bb6eb9ba689d9a81daa6e62b2e
|
7
|
+
data.tar.gz: 727df1af981327fcd5d35d5b4ae13ad0d8e09028616e79b19176d3164419907d37adbfdb1cc23facee31d6001b4c6c60a13f1e6e4a90c2efc8ab14982700e34e
|
data/.rdoc_options
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
--- !ruby/object:RDoc::Options
|
2
|
+
encoding: UTF-8
|
3
|
+
static_path: []
|
4
|
+
rdoc_include:
|
5
|
+
- "./lib"
|
6
|
+
charset: UTF-8
|
7
|
+
exclude:
|
8
|
+
- './spec'
|
9
|
+
hyperlink_all: true
|
10
|
+
line_numbers: true
|
11
|
+
main_page:
|
12
|
+
markup: markdown
|
13
|
+
output_decoration: true
|
14
|
+
page_dir:
|
15
|
+
search_index: true
|
16
|
+
show_hash: false
|
17
|
+
tab_width: 8
|
18
|
+
template_stylesheets: []
|
19
|
+
title:
|
20
|
+
visibility: :private
|
21
|
+
webcvs:
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smart_sms (0.1.
|
4
|
+
smart_sms (0.1.1)
|
5
5
|
activerecord (>= 3.0, < 5.0)
|
6
6
|
activesupport (>= 3.0, < 5.0)
|
7
7
|
|
@@ -77,19 +77,31 @@ GEM
|
|
77
77
|
rake (>= 0.8.7)
|
78
78
|
thor (>= 0.18.1, < 2.0)
|
79
79
|
rake (10.3.1)
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
rspec-
|
80
|
+
rdoc (4.1.1)
|
81
|
+
json (~> 1.4)
|
82
|
+
rspec-core (3.1.7)
|
83
|
+
rspec-support (~> 3.1.0)
|
84
|
+
rspec-expectations (3.1.2)
|
85
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
86
|
+
rspec-support (~> 3.1.0)
|
87
|
+
rspec-its (1.1.0)
|
88
|
+
rspec-core (>= 3.0.0)
|
89
|
+
rspec-expectations (>= 3.0.0)
|
90
|
+
rspec-mocks (3.1.3)
|
91
|
+
rspec-support (~> 3.1.0)
|
92
|
+
rspec-rails (3.1.0)
|
85
93
|
actionpack (>= 3.0)
|
86
|
-
activemodel (>= 3.0)
|
87
94
|
activesupport (>= 3.0)
|
88
95
|
railties (>= 3.0)
|
89
|
-
rspec-core (~>
|
90
|
-
rspec-expectations (~>
|
91
|
-
rspec-mocks (~>
|
96
|
+
rspec-core (~> 3.1.0)
|
97
|
+
rspec-expectations (~> 3.1.0)
|
98
|
+
rspec-mocks (~> 3.1.0)
|
99
|
+
rspec-support (~> 3.1.0)
|
100
|
+
rspec-support (3.1.2)
|
92
101
|
safe_yaml (1.0.3)
|
102
|
+
sdoc (0.4.0)
|
103
|
+
json (~> 1.8)
|
104
|
+
rdoc (~> 4.0, < 5.0)
|
93
105
|
slop (3.5.0)
|
94
106
|
sprockets (2.12.1)
|
95
107
|
hike (~> 1.2)
|
@@ -122,7 +134,9 @@ DEPENDENCIES
|
|
122
134
|
pry
|
123
135
|
rails (>= 3.1.0)
|
124
136
|
rake
|
125
|
-
rspec-
|
137
|
+
rspec-its (>= 1.0.0)
|
138
|
+
rspec-rails (>= 3.0.0)
|
139
|
+
sdoc
|
126
140
|
smart_sms!
|
127
141
|
sqlite3
|
128
142
|
webmock (~> 1.17.0)
|
data/README.md
CHANGED
@@ -244,15 +244,18 @@ SmartSMS::Template.destroy 3252
|
|
244
244
|
``` ruby
|
245
245
|
|
246
246
|
# 生成随机校验码
|
247
|
-
#
|
248
|
-
#
|
249
|
-
#
|
250
|
-
#
|
251
|
-
|
252
|
-
|
247
|
+
# 四个选项:
|
248
|
+
# short: 4位随机数字
|
249
|
+
# simple: 6位随机数字, 默认
|
250
|
+
# middle: 6位随机字母, 数字组合
|
251
|
+
# complex: 8位随机字母, 数字, 特殊字符组合
|
252
|
+
|
253
|
+
SmartSMS::VerificationCode.random # => "1708"
|
254
|
+
SmartSMS::VerificationCode.random :short # => "141068"
|
253
255
|
SmartSMS::VerificationCode.random :middle # => "xey7id"
|
254
256
|
SmartSMS::VerificationCode.random :complex # => "x+rkag6a"
|
255
257
|
|
258
|
+
SmartSMS::VerificationCode.short # => "1708"
|
256
259
|
SmartSMS::VerificationCode.simple # => "141068"
|
257
260
|
SmartSMS::VerificationCode.middle # => "xey7id"
|
258
261
|
SmartSMS::VerificationCode.complex # => "x+rkag6a"
|
@@ -269,12 +272,8 @@ SmartSMS::VerificationCode.complex # => "x+rkag6a"
|
|
269
272
|
|
270
273
|
## LICENCE
|
271
274
|
|
272
|
-
MIT
|
275
|
+
[MIT](https://github.com/lyfeyaj/smart_sms/blob/master/LICENSE)
|
273
276
|
|
274
277
|
## 作者
|
275
278
|
|
276
279
|
[Felix Liu](https://github.com/lyfeyaj)
|
277
|
-
|
278
|
-
## TODO
|
279
|
-
|
280
|
-
+ 增加测试用例覆盖率
|
@@ -14,7 +14,9 @@ before running this command
|
|
14
14
|
EOF
|
15
15
|
|
16
16
|
def create_migration_file
|
17
|
-
|
17
|
+
return unless SmartSMS.config.store_sms_in_local
|
18
|
+
add_smart_sms_migration('create_smart_sms_messages')
|
19
|
+
add_smart_sms_migration('add_uid_to_smart_sms_messages')
|
18
20
|
end
|
19
21
|
|
20
22
|
def self.next_migration_number(dirname)
|
data/lib/smart_sms/account.rb
CHANGED
@@ -7,14 +7,17 @@ module SmartSMS
|
|
7
7
|
module_function
|
8
8
|
|
9
9
|
# 获取用户信息
|
10
|
+
#
|
10
11
|
def info
|
11
12
|
Request.post 'user/get.json'
|
12
13
|
end
|
13
14
|
|
14
15
|
# 设置用户信息
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
16
|
+
#
|
17
|
+
# * emergency_contact: 紧急联系人
|
18
|
+
# * emergency_mobile: 紧急联系人手机号
|
19
|
+
# * alarm_balance: 短信余额提醒阈值。一天只提示一次
|
20
|
+
#
|
18
21
|
def set(options = {})
|
19
22
|
Request.post 'user/set.json', options
|
20
23
|
end
|
data/lib/smart_sms/config.rb
CHANGED
@@ -20,30 +20,30 @@ module SmartSMS
|
|
20
20
|
#
|
21
21
|
class Configuration #:nodoc:
|
22
22
|
include ActiveSupport::Configurable
|
23
|
-
config_accessor :api_key
|
24
|
-
config_accessor :api_version
|
25
|
-
config_accessor :template_id
|
26
|
-
config_accessor :template_value
|
27
|
-
config_accessor :page_num
|
28
|
-
config_accessor :page_size
|
29
|
-
config_accessor :company
|
30
|
-
config_accessor :expires_in
|
31
|
-
config_accessor :default_interval
|
32
|
-
config_accessor :store_sms_in_local
|
23
|
+
config_accessor :api_key # 授权 API KEY
|
24
|
+
config_accessor :api_version # API 的版本, 当前仅有v1
|
25
|
+
config_accessor :template_id # 指定发送信息时使用的模板
|
26
|
+
config_accessor :template_value # 用于指定信息文本中的可替换内容, 数组形势: [:code, :company]
|
27
|
+
config_accessor :page_num # 获取信息时, 指定默认的页数
|
28
|
+
config_accessor :page_size # 获取信息时, 一页包含信息数量
|
29
|
+
config_accessor :company # 默认公司名称
|
30
|
+
config_accessor :expires_in # 短信验证过期时间
|
31
|
+
config_accessor :default_interval # 查询短信时的默认时间段: end_time - start_time
|
32
|
+
config_accessor :store_sms_in_local # 是否存储SMS信息在本地: true or false
|
33
33
|
config_accessor :verification_code_algorithm # :simple, :middle, :complex
|
34
34
|
end
|
35
35
|
|
36
36
|
configure do |config|
|
37
|
-
config.api_key
|
38
|
-
config.api_version
|
39
|
-
config.template_id
|
40
|
-
config.template_value
|
41
|
-
config.page_num
|
42
|
-
config.page_size
|
43
|
-
config.company
|
44
|
-
config.expires_in
|
45
|
-
config.default_interval
|
46
|
-
config.store_sms_in_local
|
37
|
+
config.api_key = nil
|
38
|
+
config.api_version = :v1
|
39
|
+
config.template_id = '2'
|
40
|
+
config.template_value = [:code, :company]
|
41
|
+
config.page_num = 1
|
42
|
+
config.page_size = 20
|
43
|
+
config.company = '云片网'
|
44
|
+
config.expires_in = 1.hour
|
45
|
+
config.default_interval = 1.day
|
46
|
+
config.store_sms_in_local = false
|
47
47
|
config.verification_code_algorithm = :simple
|
48
48
|
end
|
49
49
|
end
|
@@ -13,12 +13,13 @@ module SmartSMS
|
|
13
13
|
module ClassMethods
|
14
14
|
|
15
15
|
# 在您的Model里面声明这个方法, 以添加SMS短信验证功能
|
16
|
-
#
|
17
|
-
#
|
16
|
+
#
|
17
|
+
# * moible_column: mobile 绑定的字段, 用于发送短信, 默认 :phone
|
18
|
+
# * verification_column: 验证绑定的字段, 用于判断是否已验证, 默认 :verified_at
|
18
19
|
#
|
19
20
|
# Options:
|
20
|
-
# :class_name 自定义的Message类名称. 默认是 `::SmartSMS::Message`
|
21
|
-
# :messages 自定义的Message关联名称. 默认是 `:
|
21
|
+
# * :class_name 自定义的Message类名称. 默认是 `::SmartSMS::Message`
|
22
|
+
# * :messages 自定义的Message关联名称. 默认是 `:messages`.
|
22
23
|
#
|
23
24
|
def has_sms_verification(moible_column = :phone, verification_column = :verified_at, options = {})
|
24
25
|
send :include, InstanceMethods
|
@@ -41,7 +42,7 @@ module SmartSMS
|
|
41
42
|
class_attribute :message_class_name
|
42
43
|
self.message_class_name = options[:class_name] || '::SmartSMS::Message'
|
43
44
|
|
44
|
-
if ::ActiveRecord::VERSION::MAJOR >= 4 # Rails 4
|
45
|
+
if ::ActiveRecord::VERSION::MAJOR >= 4 # Rails 4 的 `has_many` 中定义order lambda的新语法
|
45
46
|
has_many messages_association_name,
|
46
47
|
-> { order('send_time ASC') },
|
47
48
|
class_name: message_class_name,
|
@@ -57,8 +58,10 @@ module SmartSMS
|
|
57
58
|
end
|
58
59
|
|
59
60
|
# Instance methods
|
61
|
+
#
|
60
62
|
module InstanceMethods
|
61
63
|
# 非安全verify!方法, 验证成功后会存储成功的结果到数据表中
|
64
|
+
#
|
62
65
|
def verify!(code)
|
63
66
|
result = verify code
|
64
67
|
if result
|
@@ -1,11 +1,19 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module SmartSMS
|
4
|
-
#
|
4
|
+
# Module that contains methods to generate fake message
|
5
5
|
#
|
6
6
|
module FakeSMS
|
7
7
|
module_function
|
8
8
|
|
9
|
+
# This will generate fake sms with all necessary attributes
|
10
|
+
#
|
11
|
+
# Options:
|
12
|
+
#
|
13
|
+
# * mobile: mobile number
|
14
|
+
# * code: verification code
|
15
|
+
# * company: assigned company, format is【company】
|
16
|
+
#
|
9
17
|
def build_fake_sms(mobile, code, company)
|
10
18
|
{
|
11
19
|
'sid' => SecureRandom.uuid,
|
@@ -2,11 +2,13 @@ require 'securerandom'
|
|
2
2
|
|
3
3
|
module SmartSMS
|
4
4
|
# This module provides some methods to generate random verification code
|
5
|
+
#
|
5
6
|
# Algorithm:
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
7
|
+
#
|
8
|
+
# * short: Generate short code with 4 numbers
|
9
|
+
# * simple: Generate simple code with 6 numbers
|
10
|
+
# * middle: Generate middle complex code of 6 charactors with mixed numbers and letters
|
11
|
+
# * complex: Generate complex code of 8 charactors with mixed numbers, letters or special charactors
|
10
12
|
module VerificationCode
|
11
13
|
module_function
|
12
14
|
|
@@ -10,12 +10,14 @@ module SmartSMS
|
|
10
10
|
DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
|
11
11
|
|
12
12
|
# 发送短信到手机, 默认使用模板发送, 提供通用接口支持
|
13
|
-
#
|
14
|
-
#
|
13
|
+
#
|
14
|
+
# * phone: 需要接受短信的手机号码
|
15
|
+
# * content: 短信验证内容
|
15
16
|
#
|
16
17
|
# Options:
|
17
|
-
#
|
18
|
-
# :
|
18
|
+
#
|
19
|
+
# * method 如若要使用通用短信接口, 需要 :method => :general
|
20
|
+
# * tpl_id 选择发送短信的模板, 默认是2
|
19
21
|
def deliver(phone, content, options = {})
|
20
22
|
if options[:method] == :general
|
21
23
|
Request.post 'sms/send.json', mobile: phone, text: content, extend: options[:extend]
|
@@ -38,10 +40,13 @@ module SmartSMS
|
|
38
40
|
find_messages 'sms/get.json', options
|
39
41
|
end
|
40
42
|
|
43
|
+
# 查询黑名单词语, 用于预先测试可能无法通过审核的模板
|
44
|
+
#
|
41
45
|
def get_black_word(text = '')
|
42
46
|
Request.post 'sms/get_black_word.json', text: text
|
43
47
|
end
|
44
48
|
|
49
|
+
# 查询用户回复的短信, 参见 `find_messages` 方法
|
45
50
|
def get_reply(options = {})
|
46
51
|
find_messages 'sms/get_reply.json', options
|
47
52
|
end
|
@@ -49,11 +54,12 @@ module SmartSMS
|
|
49
54
|
private
|
50
55
|
|
51
56
|
# 批量查短信, 参数:
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
+
#
|
58
|
+
# * start_time: 短信提交开始时间
|
59
|
+
# * end_time: 短信提交结束时间
|
60
|
+
# * page_num: 页码,从1开始
|
61
|
+
# * page_size: 每页个数,最大100个
|
62
|
+
# * mobile: 接收短信的手机号
|
57
63
|
#
|
58
64
|
def find_messages(api, options = {})
|
59
65
|
options[:end_time] = Time.now if options[:end_time].blank?
|
@@ -65,6 +71,9 @@ module SmartSMS
|
|
65
71
|
Request.post api, options
|
66
72
|
end
|
67
73
|
|
74
|
+
# 解析日期时间
|
75
|
+
# 格式可以是 `2014-05-01 08:40:20`, 也可以是Time类型
|
76
|
+
#
|
68
77
|
def parse_time(time = '')
|
69
78
|
if time.present? && time.is_a?(Time)
|
70
79
|
time.strftime DATETIME_FORMAT
|
@@ -75,6 +84,8 @@ module SmartSMS
|
|
75
84
|
end
|
76
85
|
end
|
77
86
|
|
87
|
+
# 生成信息发送内容
|
88
|
+
#
|
78
89
|
def parse_content(options = {})
|
79
90
|
options[:code] ||= ''
|
80
91
|
options[:company] ||= SmartSMS.config.company
|
@@ -4,6 +4,6 @@ module SmartSMS
|
|
4
4
|
class Message < ::ActiveRecord::Base
|
5
5
|
self.table_name = 'smart_sms_messages'
|
6
6
|
belongs_to :smsable, polymorphic: true
|
7
|
-
attr_accessible :sid, :mobile, :send_time, :text, :code, :send_status, :report_status, :fee, :user_receive_time, :error_msg if SmartSMS.active_record_protected_attributes?
|
7
|
+
attr_accessible :sid, :uid, :mobile, :send_time, :text, :code, :send_status, :report_status, :fee, :user_receive_time, :error_msg if SmartSMS.active_record_protected_attributes?
|
8
8
|
end
|
9
9
|
end
|
data/lib/smart_sms/request.rb
CHANGED
@@ -5,6 +5,8 @@ require 'active_support/json'
|
|
5
5
|
module SmartSMS
|
6
6
|
# Module that manage requests
|
7
7
|
module Request
|
8
|
+
# Method that use `Net::HTTP.post_form` to perform `POST` action
|
9
|
+
#
|
8
10
|
def post(api, options = {})
|
9
11
|
options[:apikey] = SmartSMS.config.api_key
|
10
12
|
uri = URI.join(base_url, api)
|
@@ -12,6 +14,8 @@ module SmartSMS
|
|
12
14
|
result res.body
|
13
15
|
end
|
14
16
|
|
17
|
+
# Method that use `Net::HTTP.get` to perform `GET` action
|
18
|
+
#
|
15
19
|
def get(api, options = {})
|
16
20
|
options[:apikey] = SmartSMS.config.api_key
|
17
21
|
uri = URI.join(base_url, api)
|
@@ -20,6 +24,8 @@ module SmartSMS
|
|
20
24
|
|
21
25
|
private
|
22
26
|
|
27
|
+
# Method that parse JSON to Hash
|
28
|
+
#
|
23
29
|
def result(body)
|
24
30
|
begin
|
25
31
|
ActiveSupport::JSON.decode body
|
@@ -32,6 +38,7 @@ module SmartSMS
|
|
32
38
|
end
|
33
39
|
end
|
34
40
|
|
41
|
+
# Base uri for yunpian API
|
35
42
|
def base_url
|
36
43
|
"http://yunpian.com/#{SmartSMS.config.api_version}/"
|
37
44
|
end
|
data/lib/smart_sms/template.rb
CHANGED
@@ -7,7 +7,8 @@ module SmartSMS
|
|
7
7
|
|
8
8
|
# 取默认模板
|
9
9
|
# Options:
|
10
|
-
#
|
10
|
+
#
|
11
|
+
# * tpl_id: 指定tpl_id时返回tpl_id对应的默认模板. 未指定时返回所有默认模板
|
11
12
|
#
|
12
13
|
def find_default(tpl_id = '')
|
13
14
|
Request.post 'tpl/get_default.json', tpl_id: tpl_id
|
@@ -15,7 +16,8 @@ module SmartSMS
|
|
15
16
|
|
16
17
|
# 取自定义模板
|
17
18
|
# Options:
|
18
|
-
#
|
19
|
+
#
|
20
|
+
# * tpl_id: 指定tpl_id时返回tpl_id对应的自定义模板. 未指定时返回所有自定义模板
|
19
21
|
#
|
20
22
|
def find(tpl_id = '')
|
21
23
|
Request.post 'tpl/get.json', tpl_id: tpl_id
|
data/lib/smart_sms/version.rb
CHANGED
data/smart_sms.gemspec
CHANGED
@@ -24,10 +24,12 @@ Gem::Specification.new do |s|
|
|
24
24
|
|
25
25
|
s.add_development_dependency 'bundler', ['>= 1.0.0']
|
26
26
|
s.add_development_dependency 'rake', ['>= 0']
|
27
|
-
s.add_development_dependency 'rspec-rails', ['>= 0']
|
27
|
+
s.add_development_dependency 'rspec-rails', ['>= 3.0.0']
|
28
|
+
s.add_development_dependency 'rspec-its', ['>= 1.0.0']
|
28
29
|
s.add_development_dependency 'database_cleaner', ['~> 1.2.0']
|
29
30
|
s.add_development_dependency 'webmock', ['~> 1.17.0']
|
30
31
|
s.add_development_dependency 'rails', ['>= 3.1.0']
|
31
32
|
s.add_development_dependency 'sqlite3', ['>= 0']
|
32
33
|
s.add_development_dependency 'pry', ['>= 0']
|
34
|
+
s.add_development_dependency 'sdoc', ['>= 0']
|
33
35
|
end
|
@@ -23,6 +23,7 @@ class CreateAllTables < ActiveRecord::Migration
|
|
23
23
|
|
24
24
|
create_table :smart_sms_messages do |t|
|
25
25
|
t.string :sid
|
26
|
+
t.string :uid
|
26
27
|
t.string :mobile
|
27
28
|
t.datetime :send_time
|
28
29
|
t.text :text
|
@@ -35,6 +36,7 @@ class CreateAllTables < ActiveRecord::Migration
|
|
35
36
|
t.belongs_to :smsable, polymorphic: true
|
36
37
|
end
|
37
38
|
add_index :smart_sms_messages, :sid
|
39
|
+
add_index :smart_sms_messages, :uid
|
38
40
|
add_index :smart_sms_messages, [:smsable_id, :smsable_type]
|
39
41
|
end
|
40
42
|
end
|
@@ -18,8 +18,8 @@ describe 'SmartSMS::HasSmsVerification' do
|
|
18
18
|
before { user.verify! verification_code }
|
19
19
|
|
20
20
|
it 'should be verified' do
|
21
|
-
expect
|
22
|
-
expect(user.reload.verified?).to
|
21
|
+
expect(user.verify! verification_code).to be_truthy
|
22
|
+
expect(user.reload.verified?).to be_truthy
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should have right verification code' do
|
@@ -46,7 +46,7 @@ describe 'SmartSMS::HasSmsVerification' do
|
|
46
46
|
|
47
47
|
it 'should not be verified' do
|
48
48
|
expect(user.verify!('kfdsfd')).to be_nil
|
49
|
-
expect(user.reload.verified?).to
|
49
|
+
expect(user.reload.verified?).to be_falsey
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'should not have right verification code' do
|
@@ -79,8 +79,8 @@ describe 'SmartSMS::HasSmsVerification' do
|
|
79
79
|
before { account.verify! verification_code }
|
80
80
|
|
81
81
|
it 'should be verified' do
|
82
|
-
expect
|
83
|
-
expect(account.reload.verified?).to
|
82
|
+
expect(account.verify! verification_code).to be_truthy
|
83
|
+
expect(account.reload.verified?).to be_truthy
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'should have right verification code' do
|
@@ -111,7 +111,7 @@ describe 'SmartSMS::HasSmsVerification' do
|
|
111
111
|
|
112
112
|
it 'should not be verified' do
|
113
113
|
expect(account.verify!('kfdsfd')).to be_nil
|
114
|
-
expect(account.reload.verified?).to
|
114
|
+
expect(account.reload.verified?).to be_falsey
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'should not have right verification code' do
|
@@ -152,8 +152,8 @@ describe 'SmartSMS::HasSmsVerification' do
|
|
152
152
|
before { user.verify verification_code }
|
153
153
|
|
154
154
|
it 'should be verified' do
|
155
|
-
expect
|
156
|
-
expect(user.reload.verified?).to
|
155
|
+
expect(user.verify verification_code).to be_truthy
|
156
|
+
expect(user.reload.verified?).to be_falsey
|
157
157
|
end
|
158
158
|
|
159
159
|
it 'should have right verification code' do
|
@@ -167,7 +167,7 @@ describe 'SmartSMS::HasSmsVerification' do
|
|
167
167
|
it 'should not be verified by using expired verification code' do
|
168
168
|
user.verified_at = nil
|
169
169
|
user.save
|
170
|
-
expect(user.verify(user.messages.first.code)).to
|
170
|
+
expect(user.verify(user.messages.first.code)).to be_falsey
|
171
171
|
end
|
172
172
|
|
173
173
|
it 'should be the latest_message' do
|
@@ -179,8 +179,8 @@ describe 'SmartSMS::HasSmsVerification' do
|
|
179
179
|
before { user.verify 'kfdsfd' }
|
180
180
|
|
181
181
|
it 'should not be verified' do
|
182
|
-
expect(user.verify('kfdsfd')).to
|
183
|
-
expect(user.reload.verified?).to
|
182
|
+
expect(user.verify('kfdsfd')).to be_falsey
|
183
|
+
expect(user.reload.verified?).to be_falsey
|
184
184
|
end
|
185
185
|
|
186
186
|
it 'should not have right verification code' do
|
@@ -194,7 +194,7 @@ describe 'SmartSMS::HasSmsVerification' do
|
|
194
194
|
it 'should not be verified by using expired verification code' do
|
195
195
|
user.verified_at = nil
|
196
196
|
user.save
|
197
|
-
expect(user.verify(user.messages.first.code)).to
|
197
|
+
expect(user.verify(user.messages.first.code)).to be_falsey
|
198
198
|
end
|
199
199
|
|
200
200
|
it 'should be the latest_message' do
|
@@ -213,8 +213,8 @@ describe 'SmartSMS::HasSmsVerification' do
|
|
213
213
|
before { account.verify verification_code }
|
214
214
|
|
215
215
|
it 'should be verified' do
|
216
|
-
expect
|
217
|
-
expect(account.reload.verified?).to
|
216
|
+
expect(account.verify verification_code).to be_truthy
|
217
|
+
expect(account.reload.verified?).to be_falsey
|
218
218
|
end
|
219
219
|
|
220
220
|
it 'should have right verification code' do
|
@@ -228,7 +228,7 @@ describe 'SmartSMS::HasSmsVerification' do
|
|
228
228
|
it 'should not be verified by using expired verification code' do
|
229
229
|
account.confirmed_at = nil
|
230
230
|
account.save
|
231
|
-
expect(user.verify(account.messages.first.code)).to
|
231
|
+
expect(user.verify(account.messages.first.code)).to be_falsey
|
232
232
|
end
|
233
233
|
|
234
234
|
it 'should be the latest_message' do
|
@@ -244,8 +244,8 @@ describe 'SmartSMS::HasSmsVerification' do
|
|
244
244
|
before { account.verify 'kfdsfd' }
|
245
245
|
|
246
246
|
it 'should not be verified' do
|
247
|
-
expect(account.verify('kfdsfd')).to
|
248
|
-
expect(account.reload.verified?).to
|
247
|
+
expect(account.verify('kfdsfd')).to be_falsey
|
248
|
+
expect(account.reload.verified?).to be_falsey
|
249
249
|
end
|
250
250
|
|
251
251
|
it 'should not have right verification code' do
|
@@ -259,7 +259,7 @@ describe 'SmartSMS::HasSmsVerification' do
|
|
259
259
|
it 'should not be verified by using expired verification code' do
|
260
260
|
account.confirmed_at = nil
|
261
261
|
account.save
|
262
|
-
expect(account.verify(account.messages.first.code)).to
|
262
|
+
expect(account.verify(account.messages.first.code)).to be_falsey
|
263
263
|
end
|
264
264
|
|
265
265
|
it 'should be the latest_message' do
|
data/spec/smart_sms_spec.rb
CHANGED
@@ -242,7 +242,7 @@ describe SmartSMS do
|
|
242
242
|
'sms_reply' => [
|
243
243
|
{
|
244
244
|
'id' => nil,
|
245
|
-
'mobile' =>
|
245
|
+
'mobile' => phone,
|
246
246
|
'text' => '哈哈',
|
247
247
|
'reply_time' => '2014-05-08 12:03:16',
|
248
248
|
'extend' => '11642'
|
@@ -256,5 +256,6 @@ describe SmartSMS do
|
|
256
256
|
its(['msg']) { should eq 'OK' }
|
257
257
|
its(:keys) { should include 'sms_reply' }
|
258
258
|
its(['sms_reply']) { should_not be_empty }
|
259
|
+
its(['sms_reply', 0, 'mobile']) { should eq phone }
|
259
260
|
end
|
260
261
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lyfeyaj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -84,14 +84,28 @@ dependencies:
|
|
84
84
|
requirements:
|
85
85
|
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version:
|
87
|
+
version: 3.0.0
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
92
|
- - ">="
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version:
|
94
|
+
version: 3.0.0
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rspec-its
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.0.0
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 1.0.0
|
95
109
|
- !ruby/object:Gem::Dependency
|
96
110
|
name: database_cleaner
|
97
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -162,6 +176,20 @@ dependencies:
|
|
162
176
|
- - ">="
|
163
177
|
- !ruby/object:Gem::Version
|
164
178
|
version: '0'
|
179
|
+
- !ruby/object:Gem::Dependency
|
180
|
+
name: sdoc
|
181
|
+
requirement: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - ">="
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
type: :development
|
187
|
+
prerelease: false
|
188
|
+
version_requirements: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
165
193
|
description: A smart sms verification tool
|
166
194
|
email:
|
167
195
|
- lyfeyaj@gmail.com
|
@@ -170,6 +198,7 @@ extensions: []
|
|
170
198
|
extra_rdoc_files: []
|
171
199
|
files:
|
172
200
|
- ".gitignore"
|
201
|
+
- ".rdoc_options"
|
173
202
|
- ".travis.yml"
|
174
203
|
- Gemfile
|
175
204
|
- Gemfile.lock
|
@@ -178,6 +207,7 @@ files:
|
|
178
207
|
- Rakefile
|
179
208
|
- lib/generators/smart_sms/config_generator.rb
|
180
209
|
- lib/generators/smart_sms/install_generator.rb
|
210
|
+
- lib/generators/smart_sms/templates/add_uid_to_smart_sms_messages.rb
|
181
211
|
- lib/generators/smart_sms/templates/create_smart_sms_messages.rb
|
182
212
|
- lib/generators/smart_sms/templates/smart_sms_config.rb
|
183
213
|
- lib/smart_sms.rb
|
@@ -225,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
255
|
version: '0'
|
226
256
|
requirements: []
|
227
257
|
rubyforge_project:
|
228
|
-
rubygems_version: 2.
|
258
|
+
rubygems_version: 2.4.3
|
229
259
|
signing_key:
|
230
260
|
specification_version: 4
|
231
261
|
summary: A smart sms verification tool used in China and integrate with yunpian.com
|