shared_examples和之间的真正区别是shared_context什么?
我的观察:
我可以使用两者测试相同的东西(即带shared_examples或shared_context)
但是如果我以后使用其他测试,我的其他一些测试会失败.
观察#1:
我在https://www.relishapp.com/上比较了每个文档的shared_examples和shared_context
语法上的差异是:
示例:
shared_context "shared stuff", :a => :b do
...
end
Run Code Online (Sandbox Code Playgroud)
shared_examples
include_examples "name" # include the examples in the current context
it_behaves_like "name" # include the examples in a nested context
it_should_behave_like "name" # include the examples in a nested context
Run Code Online (Sandbox Code Playgroud)
shared_context
include_context "shared stuff"
Run Code Online (Sandbox Code Playgroud)
观察#2
我有一个测试用例
shared_context 'limit_articles' do |factory_name|
before do
@account = create(:account)
end
it 'should …Run Code Online (Sandbox Code Playgroud) 一切顺利,直到今天我收到来自LinkedIn的电子邮件,表明一些重大的API变化.随后我在通过身份验证用户时看到了例外情况.LinkedIn.
以下是日志的例外情况
OAuth::Problem (Scope NOT_AUTHORIZED : r_fullprofile):
oauth (0.4.7) lib/oauth/consumer.rb:178:in `request'
oauth (0.4.7) lib/oauth/consumer.rb:194:in `token_request'
oauth (0.4.7) lib/oauth/consumer.rb:136:in `get_request_token'
Run Code Online (Sandbox Code Playgroud)
用于获取请求令牌的OAuth逻辑.
consumer = OAuth::Consumer.new(LINKED_IN_API_KEY, LINKED_IN_SECRET_KEY,
{
:site => "https://api.linkedin.com",
:scheme => :header,
:http_method => :post,
:request_token_path => "/uas/oauth/requestToken?scope=r_fullprofile",
:access_token_path => "/uas/oauth/accessToken",
:authorizeEmapath => "/uas/oauth/authorize"
})
### Exception occurs at this call.
request_token = consumer.get_request_token(:oauth_callback => callback_url)
Run Code Online (Sandbox Code Playgroud)
来自LinkedIn的电子邮件

我的分析到现在为止
如果我将范围更改为r_basicprofile它工作正常但我没有获得skills经过身份验证的linkedin用户的信息.
为了满足API更改,我需要做些什么其他更改?
我在git上有几个分支,这些分支的模式在不同的版本上.切换到分支后,new_feature如果我这样做(有挂起的迁移),rake db:setup那么建议我运行挂起的迁移.
一旦我这样做,我的模式就会更新在同一分支中删除的表.
如果我这样做rake db:reset那就行了.
我知道之间的区别db:setup和db:reset.后者一个db:drop接一个db:setup
但我想知道为什么架构显示那些丢弃的表 rake db:migrate
我肯定错过了模式加载和迁移过程中的一些rails知识
任何见解都会有很大的帮助.提前致谢
尝试使用SecureRandom类rails生成随机数字.我们可以使用SecureRandom.hex创建一个随机数,其中只包含数字而不包含字母.
例如:
代替
SecureRandom.hex(4)
=> "95bf7267"
Run Code Online (Sandbox Code Playgroud)
它应该给
SecureRandom.hex(4)
=> "95237267"
Run Code Online (Sandbox Code Playgroud) 这是全球高度讨论的话题.但我还没有找到令人信服的答案或解决方案.所有的SO帖子最终都以NO或解决方案最终领先.
通过Open Graph API open-graph-api以编程方式创建Facebook页面
最后这个 - 创建Facebook业务页面是可能的,但如何?
Pagemodo确实可以让你创建一个真正的Facebook页面(我假设它通过Facebook javascript SDK).
据我所知,Facebook提供以下API/SDK
Graph API
FQL
Open Graph
Javascript SDK
Dialogs
Chat
Internationalization
Ads
Public Feed
Keyword Insights
Run Code Online (Sandbox Code Playgroud)
前4个应该可以定义页面创建API
图谱API - 没有任何POST查询 pages/create
FQL - 无法插入(无论如何忽略)
OpenGraph - 我们可以拥有一个对象 type:page
Javascript SDK - 我是积极的,javascript SDK可以帮助(任何人都有运气吗?)
我是否真的可以通过任何方式创建一个Facebook页面?facebook有没有其他API允许创建一个?
任何形式的帮助表示赞赏.谢谢!
facebook ruby-on-rails facebook-graph-api facebook-javascript-sdk facebook-opengraph
需要帮助解决错误:
kotlin.UninitializedPropertyAccessException: lateinit property ultraService has not been initialized
at com.example.ultrasonic.service.UltraServiceTest.get all Ultra(UltraServiceTest.kt:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Run Code Online (Sandbox Code Playgroud)
服务类:https : //github.com/swapab/ultrasonic/blob/master/src/main/kotlin/com/example/ultrasonic/service/UltraService.kt
package com.example.ultrasonic.service
import com.example.ultrasonic.domain.Ultra
import com.example.ultrasonic.repository.UltraRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
@Service
class UltraService {
@Autowired
private …Run Code Online (Sandbox Code Playgroud) 用于跟踪用户登录信息.
我的user.rb模型遵循以下模块的设计.
devise :database_authenticatable, :registerable, :recoverable,
:rememberable, :token_authenticatable
Run Code Online (Sandbox Code Playgroud)
我想添加:trackable它,但是当它更新相应的字段时,它不应该从User模型中触发任何回调.
一种解决方案是有条件地检查可跟踪字段更改的每个回调.
有一种优雅的方式来做到这一点?可能没有回调检查.
以前我正在执行以下操作以从报告表中获取每日计数。
SELECT COUNT(*) AS count_all, tracked_on
FROM `reports`
WHERE (domain_id = 939 AND tracked_on >= '2014-01-01' AND tracked_on <= '2014-12-31')
GROUP BY tracked_on
ORDER BY tracked_on ASC;
Run Code Online (Sandbox Code Playgroud)
显然,这不会给我 0 缺失日期的计数。
然后我终于找到了一个最佳解决方案来生成给定日期范围之间的日期序列。但我面临的下一个挑战是将其与我的报告表连接起来并按日期分组计数。
select count(*), all_dates.Date as the_date, domain_id
from (
select curdate() - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as Date
from (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all …Run Code Online (Sandbox Code Playgroud) 我试图在 Spree 中指定一些自定义角色,例如角色“客户端”,并扩展访问该角色的管理部分的权限。
该用户将只能访问该用户创建的那些产品。概念是让具有“客户”角色的用户仅管理产品和其他某些模型。
首先,我添加了 CanCan 插件并在 role_ability.rb 中定义了 RoleAbility 类
就在这篇文章之后:Spree 自定义角色权限
class RoleAbility
include CanCan::Ability
def initialize(user)
user ||= User.new
if user.has_role? 'admin'
can :manage, :all
elsif user.has_role? 'client_admin'
can :read, Product
can :admin, Product
end
end
end
Run Code Online (Sandbox Code Playgroud)
将其添加到初始化程序中:config/initializers/spree.rb
Ability.register_ability(RetailerAbility)
Run Code Online (Sandbox Code Playgroud)
还扩展了 admin_products_controller_decorator.rb :app/controllersadmin_products_controller_decorator.rb
Admin::ProductsController.class_eval do
def authorize_admin
authorize! :admin, Product
authorize! params[:action].to_sym, Product
end
end
Run Code Online (Sandbox Code Playgroud)
但我收到闪现消息“授权失败”
为了寻找一些运气,我参考了以下链接
自定义 Spree 角色的 github 要点:https://gist.github.com/1277326
这是我面临的类似问题:http://groups.google.com/group/spree-user/browse_thread/thread/1e819e10410d03c5/23b269e09c7ed47e
所有的努力都白费了……
有任何高度赞赏的指点吗?
提前致谢。
我在中定义了一个工厂<Rails-root>/spec/factories/models.rb:
FactoryGirl.define do
factory :model do
id 1
association :organization, factory: :aureso
name "Default Model"
factory :serie_1 do
id 2
name 'serie_1'
end
factory :serie_2 do
id 3
name 'serie_2'
end
factory :serie_3 do
id 4
name 'serie_3'
end
end
end
Run Code Online (Sandbox Code Playgroud)
我想获得所有为Class定义的工厂Model。
我可以使用来获得所有类的工厂定义FactoryGirl.factories,是的,我可以使用map / reduce实现上述目标。但是我想知道是否有任何辅助方法来获取模型类的所有定义。